Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Perl Monk, Perl Meditation
 
PerlMonks  

Re: More then one AUTOLOAD in a class hierarchy.

by tilly (Archbishop)
on Nov 12, 2004 at 00:05 UTC ( #407228=note: print w/ replies, xml ) Need Help??


in reply to More then one AUTOLOAD in a class hierarchy.

In my books an AUTOLOAD catching getters and setters is almost always better replaced with a call to a function which creates getters and setters by assigning closures to typeglobs. Like this bare-bones example:

use strict; package Parent; sub make_accessors { my ($class, @attributes) = @_; foreach my $attribute (@attributes) { no strict 'refs'; *{"$class\::$attribute"} = sub { my $self = shift; if (@_) { $self->{$attribute} = shift; } return $self->{$attribute}; }; } } package Child; our @ISA = 'Parent'; __PACKAGE__->make_accessors(qw(this that the other));
And now the method cascading that you asked for comes for free from Perl's OO dispatch. There is no AUTOLOAD issue to figure out how to resolve because there is no AUTOLOAD to confuse the issue.


Comment on Re: More then one AUTOLOAD in a class hierarchy.
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2014-04-19 18:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (483 votes), past polls