in reply to Default import function

Thanks to all who replied!

choroba: Data::Dumper::Deparse looks useful, thanks. I wasn’t aware of it, as I usually use Data::Dump, which doesn’t seem to have an equivalent function (it always prints sub { ... }).

Anonymous Monk: I thought of UNIVERSAL, but as others have said, that’s not the source of the import in question. As I understand it, UNIVERSAL is inherited by every class, meaning it applies only where there is a blessed reference. In my minimal example, MyMod is a module but not a class.

salva: Thanks for the source code extract! I think this special case should be documented in the entry for import. Also, good point about distinguishing between import being defined and merely being entered in the symbol table. (But I wonder: since, as you have shown, import is special-cased so that invoking it when it’s not defined is passed over in silence, why is it necessary or useful to add it to the symbol table at all in this case?)

dave_the_m: Thanks for the explanation!

1nickt: “I murmur a chant of gratitude” Amen!

Cheers,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Default import function
by salva (Canon) on Oct 25, 2016 at 07:37 UTC
    But I wonder: since, as you have shown, import is special-cased so that invoking it when it’s not defined is passed over in silence, why is it necessary or useful to add it to the symbol table at all in this case?

    That's probably just an implementation detail.

    It is common for symbol table entries to be created whenever the name is referenced. For instance, the following code...

    sub foo { bar(); return $baz }
    adds entries for foo, bar and baz.
    $obj->non_existent_method;
    dies but after creating an entry for non_existent_method.