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

Re: require UNIVERSAL;

Thread Previous | Thread Next
From:
Graham Barr
Date:
October 6, 2003 09:05
Subject:
Re: require UNIVERSAL;
Message ID:
DA361A0E-F816-11D7-B726-0003938857CC@pobox.com
On 6 Oct 2003, at 16:05, Slaven Rezic wrote:
> The explicit usage/requirement of UNIVERSAL.pm 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.pm:
>
> # 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 UNIVERSAL.pm 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 UNIVERSAL.pm 
> should
> be changed and it should say in big letters to not use or require
> UNIVERSAL.

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

http://search.cpan.org/perldoc?UNIVERSAL::exports

which is just as evil

Graham.


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