develooper Front page | perl.perl5.porters | Postings from September 2013

Fwd: [ #88572] UNIVERSAL::VERSION and argument checking

September 10, 2013 08:26
Fwd: [ #88572] UNIVERSAL::VERSION and argument checking
Message ID:
Subject: UNIVERSAL::VERSION and argument checking
MIME-Version: 1.0
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
Message-ID: <>
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 925

As far as I can tell, the UNIVERSAL::VERSION in the perl core has always been callable with no arguments, but reads past the end of the stack (seeing the argument to pp_entersub; usually the *UNIVERSAL::VERSION glob, but possibly a string used to call the sub).

$ perl -le '*Foo = *UNIVERSAL::VERSION; $Foo::VERSION = 10; $_ = "Foo"; print $_->()'
$ perl -le '*Foo = *UNIVERSAL::VERSION; $Foo::VERSION = 10; $_ = \&Foo; print $_->()'
Cannot find version of an unblessed reference at -e line 1.

But’s UNIVERSAL::VERSION requires at least one argument:

$ perl -Mblib -Mversion -le '*Foo = *UNIVERSAL::VERSION; $Foo::VERSION = 10; $_ = "Foo"; print $_->()'
Usage: version::vxs::_VERSION(sv, ...) at -e line 1.

I think the former behaviour is wrong, but the latter is less helpful than it could be.

I would suggest:

Usage: UNIVERSAL::VERSION(sv, ...) at -e line 1.

I’m going to forward this to p5p, too. Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About