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

#####  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/                 ##
##                                                            ##
################################################################

Reply via email to