[Pdx-pm] fun with import()

Eric Wilhelm scratchcomputing at gmail.com
Sun Aug 6 15:48:12 PDT 2006

# from chromatic
# on Sunday 06 August 2006 01:45 pm:

>        use UNIVERSAL 'isa';
>... and pretend as if isa() and can() are functions.

Justifiable finger-wagging aside, is that the only "historical accident" 
part of it?  If so, that is fixable.

Is anyone relying on Foo->import() landing in UNIVERSAL::import()?  I 
would say it would be fair enough to break it.

>The comment in UNIVERSAL.pm reads:
>        # The use of Exporter below is a historical
>        # accident that can't be fixed without breaking code.


  # can/t.pm
  package can::t;
  require UNIVERSAL;
  require Exporter;
  *UNIVERSAL::import = sub {
    my $self = shift;
    ($self eq 'UNIVERSAL') or return; # should we goto somewhere?
    @_ or return;
    carp("chromatic said to stop it (and tell your friends)");
    Exporter::import($self, @_);

We'll have to work on the edge cases of storing an intentionally 
installed UNIVERSAL::import (but maybe anyone doing that should `use 
can't "don't";` or something.)  And, I guess `no can't` might also be 
in order because sometimes it helps to have enough rope to shoot 
yourself in the foot with.

>I did fix the documentation in bleadperl to suggest therapy instead of
>importing isa() and can(); I'm not sure if it went into maintperl at
> some point.

Just breaking it might get their attention.

  $ perldoc -f use | grep -A 1 'If no "import"'
  ...  If no "import" method can be found then the call is

IMO, that pod is much more visible than an "I wish this weren't so" 

Chicken farmer's observation:  Clunk is the past tense of cluck.

More information about the Pdx-pm-list mailing list