Hi Stas,
Am Freitag, 13. Februar 2004 23:56 schrieb Stas Bekman:
> I've extended lookup_method to support sub-classed objects. which
> simplifies the usage. It's now committed. Here is a test:
>
> perl -MModPerl::MethodLookup -le '\
> package Apache::RequestRec; sub new { bless {}, shift }; \
> package My::Request; @ISA = qw(Apache::RequestRec); \
> package main; my $obj = My::Request->new(); \
> my($hint, @modules) = ModPerl::MethodLookup::lookup_method("print", $obj);
> \ print $hint'
> To use method 'print' add:
> use Apache::RequestIO ();
>
> So EazyLife.pm, including fixes for your previous comments, looks like:
>
It works better, but not right. It has the same problems as the last one, but
the other way around ;-)
On my first test I found out that it is incredible slow. So iI move the
return if $AUTOLOAD =~ /$skip/;
line before the lookup_method. That is not right ever, your way looks much
better, but it was so slow. Perhaps other ideas are around.
The second problem is if I have a class that inherits from another class with
splitted functions like Apache::RequestRec.
package xxx;
@ISA='Apache::RequestRec';
sub new { bless $_[1], $_[0] }
sub handler : method {
my ( $class, $rec ) = @_;
xxx->new( $rec )->print('hello world');
}
then AUTOLOAD is called and found out, that Apache::RequestRec is the
superclass of xxx and that Apache::RequestIO must be loaded. We require
Apache::RequestRec and then goto subroutine xxx::print. That is an endless
loop, since it calls AUTOLOAD to find out about xxx::print. In this case we
must call Apache::RequestRec::print, but we do not know about it we only know
Apache::RequestIO.
> package ModPerl::EazyLife;
>
> use ModPerl::MethodLookup ();
> use Carp;
>
> my @avail_modules = ModPerl::MethodLookup::avail_modules();
> push @avail_modules, 'Apache'; # XXX: may go away
> my $skip = qr|(::)?DESTROY$|;
> for my $module (@avail_modules) {
> *{"$module\::AUTOLOAD"} = sub {
> my($hint, @modules) =
> ModPerl::MethodLookup::lookup_method($AUTOLOAD, @_);
>
> if (@modules) {
> eval "require $_" for @modules;
> goto &$AUTOLOAD;
> }
> else {
> return if $AUTOLOAD =~ /$skip/;
> croak $hint || "Can't find $AUTOLOAD";
> }
> };
> }
>
> 1;
>
> You need to update your cvs and rebuild (because of the changes in the
> autogenerated MethodLookup.pm module).
>
Have a nice day.
--
Boris
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]