[cgiapp] hook question

Michael Peters mpeters at plusthree.com
Thu Jul 29 17:30:00 EDT 2010


On 07/29/2010 05:16 PM, Todd Ross wrote:

> #!/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);

You're confusing runtime and compile time. Some things (like package and 
use statements) run at compile time. Other things (like any method 
calls) happen at run time. So your package is compiled and methods 
added, but those hooks won't be added until after $webapp->run() has 
already taken place.

But if you put the package into it's own file you wouldn't have this 
problem since the runtime code in the package is run when the "use 
Private::Webapp" statement is run.

-- 
Michael Peters
Plus Three, LP


More information about the cgiapp mailing list