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) }; }
In reply to Re: Ref to an object instance method
by stvn
in thread Ref to an object instance method
by former33t
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |