Tidying up Parse::RecDescent autotrees with topiary

ivorw on 2006-06-18T16:28:50

The work on cronic has made me think about using Parse::RecDescent autotrees in modules, as I want to turn the guts of cronic into one or more bot plugins.

The issue is that autotrees have their nodes blessed into packages corresponding to the rule names. To my mind, this sucks for two reasons. Firstly, you're polluting a namespace with no control, and secondly the objects should be brought into existence through a constructor, not blessing.

I toyed with rolling my own trees with an autorule, but this didn't give me what I wanted. I posted a wishlist item to RT, but I don't know when that will get looked at, as I know Damian is a busy man.

I looked briefly at the code in Parse::RecDescent to see if it is patchable, then came up with a better idea. This better idea is to post-process the output from the parser, walking the tree, building properly constructed nodes in a sensible namespace.

Voila:

Parse::RecDescent::Topiary