Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://407228]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2017-03-26 07:56 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (313 votes). Check out past polls.