Subject: | uninitialized variable warning in the debugger when using NEXT::AUTOLOAD + warnings |
Using the debugger with code using NEXT::AUTOLOAD causes an uninit
variable warning from within the debugger code. Using the attached
example script:
$ perl -dw /tmp/next.pl
Loading DB routines from perl5db.pl version 1.28
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(/tmp/next.pl:17): my $obj = bless {}, "CN";
DB<1> c
CN=HASH(0x94a660): CN AUTOLOAD
Use of uninitialized value in concatenation (.) or string at
/usr/lib/perl5/5.8.8/perl5db.pl line 3617.
at /usr/lib/perl5/5.8.8/perl5db.pl line 3617
CN::AUTOLOAD('CN=HASH(0x94a660)') called at /tmp/next.pl line 18
CN=HASH(0x94a660): BN AUTOLOAD
Use of uninitialized value in concatenation (.) or string at
/usr/lib/perl5/5.8.8/perl5db.pl line 3617.
at /usr/lib/perl5/5.8.8/perl5db.pl line 3617
BN::AUTOLOAD('CN=HASH(0x94a660)') called at
/usr/lib/perl5/5.8.8/NEXT.pm line 80
NEXT::AUTOLOAD('CN=HASH(0x94a660)') called at /tmp/next.pl line 13
CN::AUTOLOAD('CN=HASH(0x94a660)') called at /tmp/next.pl line 18
CN=HASH(0x94a660): AN AUTOLOAD
Debugged program terminated. Use q to quit or R to restart,
The error is from DB::sub, in the assignment to $al:
# If the last ten characters are C'::AUTOLOAD', note we've traced
# into AUTOLOAD for $sub.
if ( length($sub) > 10 && substr( $sub, -10, 10 ) eq '::AUTOLOAD' ) {
$al = " for $$sub";
}
When this is called for an AUTOLOAD sub, $sub == 'CN::AUTOLOAD', so
$$sub deferences $CN::AUTOLOAD, which is 'CN::method' (in the example
script).
But, when redispatched to $self->NEXT::AUTOLOAD(), $sub ==
'NEXT::AUTOLOAD', and $NEXT::AUTOLOAD isn't set.
Subject: | next.pl |
use NEXT 0.6;
package AN;
sub AN::AUTOLOAD { print "$_[0]: AN AUTOLOAD\n" }
sub AN::DESTROY { }
package BN;
use base qw( AN );
sub BN::AUTOLOAD { print "$_[0]: BN AUTOLOAD\n"; $_[0]->NEXT::AUTOLOAD() }
package CN;
use base qw( BN );
sub CN::AUTOLOAD { print "$_[0]: CN AUTOLOAD\n"; $_[0]->NEXT::AUTOLOAD() }
package main;
my $obj = bless {}, "CN";
$obj->method();