Yep, that works perfectly. I had a feeling it was a fundamental mistake. :-)

I now use Frontend directly like this:

my $obj = Frontend->new; $obj->parse($file);

Frontend inherits from Backend, and Frontend doesn't provide a _parse_ method, so it dispatches it up the chain to Backend. Backend does have this method and starts parsing the file. When it hits a token it calls

$self->handle(name=>'token_name',args=>['arg1','arg2'])
which is a generic dispatch mechanism in Backend.

The code for _handle_ is simplified now because it does something like:

if ($self->can($token)) { return $self->$token($args); }

IOW, it looks for a method with the same name as the token in the current class and when it fails it passes it to Frontend which does implement said method.:-)


In reply to Re^3: OO Parser Class with Callbacks - Confusion by Anonymous Monk
in thread OO Parser Class with Callbacks - Confusion by Anonymous Monk

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.