develooper Front page | perl.perl5.porters | Postings from July 2011

Re: UNIVERSAL::VERSION and base.pm

Thread Previous | Thread Next
From:
Father Chrysostomos
Date:
July 3, 2011 13:14
Subject:
Re: UNIVERSAL::VERSION and base.pm
Message ID:
8BD2F38A-74AF-4A8C-BF77-4E8B66CD4B02@cpan.org

On Jun 20, 2011, at 3:25 AM, John Peacock wrote:

> On 06/19/2011 11:41 PM, Father Chrysostomos wrote:
>> I’ve come up with a simple way to fix the incompatibility between UNIVERSAL::VERSION and base.pm: stop UNIVERSAL::VERSION from parsing the version if called with no arguments. When called simply as package->VERSION, the purpose is to retrieve the v...bersion number, so why is VERSION trying to parse it anyway? It didn’t in 5.8.
> Because version objects were introduced into the core in 5.10.0.  UNIVERSAL::VERSION always did double duty (in that with a parameter it would do a comparison and without would return the package $VERSION), so when version objects were added, it only made sense to upgrade the scalar to a version object so it could be used in a comparison.  

But such should not be necessary if no comparison is to take place.

> The fact that it returns the stringified form, rather than a version object directly, was a matter of some discussion.
> 
> What bug(s) are you trying to fix?  I see nothing in rt about base.pm and UNIVERSAL::VERSION, but then maybe my searching skills have atrophied.  The real problem is base.pm is excessively clever (not) and should be deprecated in favor of parent.pm.

base.pm does useful things that parent.pm doesn’t do. (Each module in turn considers that a feature.)

base.pm sets $VERSION to "-1, set by base.pm" in some cases, so it knows the package has been loaded. Some have expressed astonishment on learning that, but no-one has suggested a better way to detect whether a package is loaded. (You can’t just check the existence of the stash, as merely mentioning the package in a fully qualified sub call autovivifies it during compilation.)

> 
>> (This also resolves a CPAN ticket for another VERSION problem.)
> Citation please?

I don’t remember the bug number off hand, but this is the issue:

Code like this used to work in 5.8.x:

$VERSION = "3alpha";

sub VERSION {
  my $version = shift->SUPER::VERSION;
  if(@_) {
     .... do custom comparison ....
     die $message if $too_old
  }
  $version
}

Such code, which is just using SUPER::VERSION to fetch the version number (since it’s clea[rn]er that ‘do{no strict "refs"; ${(length ref($_[0]) ? ref $_[0] : $_[0])."::VERSION"}}’), and which in 5.8.x is a perfectly acceptable use of UNIVERSAL::VERSION, broke in 5.10.0.


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About