in reply to Re: import() magic
in thread import() magic

If the function is not being created, then how is it possible to call the function without crashing? This does not crash, for example:

$x = bless {}, 'Foo'; $x->import( 'whatever' );

Replies are listed 'Best First'.
Re: Re2: import() magic
by Ovid (Cardinal) on May 29, 2002 at 22:44 UTC

    If you read the docs carefully, you'll see that even though import is not a built-in, it is has 'magic' treatment.

    Ovid@OT-D1 ~ $ perl -e '$x=bless{}, "Foo";$x->import;print "Defined" if defined &Fo +o::import' Ovid@OT-D1 ~ $ perl -e 'print "Defined" if defined &UNIVERSAL::isa' Defined

    As you can see from the above snippet, even though we call an import method, none is actually defined in %Foo::. I threw in the %UNIVERSAL:: test so you can see how that test works. Here's proof that it is "special". Note that the call to the non-existent method &Foo::import is successful, but the second call to a non-existent method is not.

    $ perl -e '$x=bless{}, "Foo";$x->import;$x->no_way' Can't locate object method "no_way" via package "Foo" (perhaps you for +got to load "Foo"?) at -e line 1.

    Cheers,
    Ovid

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