[cgiapp] hook question

Todd Ross tar.lists at yahoo.com
Thu Jul 29 17:16:31 EDT 2010


Hello,

I'm playing around with hooks in CGI::Application and am running into behavior 
that I don't understand.

Given this script (suitable to run from the command line):

[me at unixbox1:~]> cat testcgiapp.pl
#!/usr/bin/perl

use strict;
use warnings;

my $webapp = Private::Webapp->new();
$webapp->run();

package Private::Webapp;

use base 'CGI::Application';

# Neither of these work -- why?
__PACKAGE__->add_callback('prerun', \&hook_prerun);
Private::Webapp->add_callback('prerun', \&hook_prerun);

sub setup {
        my $self = shift;

        $self->start_mode('begin');
        $self->mode_param('rm');
        $self->run_modes(
                begin => 'do_begin'
        );
        
        # this works
        $self->add_callback('prerun', \&hook_prerun);
}

sub do_begin {
        my $self = shift;

        my $output = "Hello, CGI::Application!\n";
        return $output;
}

sub hook_prerun {
        my $self = shift;

        print STDERR "hook_prerun\n";
}

1;

[me at unixbox1:~]> perl testcgiapp.pl
hook_prerun
Content-Type: text/html; charset=ISO-8859-1

Hello, CGI::Application!

Why don't my package/class level hooks work but my instance/self hook does?  I'm 
not actually trying to register all three hooks; just one at a time.  I included 
all three to demonstrate what I've tried.

Todd



      


More information about the cgiapp mailing list