Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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 exploiting the Monastery: (10)
As of 2018-06-22 15:51 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.