Hi,
We found that `perl -E 'use LWP; use base(); say
base::has_version("HTML::Parser")'` prints 1 but HTML::Parser is not loaded.
This is because base::has_version() checks the existence of
*pkg::VERSION and if one refers $pkg::VERSION then its glob terns into
existence. This means that `use base qw(Foo)` could silently fail if one
checks $Foo::VERSION in somewhere before. Thus, base::has_version() must
check defined($pkg::VERSION) to avoid this problem. Can you review my
patch to fix it?
Thanks,
--
Goro Fuji (gfx) GFUJI at CPAN.org
Subject: | base.pm.patch |
diff --git a/lib/base.pm b/lib/base.pm
index 2f6a19e..f809b1a 100644
--- a/lib/base.pm
+++ b/lib/base.pm
@@ -25,7 +25,7 @@ sub has_fields {
sub has_version {
my($base) = shift;
my $vglob = ${$base.'::'}{VERSION};
- return( ($vglob && *$vglob{SCALAR}) ? 1 : 0 );
+ return( ($vglob && *$vglob{SCALAR} && defined(${ $vglob })) ? 1 : 0 );
}
sub has_attr {
diff --git a/t/version-defined.t b/t/version-defined.t
new file mode 100644
index 0000000..2397b51
--- /dev/null
+++ b/t/version-defined.t
@@ -0,0 +1,13 @@
+#!perl
+use strict;
+use Test::More tests => 1;
+
+use base ();
+
+if(0) { # emulate LWP::UserAgent's problem
+ if($HTML::Parser::VERSION > 0) { }
+ if($HTML::Parser::VERSION > 0) { } # avoid warnings
+}
+
+ok !base::has_version('HTML::Parser');
+