in reply to Re^2: OO Parser Class with Callbacks - Confusion
in thread OO Parser Class with Callbacks - Confusion
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
which is a generic dispatch mechanism in Backend.$self->handle(name=>'token_name',args=>['arg1','arg2'])
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.:-)
|
|---|