On Tue, Jan 29, 2002 at 02:55:37PM -0500, Ron Newman wrote:
> The following program does not cause an error, even though
> my package neither defines a function called import(), nor 
> inherits from any other package:
> 
>   #!/usr/bin/perl -w
>   use strict;
> 
>   package This;
>   This->import();
> 
> My question: What function is it calling, and where did it
> find that function?  Is there a UNIVERSAL::import() which
> does nothing?
> 

It turns out that import() gets a bit of special treatment; if the method
doesn't exist, the error is ignored.

perldoc -f use:
 
    The BEGIN forces the require and import() to
    happen at compile time.  The require makes sure
    the module is loaded into memory if it hasn't been
    yet.  The import() is not a builtin--it's just an
    ordinary static method call into the "Module"
    package to tell the module to import the list of
    features back into the current package.  The
    module can implement its import() method any way
    it likes, though most modules just choose to
    derive their import() method via inheritance from
    the Exporter class that is defined in the Exporter
    module.  See the Exporter manpage.  If no import()
    method can be found then the error is currently
    silently ignored.  This may change to a fatal
    error in a future version.


Ronald

Reply via email to