[cgiapp] hook question

Michael Peters mpeters at plusthree.com
Fri Jul 30 11:47:48 EDT 2010


On 07/29/2010 05:58 PM, Todd Ross wrote:
> 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);

Yes those are method calls and they happen at run time. So they happen 
after you've already created and run your application.

> ... 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.

No, they aren't any different than the methods you invoked to create 
your application object (new) nor the method you invoked to run it (run).

> 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?

"use" will find the package, compile it and then run it, returning the 
value of the last operation in that package (which is why you always see 
Perl packages with a "1;" at the bottom, so that it has a successful 
statement to run that returns a true value).

In your case the same basic things happen except that there is no "use" 
to compile and run the package before you create and run your 
application object. So perl compiles that script (including your web app 
package) and then starts executing the script. And you create and run 
your application object before you run those callbacks, so you never see 
them executing.

-- 
Michael Peters
Plus Three, LP


More information about the cgiapp mailing list