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):
[...@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;
[...@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
##### CGI::Application community mailing list ################
## ##
## To unsubscribe, or change your message delivery options, ##
## visit: http://www.erlbaum.net/mailman/listinfo/cgiapp ##
## ##
## Web archive: http://www.erlbaum.net/pipermail/cgiapp/ ##
## Wiki: http://cgiapp.erlbaum.net/ ##
## ##
################################################################