I'm fond of wrapping the method call into a subroutine reference.
my $cb = MIS_PrintStatus->new(); my $callback = sub { $cb->printit(); }; # ... my $handler = MIS_SAX_Parser->new($callback);
Update: I typed too slow and others got this answer before me. I'll try to add some value to this comment by pointing out that you can streamline your constructor:
# Here's what you have. sub new { my ($class, $callback) = @_; my $self = { COUNTER => 0, HASHTYPE => TYPE0 }; bless $self, $class; if ($callback) { $self->{CALLBACK} = \&$callback; } else { $self->{CALLBACK} = \&nocall; } return $self; } # Start with this instead, maybe sub new { my ($class, $callback) = @_; $callback ||= \&nocall; my $self = { COUNTER => 0, HASHTYPE => TYPE0, CALLBACK => $callback, }; bless $self, $class; }
In reply to Re: Ref to an object instance method
by webfiend
in thread Ref to an object instance method
by former33t
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |