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.
In reply to Re: reference to self function
by chromatic
in thread reference to self function
by anjiro
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |