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' %] [% 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. 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) 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. My next steps would be: 1) better understand the debugging output so I better understand what I am looking at. 2) break down and write a plugin. If I find a solution I will post back to the thread. If anyone has any further ideas I would love to hear them :) Thanks to all.
_______________________________________________ templates mailing list templates@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates