Parse::RecDescent::Topiary - tree surgery for Parse::RecDescent autotrees
use Parse::RecDescent::Topiary; my $parser = Parse::RecDescent->new($grammar); ... my $tree = topiary( tree => $parser->mainrule, namespace => 'MyModule::Foo', ucfirst => 1 );
Parse::RecDescent has a mechanism for automatically generating parse trees. What this does is to bless each resulting node into a package namespace corresponding to the rule. This might not be desirable, for a couple of reasons:
You probably don't want to pollute the top-level namespace with packages, and you probably don't want your grammar rules to be named according to CPAN naming conventions. Also, the namespaces could collide if an application has two different RecDescent grammars, that share some rule names.
Parse::RecDescent merely blesses the data structures. It does not call a constructor. Parse::RecDescent::Topiary calls
newfor each class. A base class, l<Parse::RecDescent::Topiary::Base> is provided in the distribution, to construct hashref style objects. The user can always supply their own - inside out or whatever.
This exported function takes a list of option / value pairs:
Pass in the resulting autotree returned by a Parse::RecDescent object.
Optional prefix to use for package names.
Optional flag to upper case the first character of the rule when forming the class name.
Please report bugs to http://rt.cpan.org
Ivor Williams CPAN ID: IVORW email@example.com
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.