develooper Front page | perl.perl5.porters | Postings from October 2003

Re: cannot AUTOLOAD a method called VERSION

Thread Previous
Graham Barr
October 21, 2003 11:25
Re: cannot AUTOLOAD a method called VERSION
Message ID:
On 21 Oct 2003, at 13:59, Dirk Koopman wrote:
> It appears that AUTOLOAD will never see a request for a method (an
> autogenerated external data dictionary accessor in my case) called

That is correct. And is the same for all methods that are defined in 
UNIVERSAL because AUTOLOAD is only called if a method cannot be found 
and methods in UNIVERSAL can be found in all classes.

>  It will simply bypass it and try to return the (usually
> non-existant) scalar $FOO::VERSION (and, failed, the error message
> associated with that).

That is not strictly true. When called UNIVERSAL::VERSION looks at its 
first argument to obtain a package name. If then access $VERSION in 
that package. If there is no second argument it simply returns that 
VERSION, if there is it does a comparison and die it the VERSION is 
less than the given argument.

> This is fixed by having an explicit method called VERSION in one
> of the ancestors (ie: sub VERSION {...}).

Actually you can get AUTOLOAD to be called by doing


But I would reccomend against doing this. The VERSION method is used by 
perl itself if the module is use'd and a version is requested, eg

   use Foo 1.12;

is actually

   BEGIN {
     require Foo;


> I wonder what other 'magical' names there are?
> Dirk
> -- 
> Please Note: Some Quantum Physics Theories Suggest That When the
> Consumer Is Not Directly Observing This Message, It May Cease to
> Exist or Will Exist Only in a Vague and Undetermined State.

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About