Guys,

Here's my take on why that "naughty" code is there.  
In short:

It is because prior to the first request, no "handler" routine is there yet, 
and when the first request is handled, it's not passed as an OO-style call but 
as a plain old subroutine call, so no inheritance technique was going to find a 
"handler" out of somewhere else.

Example:

One of our Maypole apps is ITSRR::Prism.

<Location /prism >
    SetHandler perl-script
    PerlResponseHandler ITSRR::Prism
</Location>

Life-cycle of first ever request:  

In a just-in-time fashion, ModPerl finds that ITSRR::Prism is not already in 
its namespace so it gets automatically 'required' prior handling the first 
request.
During the require, the module-level code calls Maypole::setup (via its 
inheritance chain) which as we know uses the "naughty" technique to add a 
handler entry into the ITSRR::Prism namespace.
Once the require is finished, modperl is finally ready to get this pending 
first-ever request dealt with.  It calls something like this: 
ITSRR::Prism::handler($r) where the $r is an Apache::Request object (note not a 
Maypole request!).  That call is not an OO-style call.. it's just a call to a 
sub out of that package.  Therefore no rules about following inheritance chains 
to find the method "handler" are going to be applied.  So if the naughty bit is 
not done, no handler is available to service the request. 

If modperl had invoked ITSRR::Prism->handler($r) .. note the arrow technique in 
other words a "method" call..  then I suppose the naughty technique would be 
unnecessary.  I note that modperl does support exactly this if you want, see 
http://perl.apache.org/docs/2.0/user/coding/coding.html#Method_Handlers .  But 
I get the impression from the modperl 1&2 docs that this is unchartered waters 
(by me anyway), and requires a special build of modperl.



>>> Peter Speltz <[EMAIL PROTECTED]> 16/09/05 1:57 PM >>>
On 9/15/05, David Baird <[EMAIL PROTECTED]> wrote:
> Maypole::setup() has this:
> 
> # Naughty.
> *{ $calling_class . "::handler" } =
>           sub { Maypole::handler( $calling_class, @_ ) };
> 
> Why is this necessary? $calling_class is the application, which
> already inherits from Maypole.
> 

At first I was going to say to safeguard users from messing things up
by defining a handler sub.  But it looks like it is so the $r object 
in @_ is passed is available and not just the class. I commented it
out and the request could not run.  It is really beyond my
understanding now and i could be totally wrong. I am curious though.


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php 
_______________________________________________
Maypole-devel mailing list
[email protected] 
https://lists.sourceforge.net/lists/listinfo/maypole-devel



This message (including any attachments) is intended solely for the addressee 
named and may contain confidential and privileged information. If you are not 
the intended recipient, please delete it and notify the sender.
Views expressed in this message are those of the individual sender, and are not 
necessarily the views of the Independent Transport Safety and Reliability 
Regulator (ITSRR). Whole or parts of this e-mail may be subject to copyright
of ITSRR or third parties. You should only re-transmit, distribute or use the 
material for commercial purposes if you are authorised to do so.

                        Visit us at:

www.transportregulator.nsw.gov.au  or  Telephone: (02) 8263 7100




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Maypole-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maypole-devel

Reply via email to