in reply to Ref to an object instance method
All the above suggestions are fine, but if you want this really to be a feature of your objects, then you could add method currying features to a base class pretty easily ...
Then have your MIS_PrintStatus class inherit from Curryable and then all you need to do is this ...package Curryable; sub curry { my ($self, $method_name, @args) = @_; my $method = $self->can($method_name) || die "No $method_name meth +od found"; return sub { $self->$method(@args, @_) }; }
And it will make sure to wrap up the method correctly for you. If you need some additional flexibility, you could also define a "right curry" method as well, which can come in quite handy. Note the reversal of the @args and @_ from the original curry.my $handler = MIS_SAX_Parser->new($cb->curry('printit'));
sub rcurry { my ($self, $method_name, @args) = @_; my $method = $self->can($method_name) || die "No $method_name meth +od found"; return sub { $self->$method(@_, @args) }; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Ref to an object instance method
by former33t (Scribe) on Dec 04, 2007 at 13:56 UTC |