CC: | 10084191 [...] ticket.noris.net |
Subject: | error not undef after successful Net::DNS::Packet->new(\$data) |
The documentation of Net::DNS::Packet reads:
| METHODS
| new
[…]
| If called in array context, returns a packet object and an error
| string. The error string will only be defined if the packet
| object is undefined (i.e., couldn’t be created).
But since version 0.63, Net::DNS::Packet->parse(), this is no longer
true, at least when Net::DNS::Packet->new() is passed a reference to a
scalar containing DNS packet data.
The reason for this is that Net::DNS::Packet->parse(), which is called
by Net::DNS::Packet->new() under these circumstances, now returns $@:
return wantarray ? ($self, $@) : $self;
But as explained in perlvar(1), $@ is not undef after a successful
eval(), but "":
$@ The Perl syntax error message from the last eval() operator.
If $@ is the null string, the last eval() parsed and executed
^^^^^^^^^^^^^^^^^^^^^
correctly
Please find a test script for this bug attached.
Regards,
fany
Subject: | 04-packet-creation.t |
use Test::More tests => 6;
use strict;
BEGIN { use_ok('Net::DNS') }
ok( my $packet = Net::DNS::Packet->new('example.com'),
'packet could be constructed' );
ok( my $data = $packet->data, 'packet data is defined' );
my ( $new_packet, $error ) = Net::DNS::Packet->new( \$data );
ok( $new_packet, 'new packet could be constructed' );
is( $new_packet->data, $data, 'data of new packet is identical to old packet' );
ok( !defined $error, 'error string is undefined' );