in reply to Re: loading modules at runtime
in thread loading modules at runtime

Module->import( PARAMETERS );

Indirect method invocation has severe and difficult-to-debug ambiguities.

Replies are listed 'Best First'.
Re^3: loading modules at runtime
by ikegami (Patriarch) on Oct 14, 2006 at 21:08 UTC

    Module might not have an import.

    Module->import( PARAMETERS ) if Module->can('import');

    This is rather moot, since once usually wants to avoid importing from a dynamically loaded module.

      Module might not have an import.

      There's one in UNIVERSAL, if anything has loaded that. Besides:

      # in NoImport.pm package NoImport; 1; # in no_import.pl use strict; use warnings; require NoImport; NoImport->import();

      But the import routine might also do other things than setting up symbols in the calling namespace - it might set up internal data corresponding to the namespace. So it doesn't hurt to call import, or at least to read the documentation of the imported module to see what it actually does.

        use Module (); is the documented way of not importing symbols into your namespace. use Module (); does not call import.

        Furthermore, there is no stated requirement for all packages that use a module to use it. I often do use Module (); { package PkgA; ... } { package PkgB; ... } { package PkgC; ... }. Notice import was not called from any of the 4 packages involved.

        A module should not rely on import being called. (Pragmas are another matter.)