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

From as far as I can see, this is expected behaviour - With CGI::Application, in addition to the setup method for the establishment of parameters such as database handles, there is also the teardown method, which is implemented automatically after the application is run and can be used for the clean up of handles and objects that require an explicit closure before script termination.

The error you are experiencing is a result of the DBI handle not being explicitedly disconnected prior to termination of CGI::Application execution - This error is not due to the closure of scope within the setup method. To correct this behaviour, you should make use of the teardown method within your CGI::Application class:

sub teardown { my $self = shift; $self->param('mydbh')->disconnect; }

This should correct your problem. This method and a couple of other 'gotchas' for CGI::Application is described in my review of this module here.

 

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

Replies are listed 'Best First'.
Re: Re: DBI handle destroyed during CGI::Application setup
by talexb (Chancellor) on Jan 07, 2002 at 04:36 UTC
    I have implemented a teardown routine; but not calling it is not the cause of my error.

    And I still don't understand how your sub setup executes without error -- you are creating a DBI handle within your call to $self->param just as I was -- and I got a DBI error out of that.

    I also note that you have also made the change from

    $self->run_modes( 'mode1' => 'showform', 'mode2' => 'showlist' );
    to
    $self->run_modes( 'mode1' => \&showform, 'mode2' => \&showlist );
    Is the original documentation inaccurate? After some skull sweat I figured out the answer myself, and I'm glad to see that you have it correctly on your page. I will peruse your node with a magnifying glass to see how many other 'gotcha's there are -- thanks for your contribution.

    --t. alex

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

      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.

        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.