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

Re: require UNIVERSAL;

Thread Previous | Thread Next
Graham Barr
October 6, 2003 09:05
Re: require UNIVERSAL;
Message ID:
On 6 Oct 2003, at 16:05, Slaven Rezic wrote:
> The explicit usage/requirement of seems to break things:
> $ perl -Mless=time -e1
> (no errors)
> $ perl -MUNIVERSAL -Mless=time -e1
> "time" is not exported by the less module
> Can't continue after import errors at -e line 0
> BEGIN failed--compilation aborted.
> I see the following comment and code in
> # UNIVERSAL should not contain any extra subs/methods beyond those
> # that it exists to define. The use of Exporter below is a historical
> # accident that can't be fixed without breaking code.  Note that we
> # *don't* set @ISA here, don't want all classes/objects inheriting from
> # Exporter.  It's bad enough that all classes have a import() method
> # whenever is loaded.
> require Exporter;
> *import = \&Exporter::import;

Well as the search only would have got here if the package in question 
did not have an import sub and if UNIVERSAL did not then perl would be 
silent, could we do

sub import {
   goto &Exporter::import if $_[0] eq 'UNIVERSAL';

Which will allow UNIVERSAL to continue to export but ignore things when 
called by inheritance

> Can anybody remember the requirement for defining the import alias?
> Can it be removed? If not, then the documentation of 
> should
> be changed and it should say in big letters to not use or require

IIRC much of UNIVERSAL was originally implemented in a module before it 
was made into XS and included in the core. It was then that import was 
mistakenly added.

And then there is also

which is just as evil


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