in reply to import() magic

Well this sure is crazy and appears to be undocumented behaviour[1]. But poking at the source for perl 5.6.1 it looks like it's quite normal for perl behave in this way. If you look at the Perl_gv_fetchmethod_autoload function in gv.c you'll find the following lines of code
gv = gv_fetchmeth(stash, name, nend - name, 0); if (!gv) { if (strEQ(name,"import") || strEQ(name,"unimport")) gv = (GV*)&PL_sv_yes; else if (autoload) gv = gv_autoload4(stash, name, nend - name, TRUE); }
So from what I gather the import and unimport methods are automatically handled by perl and internally autoloaded as scalar variables. As to why this is and what purpose it serves I am in totally in the dark.
HTH

_________
broquaint

[1] I sit corrected as Ovid points out in his node that this behaviour is documented albeit surreptitiously

Replies are listed 'Best First'.
Hey...two bugs in Perl from one node?
by Ovid (Cardinal) on May 29, 2002 at 20:21 UTC

    Actually, according to the docs: If no "unimport" method can be found the call fails with a fatal error., so this should fail:

    $ perl -e ' *UNIVERSAL::import = sub { print "Whoops!" }; my $x = bless {}, 'Foo'; $x->import; no Foo'

    Except it doesn't fail. This appears to be misdocumented. If you use strict, you'll get a baredword warning, but that's still not what the docs say. Am I misreading?

    Further, I think the symbol table entries should not be autovivified. If you're doing some funky work walking the symbol table, those 'faux' entries could cause bad results. I don't like it. Nosireebob. I don't.

    Cheers,
    Ovid

    Update: Added the word 'not'. Kinda changes the meaning, doncha think? :)

    Update 2: I submitted a POD patch to P5P, but Abigail beat me to it.

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      From perldelta for perl 5.6.1:
      no Module; does not produce an error even if Module does not have an unimport() method. This parallels the behavior of use vis-a-vis import.

      Seems like they just forgot to update perlfunc.

      Cheers,
      -Anomo