Boris Zentner wrote:

Earlier you've raised an important point: AUTOLOADs slow things down with DESTROY and evals, penalizing users who don't rely on this module.
In order not to penalize those who preload, I think that we need to somehow undef AUTOLOADs as soon as the module is loaded. Though this is tricky with cases like Apache::RequestRec, since Apache::RequestRec::AUTOLOAD handles several other classes.


Ideas?

so lookup_method internally finds two entries. none of them matches
My::RequestRec. So it checks isa() and finds that the first entry
matches. It should now return 'Apache::RequestIO', which AUTOLOAD loads
and now when it calls goto, it calls that method.

Yes, that is exactly what happened here. But it is wrong. from your example: Apache::RequestIO is returned. now eval { require 'Apache::RequestIO' } loads the class/package.

but the next line 'goto &$AUTOLOAD' calls My::RequestRec::print and
produce the endless loop. Since we need to call Apache::RequestRec::print
_not_ My::RequestRec::print.

I see. So we probably need to call:


shift->$AUTOLOAD



something like

my $c = shift;
$AUTOLOAD =~ /(\w+)$/;
$c->$1(@_);

looks funny, but the we need to handle the return part too. That might be not so nice for any case.

Yes, that's not good. How about:


        if (@modules) {
            eval "require $_" for @modules;
            if (@modules == 1) {
                my $module = shift @modules;
                $AUTOLOAD =~ s/.*::/$module::/;
            }
            goto &$AUTOLOAD;
        }

really, I think it should always be only one matching module, since we have no internal sub-classing at the moment.

then? which this time will find print() on its own, since Apache::RequestIO
is now loaded.

Not sure about the AUTOLOAD goto magick though. Ideas?

May be having method_lookup return the package name will allow us to call:

Apache::RequestRec::print(@_);

But if there is a way to call the object method via goto, that would be the
simplest way.



Without too much thinking I prefere if method_lookup would return the full qualified method name ( Apache::RequestRec::print ).

Then we can call goto &$method.

That will probably require writing a new function, as this extra return argument doesn't fit into the existing API. I think a simple s/// above should do the trick.


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to