Brian Sherwood wrote:
> Thank you all. A lot of good ideas, but so far no luck :(
>
> Simon recommended writing a plugin, or wrapping Net::IP using
> Template::Plugin::Class
> I tried using the Template::Plugin::Class, but it would throw an exception.
> I used the following code:
>
> [% connector1 = '1.2.10.128/29 <http://1.2.10.128/29>' %]
> [% USE c1_net = Class ('Net::IP') %]
>
> [% c1.net.set(connector1) %]
>
> connector1 = [% c1_net.prefix %]
>
> returns
>
> Uncaught exception from user code:
> undef error - Can't use string ("Net::IP") as a HASH ref while
> "strict refs" in use at /usr/lib/perl5/vendor_perl/5.10.0/Net/IP.pm line
> 372.
That's not surprising is it?
line 372 is is_prefix, which needs an object as invoker and is invoked
on the invocant of prefix. But you've invoked prefix as a class method.
It is documented as an object method, so why did you expect it to work?
BTW, what is the variable c1 on the previous line?
> This is occurring at the following line:
> $tt->process( $template, $vars )
> || die $tt->error(), "\n";
>
>
> A couple of people recommended using debugging.
>
> At first glance, the debugging looks ok to me:
>
> $stash->set('c1_net', $context->plugin('Net::IP', [
> $stash->get('connector1') ]));
>
> $stash->set('c2_net', $stash->get(['c1_net', 0, 'ip_add_num', [ 2 ]]));
>
> $output .= $stash->get(['c1_net', 0, 'prefix', 0]);
>
> But throws and exception when I turn on DEBUG_UNDEF:
>
> [Template::Context] plugin(Net::IP, 1.2.10.128/29 <http://1.2.10.128/29>)
> Uncaught exception from user code:
> undef error - prefix is undefined
>
>
> Someone also recommended instantiating the object in the perl code and
> passing it in the vars hash when I call the template toolkit. This is a
> good idea, but I don't know how many Net::IP objects I will need before
> the template is called.
>
>
> My hope for a quick fix is fading, but I did received a lot of good
> information.
>
> As far as I can tell, the Net::IP class seems to work find for all
> methods, except the ip_add_num method that returns a reference to a new
> object. I assume the problem is something to do with the way the
> reference is stored or retrieved.
I don't know Net::IP and I don't know enough about Perl semantics to
know whether it's significant so I'll just point out that ip_add_num()
is an undocumented private method that is intended to be called by the
overloaded '+' operator, and ask whether any gurus know if this is
significant?
Cheers, Dave
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates