in reply to Re: Re: DBI handle destroyed during CGI::Application setup
in thread DBI handle destroyed during CGI::Application setup

I'll post some sample code that makes uses a DBI handle within a param object for illustration - It might be worthwhile your putting a more complete segment of your code up on your scratchpad for me to have a look through because the implementation of the disconnect method on the DBI handle within the teardown method should correct your errors.

Some sample CGI::Application code using DBI handles follows - Note that my usage of the param function differs slightly as I prefer to define my parameters through the instance object of my CGI::Application class.

#!/usr/bin/perl use DBI; use strict; my $app = self->new( TMPL_PATH => "../templates/", PARAMS => { 'dbh' => DBI->connect( "DBI:mysql:database=apex;host=localhost", undef, undef ), 'mode_param' => "stage" } ); $app->run; exit 0; package self; use base qw/CGI::Application/; use strict; sub setup { my $self = shift; $self->start_mode('display'); $self->run_modes({ 'AUTOLOAD' => 'display_calendar' }); $self->mode_param($self->param('mode_param')); }; sub teardown { my $self = shift; $self->param('dbh')->disconnect; }; . . . 1; __END__

 

perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'

Replies are listed 'Best First'.
Re: (4) DBI handle destroyed during CGI::Application setup
by talexb (Chancellor) on Jan 07, 2002 at 21:27 UTC
    Perl still isn't happy with your hash in the call to set up run_modes in this statement:
    $self->run_modes ({ 'logon' => 'LogonPage', 'vlogon' => 'VerifyLogon', 'menu' => 'MenuPage', 'todo' => 'ToDoPage' }); # your run_modes argument was not explicitly a hash - the br +aces correct this
    I still get
    Can't use string ("LogonPage") as a subroutine ref while "strict refs" + in use at /usr/local/lib/perl5/site_perl/5.6.0/CGI/Application.pm li +ne 90.
    Changing back to
    $self->run_modes ( 'logon' => \&LogonPage, 'vlogon' => \&VerifyLogon, 'menu' => \&MenuPage, 'todo' => \&ToDoPage ); # your run_modes argument was not explicitly a hash - the bra +ces correct this
    makes Perl happy .. no errors, and the first page comes up fine.

    --t. alex

    "Excellent. Release the hounds." -- Monty Burns.

      You have to upgrade. Prior to version 1.3, CGI::Application only allowed subrefs (\&my_mode) -- not name-based references ('my_mode').

      Name-based referenced were added to improve CGI::Application's sub-classing functionality. Modern versions allow both sub-refs and name-based refs.

      The best answers to questions related to CGI::Application can be found on the official mailing list. To subscribe, send email to:

         cgiapp-subscribe@lists.vm.com

      An archive of the list can be found at:

         http://www.mail-archive.com/cgiapp%40lists.vm.com/