Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: AUTOLOAD cascade

by Ven'Tatsu (Deacon)
on Oct 13, 2004 at 16:51 UTC ( [id://398918]=note: print w/replies, xml ) Need Help??


in reply to AUTOLOAD cascade

Another option is to use the sub NAME; stub declaration to force AUTOLOAD to start in the correct package.
package Parent; sub parent_method; sub AUTOLOAD { my $self = shift; (my $method = $AUTOLOAD) =~ s/.*:://; return if $method eq 'DESTROY'; if ($method eq 'parent_method') { print "Parent->parent_method\n"; } else { print "Parent doesn't know $method\n"; } } package Child; @ISA = qw(Parent); sub child_method; sub AUTOLOAD { my $self = shift; (my $method = $AUTOLOAD) =~ s/.*:://; return if $method eq 'DESTROY'; if ($method eq 'child_method') { print "Child->child_method\n"; } else { print "Child doesn't know $method\n"; } } package main; Child->child_method; Child->parent_method; Child->not_defined; Parent->child_method; Parent->parent_method; Parent->not_defined; __END__ Child->child_method Parent->parent_method Child doesn't know not_defined Parent doesn't know child_method Parent->parent_method Parent doesn't know not_defined

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://398918]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-24 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found