in reply to Re: Parse::RecDescent autotree visitor
in thread Parse::RecDescent autotree visitor

Ok. Thanks. My question was to vague. I'm hoping for design assistance versus help with debugging. I did use Data::Dumper.

More specifically: It seems the classic visitor pattern (accept, visit methods) is unnecessary in Perl because of Perl's simple support for reflection and autoloading. Is that correct? (It seems like that was the intention with PRD autotree?)

Also, do I need to track visited nodes? Is there a way that the visit sub could create an infinite loop while walking a parse tree?

Thanks.

  • Comment on Re^2: Parse::RecDescent autotree visitor

Replies are listed 'Best First'.
Re^3: Parse::RecDescent autotree visitor
by jethro (Monsignor) on Aug 10, 2011 at 18:42 UTC

    The built-in OO system in perl is really a basic set to object-orientation. It works quite well and if you want more distance to the nitty-gritty it allows you to build modules to get inside-out objects or have a more refined OO with Moose for example. So it isn't uncommon that OO features of the system are used for any purpose that fits.

    Naturally I can't look in the mind of Damian Conway, but I would guess that he just used the bless to store an attribute (the name of the token) so that the hash doesn't need a special key for it. While I'm sure he knows patterns I would guess that designing for or avoiding this pattern was not his intention. It was just a good use for objects and bless.

    And no to your second question, a loop in the parse tree would be a bug.