Skip Menu |

This queue is for tickets about the Net-DNS CPAN distribution.

Report information
The Basics
Id: 53595
Status: resolved
Priority: 0/
Queue: Net-DNS

People
Owner: Nobody in particular
Requestors: FANY [...] cpan.org
Cc: 10084191 [...] ticket.noris.net
AdminCc:

Bug Information
Severity: Normal
Broken in:
  • 0.63
  • 0.64
  • 0.65
  • 0.66
Fixed in: (no value)



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' );
From: rwfranks [...] acm.org
fany, The documentation is correct, the code wrong, the blame mine. I will add it to my list of things to fix. -- Dick
From: rwfranks [...] acm.org
Show quoted text
> ($packet, $error) = new Net::DNS::Packet(\$data); > > 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).
Thinking about this more carefully, it is clear from the text that the content of $error is not intended to be used if $packet was successfully created. I therefore propose that the code remain unchanged and the description modified to read: Show quoted text
> If called in array context, returns a packet object and an > error string. The content of the error string is unspecified > if the packet object was successfully created.
Code is erroneous if it makes use of $error when $packet is defined. -- Dick
Hi Dick, I agree. Documentation altered. Regards, Willem On Tue Jan 12 23:12:23 2010, rwfranks@acm.org wrote: Show quoted text
>
> > ($packet, $error) = new Net::DNS::Packet(\$data); > > > > 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).
> > Thinking about this more carefully, it is clear from the text that the > content of $error is not intended to be used if $packet was successfully > created. > > I therefore propose that the code remain unchanged and the description > modified to read: >
> > If called in array context, returns a packet object and an > > error string. The content of the error string is unspecified > > if the packet object was successfully created.
> > Code is erroneous if it makes use of $error when $packet is defined. > > -- > Dick