in reply to reference to self function
if ($self->can($self->{method})) { my $method = $self->{method}; $self->$method(@params); } else { die "Sorry, the method $self->{method} isn't valid!"; }
You might want to restrict access by prefixing a name or a symbol to all methods you want to call this way.
One other tip: the indirect object notation is perilous. I prefer to call constructors with:
my $x = Foo->new(method => 'biscuit');It's a lot clearer that the method is new, not Foo.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: reference to self function
by anjiro (Beadle) on Jun 25, 2003 at 07:12 UTC |