in reply to import() magic
From perldoc -f use on 5.6.1: If no "import" method can be found then the call is skipped.
What that means (to me) is that the appropriate typeglob in the appropriate namespace is searched for an import() method. However, we can't look for a slot in the typeglob without the typeglob existing, so Perl is autovivifying *import for you, if it doesn't exist. I don't know that this is documented anywhere, though.
ferrency wrote:
However, the test above demonstrates that independant of use, trying to call method import which doesn't exist is handled differently than with almost any other method ("almost" only because I'm not 100% sure there is no other similar case... I don't know of any offhand, however).
There are other methods. Specifically, those that are inherited from the UNIVERSAL class (all objects inherit from there).
Ovid@OT-D1 ~ $ perl -MData::Dumper -e ' my $x = bless {}, 'Foo'; print Dumper (\%Foo::); $x->can('bar'); print Dumper (\%Foo::); print Dumper (\%UNIVERSAL::)'
That produces:
$VAR1 = {}; $VAR1 = { 'can' => *Foo::can, 'bar' => *Foo::bar }; $VAR1 = { 'can' => *UNIVERSAL::can, 'bar' => *UNIVERSAL::bar, 'isa' => *UNIVERSAL::isa, 'VERSION' => *UNIVERSAL::VERSION };
I think it's very interesting to note that testing to see if the your object can perform a particular method will autovivify the appropriate entry in the UNIVERSAL namespace if it's not found. I can't think of any way this will screw things up, but it seems a bit odd.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|