I understand the distinction between compile time and run time (as phases), but
I'm not fully appreciating the impact here; I'm still a little lost.
You indicate that method calls happen at runtime. Assuming that these qualify
as method calls ...
__PACKAGE__->add_callback('prerun', \&hook_prerun);
Private::Webapp->add_callback('prerun', \&hook_prerun);
... isn't the only time they can be processed during compile time? They're not
in a method that can be invoked at run time.
Even if the package were placed into a separate .pm file, you indicate that the
use <package> statement is going to be processed at compile time, which seems
like the same phase they're processed in in my existing example. Why would the
behavior change?
Todd
________________________________
From: Michael Peters <[email protected]>
To: CGI Application <[email protected]>
Cc: Todd Ross <[email protected]>
Sent: Thu, July 29, 2010 4:30:00 PM
Subject: Re: [cgiapp] hook question
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/ ##
## ##
################################################################