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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.