yes, thank you Simon.

When I did my perl test I used a different method than prefix.  (my bad, I
should of tested the exact same methods, I assumed that if one or two worked
they all would work.)

Under the perl debugger the problem becomes clear:

c1_net is the object created with new.

  DB<10> x $c1_net
0  Net::IP=HASH(0xa60eed4)
   'binip' => 00000001000000100000101010000000
   'binmask' => 11111111111111111111111111111000
   'intformat' => Math::BigInt=HASH(0xa60f0d4)
      'sign' => '+'
      'value' => ARRAY(0xa60f134)
         0  6910976
         1  1
   'ip' => '1.2.10.128'
   'ipversion' => 4
   'is_prefix' => 1
   'last_bin' => 00000001000000100000101010000111
   'last_int' => Math::BigInt=HASH(0xa60efd4)
      'sign' => '+'
      'value' => ARRAY(0xa60f1d4)
         0  6910983
         1  1
   'last_ip' => '1.2.10.135'
   'mask' => '255.255.255.248'
   'prefix' => '1.2.10.128/29'
   'prefixlen' => 29

c2_net is the new object returned bu ip_add_num.

  DB<11> x $c2_net
0  Net::IP=HASH(0xa60f0c4)
   'binip' => 00000001000000100000101010000010
   'ip' => '1.2.10.130'
   'ipversion' => 4
   'is_prefix' => 0
   'last_bin' => 00000001000000100000101010000111
   'last_ip' => '1.2.10.135'


For some reason the ip_add_num does not fill out all the variables internal
to the object.
I just assumed that it would return a complete object, not one that only
defined half the internal variables.


>From here I will be trying two options:
1) Contact the author of Net::IP and see if there is a reason for this, if
so document it, if not ask if it can be fixed.
2) Take the incomplete Net::IP object and see if I can create a complete
object from it.

Thank you everybody.



On Thu, Feb 12, 2009 at 1:08 PM, Simon Wilcox <[email protected]> wrote:

> Hi Brian,
>
> On 11/2/09 02:58, Brian Sherwood wrote:
>
>> I am trying to use the Net::IP module within a template and seem to be
>> having some problems.
>> I am setting LOAD_PERL and just loading the standard Perl Net::IP module.
>>
>
> I don't think this is a TT problem. The equivalent perl code doesn't work
> either:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use Net::IP;
>
> my $connector1 = '1.2.10.128/29';
>
> my $c1_net = Net::IP->new( $connector1 );
>
> print "connector1 = " . $c1_net->prefix . "\n";
> print "connector1 = " . $c1_net->ip . ' ' . $c1_net->mask . "\n";
>
> my $c2_net = $c1_net->ip_add_num( 2 );
>
> print "connector2 = " . $c2_net->prefix . "\n";
>
>
> #####################
>
> Gives the output:
>
> connector1 = 1.2.10.128/29
> connector1 = 1.2.10.128 255.255.255.248
> Use of uninitialized value in concatenation (.) or string at netip.pl line
> 16.
> connector2 =
>
> ######################
>
>
> I'm not familiar with this module but it doesn't appear to implement an
> ip_add_num method. No wait, it's the internal method for overloading +.
>
> It looks like some sort of bug in Net::IP but once you get the perl version
> working you should be able to translate that into TT syntax.
>
> This obviously highlights one reason for not doing that as it's harder to
> write your tests to target the templates than it is to write tests for perl
> code using the great test tools that are available from the CPAN.
>
> Best of luck.
>
> Simon.
>
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to