in reply to Re^2: Seeking advice for OO-related strategy
in thread Seeking advice for OO-related strategy
This is among some of the coolest aspects of perl, IMO.
Assuming $meth is a coderef, $self->$meth(@_) is exactly the same as $meth->($self, @_). However, if $meth is a string which holds the name of a function, then they aren't the same. The rules get a bit convoluted here:
This means that your validation should not check merely that the action parmaeter is a coderef, but also that $self can do it:
If you're passed a coderef, use it. If not, you can convert it into a coderef that has already gone through the @ISA tree to find the right function.$self->{_action} = ref $_[0] ? $_[0] : $self->can($_[0]); die "Invalid action" unless $self->{_action};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Seeking advice for OO-related strategy
by blazar (Canon) on Mar 08, 2005 at 15:12 UTC | |
by Tanktalus (Canon) on Mar 08, 2005 at 16:11 UTC |