Mark,
1) Header.pm is an internal component of a Packet object. The
encode/decode methods are not intended to be used outside that context.
Your code example encountered this issue because there was no means of
discovering the length of the packet data actually decoded.
A mechanism has now been added:
my ( $packet, $length ) = new Net::DNS::Packet( \$buffer );
2) Packet decoding is now done in one place and no reference to the
data buffer is retained. There is a performance penalty for doing that,
but we will need to live with that or claw it back elsewhere.
3) A special reply() constructor has been added to Packet.pm
my $reply = $query->reply();
Dick