I have an OO parser in two classes Frontend and Backend::Frontend. Frontend inherits from Backend.

Backend parses a file and invokes Frontend::method via a callback for specific chunks of the input document. For instance, it may encounter an element named 'glark', so it calls Frontend::glark($args).

These Frontend methods transform the arguments in some way then either return a string, or recursively call a Backend method to break the input down further. An example of the latter is:

sub Frontend::glark { my ($self,$args) = @_; return 'glark='.$self->backend_method($args); }

This produces the expected output even for complex documents. The problem, I have discovered, is related to the calling of the parent class' methods by Frontend -- the method is invoked correctly, but, as you would expect, the Backend method is invoked on a Backend::Frontend object, which causes no end of problems.

Or, to put it another way:

  1. Backend invokes ($self->{frontend})->frontend_method. (ref($self) eq 'Frontend').
  2. Frontend::frontend_method calls $self->backend_method (intending to dispatch to Backend, as Frontend does a "use base 'Backend'"). (ref($self) eq 'Frontend').
  3. Backend::backend_method is invoked correctly, but now of course ref($self) eq 'Frontend'. Thus, when we do step 1 again later we call the frontend_method of a Frontend object of a Frontend object... This blows up.

I'm sure this problem just represents a basic misunderstanding of Perl OO. I can probably hack around it, but I'd like to know the Right Way. :-)


In reply to 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.