Skip Menu |

This queue is for tickets about the base CPAN distribution.

Report information
The Basics
Id: 63564
Status: resolved
Priority: 0/
Queue: base

People
Owner: Nobody in particular
Requestors: gfuji [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: (no value)
Fixed in: (no value)



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'); +
Subject: base::has_version() should check $VERSION is defined
Oops, this ticket seems the same as RT #60960, but I don't close it because of the attached patch. See also https://rt.cpan.org/Public/Bug/Display.html?id=60960
base 2.18 no longer has has_version and does not mess with the version of pulled in modules.