in reply to Default import function

That's what use does. Compare the output of the following commands:
~ $ perl -lwe '{package My; sub x {}} $INC{"My.pm"}=1; +print for keys %{"My::"}' x ~ $ perl -lwe '{package My; sub x {}} $INC{"My.pm"}=1; eval "use My"; +print for keys %{"My::"}' import x

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Default import function
by Athanasius (Cardinal) on Oct 24, 2016 at 06:37 UTC

    Hello choroba,

    That's what use does.

    Yes, according to the documentation for use, it calls the import function:

    It is exactly equivalent to
    BEGIN { require Module; Module->import( LIST ); }
    except that Module must be a bareword.

    But how does use call a function that hasn’t been defined anywhere? Are you saying that use itself creates an import function for the target module? (And if so, what are the contents of that function?)

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

      I haven't checked the source, but it seems so, don't you think? The created sub seems empty:
      ~ $ perl -lwe '{package My; sub x {}} $INC{"My.pm"}=1; eval "use My"; +use Data::Dumper; $Data::Dumper::Deparse = 1; print Dumper \&$_ for v +alues %{"My::"}' $VAR1 = sub { package My; }; $VAR1 = sub ;;

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

        That makes sense, at least in retrospect. As was mentioned earlier, use() is equivalent to require() followed by import(). The minimum implementation is probably to have class UNIVERSAL, which all Perl classes inherit from, have an empty import(), which in fact it does.

        So, to go back to the original question, it appears the most useful answer is that your Perl class in fact gets an import() method from somewhere, but the default one, inherited from UNIVERSAL, does nothing, so presumably they felt no need to document it. It's not documented under UNIVERSAL either.