Subject: | base fails with multiple packages in same file |
See test program below. This fails with:
Can't locate object method "new" via package "SecondClass" at
./base-test.pl line 27
Uncomment 'use LWP::UserAgent' from FirstClass, and the error goes away.
In short, there seems to be a condition under which base.pm detects the
package has having already been loaded, when in fact it has not.
Tracing through, with 'use LWP::UserAgent' (or 'use base
qw/LWP::UserAgent/') in FirstClass, has_version() in base.pm finds that
$vglob has a value, even though HTML::Parser is not in %INC, and thus
'eval "require $base"' is never called, leading to the error.
LWP::UserAgent doesn't use HTML::Parser directly, though it does
'require HTML::HeadParser' which in turn does 'use base HTML::Parser'.
I have not been able to track down exactly how VERSION has come to be
set without the file being included in %INC.
#! /usr/bin/perl
use strict;
use warnings;
SecondClass->new();
package FirstClass;
use strict;
use warnings;
use LWP::UserAgent;
sub new {
# ... whatever
}
package SecondClass;
use strict;
use warnings;
use base qw/HTML::Parser/;
sub new {
my $class = shift;
return $class->SUPER::new();
}