Hi Stas, Am Freitag, 13. Februar 2004 04:17 schrieb Stas Bekman: > Boris Zentner wrote:
[...] > > > > 2. EazyLife can not know about my methods, so the option is guess and > > load all classes with methods that may satisfy me or ignore me. I dislike > > both and Apache::Request forwards everything unknown to the environ > > object, but it seems it looks what the object can ( untested ) so nothing > > is forwarded until the class is loaded. > > Well, may be your case is much more complicated than the average case, and > EazyLife could benefit a majority of users. And someone like you will have > to manually figure out which modules to load. Unless you have better idea. Right, but using Apache::Request is not so uncommon. If the methods and functions are grouped in the classfiles then ModPerl::MethodLookup, EazyLife and a lot of hazzle including inherence work out of the box. Just to remark this a last time. > > > Back to EazyLife: > > It calls the AUTOLOAD function and in my case it is the right one. But if > > My class is a new one ( one that is not part of mod_perl ) then > > ModPerl::MethodLookup simply find nothing and dies. > > > > suppose this ( untested and useless ) example: > > > > package SuperRequestRec; > > our @ISA = qw!Apache::RequestRec!; > > sub new { > > my $class = shift; > > return bless shift, $class; > > } > > 1; > > > > sub handler :method { > > my ( $c, $r ) = @_; > > my $sr = SuperRequestRec->new( $r ); > > $sr->print("Hi"); > > return DONE; > > } > > > > see this line from EazyLife.pm > > > > ModPerl::MethodLookup::lookup_method($AUTOLOAD, @_); > > > > $AUTOLOAD may be SuperRequestRec::print > > > > and $_[0] is a reference to SuperRequestRec. > > I see what you mean. Try to patch it to try first: > > ModPerl::MethodLookup::lookup_method($AUTOLOAD, @_); > and if it fails: > > ModPerl::MethodLookup::lookup_method($AUTOLOAD); > > The second argument (@_) is optional to help resolve the situation when > there is more than one class with the same method. For example: > > % perl -MApache2 -MModPerl::MethodLookup -e print_method new > There is more than one class with method 'new' > try one of: > use APR::NetLib (); > use APR::UUID (); > use APR::Bucket (); > use APR::Pool (); > use Apache::RequestUtil (); > use APR::ThreadMutex (); > use APR::Brigade (); > % > % perl -MApache2 -MModPerl::MethodLookup -e print_method new > Apache::RequestRec > > To use method 'new' add: > use Apache::RequestUtil (); > > So how about this (it's untested): > > ---------------------------------- > package EazyLife; > > use ModPerl::MethodLookup (); > > for my $module (ModPerl::MethodLookup::avail_modules()) { > *{"$module\::AUTOLOAD"} = sub { > my($hint, @modules) = > ModPerl::MethodLookup::lookup_method($AUTOLOAD, @_); > > # handle inheritance > unless (@modules) { > my($hint, @super_classes) = > ModPerl::MethodLookup::lookup_method($AUTOLOAD); > for (@super_classes) { > push @modules, $_ if ref($AUTOLOAD) && $AUTOLOAD->isa($_); > } > } I change the handle part a little # handle inheritance if ([EMAIL PROTECTED] && $_[0] && ref( $_[0] ) ) { my($hint, @super_classes) = ModPerl::MethodLookup::lookup_method($AUTOLOAD); for (@super_classes) { push @modules, $_ if $_[0]->isa($_); } But even then, it will not work. print seems a good startingpoint. Again from my example: lookup_method find some possible superclasses for SuperRequestRec. Apache::Filter and Apache::RequestIO. But the superclass for SuperRequestRec is Apache::RequestRec. > > if (@modules) { > eval "require $_" for @modules; > goto &$AUTOLOAD; > } > else { > die $hint; > } > }; > } > > 1; -- Boris --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]