While running ttree I've run into what appears to be a bug when
using the LOAD_PERL option. I'm using v2.04
I think I've tracked down where it is occurring, but I'm not quite
sure what is the optimal way to go about patching/fixing it.
With LOAD_PERL => 1, you should be able to pull in a standard
perl module like so,
[% USE net = Net.Netmask('198.168.14.0/24') %]
This works great on the first iteration, but barfs on subsequent
calls.
The problem is in Template::Plugins::fetch()
95 $args ||= [ ];
96 unshift @$args, $context;
97
98 $factory = $self->{ FACTORY }->{ $name } ||= do {
99 ($factory, $error) = $self->_load($name, $args);
100 return ($factory, $error) if $error; ## RETURN
101 $factory;
102 };
103
The first time through $self->{ FACTORY }->{ $name } (where $name == 'Net.Netmask' in
this case) is undefined. That allows us to drop down and call
$self->_load(), which shifts $context off $args. For a Plugin, you
want $context on the args list, but not for a non-plugin perl module.
The problem is that the next go around, $self->{ FACTORY }->{ $name } is
defined and nothing unshifts $args.
Later we call...
108 $plugin = $factory->new(@$args)
109 || die "$name plugin failed: ", $factory->error(), "\n"; ## DIE
which on subsequent invocations sends Net::Netmask->new($context, ...), which
gives Net::Netmask->new() a good case of indigestion.
I haven't determined whether Template::Plugins::fetch should not be called
for subsequent invocations.
Otherwise, we need to be able to distinguish factories which are plugins
vs. those that are not so we can pass in the arguments correctly.
Any thoughts on how and where to flag a factory as a plugin vs non-plugin?