import - import all modules with the same package prefix, aliasing it away.


import documentation  | view source Contained in the import distribution.

Index


NAME

Top

import - import all modules with the same package prefix, aliasing it away.

'import' acts as a pragma that performs a 'use' on all modules that can be found with the given package prefix. Any modules found have a 'use' statement performed, and the fully qualified package name is aliased to one without the given prefix. The functionality is similar to Java's 'import' statement.

SYNOPSIS

Top

    use import qw( org::w3c::dom );  # Loads all .pm's in org/w3c/dom/*

    my $e1 = Entity->new();          # Aliased org::w3c::dom::Entity
    my $e2 = org::w3c::dom::Entity->new(); # Same thing.
    my $a1 = Attr->new();            # Wow, this one too.
    my $er = EntityReference->new(); # Hey, all the classes are here.

This next example assumes a different program, since it would have already been 'use'd from the first example.

    use import qw( org::w3c::dom::Text ); # loads only this module
    my $e3 = Text->new();                 # Aliased org::w3c::dom::Text

DESCRIPTION

Top

'import' is a Perl pragma that performs a 'use' statement on all modules that can be found within the given package prefix. The primary intended use of the pragma is to make typing easier for people who are porting Java code to Perl. Java has the ability to import all classes defined within a class' own package, as well as a notation to import all classes defined with some external package. While there is an equivalent mechanism for doing so in Perl, the 'use' operator, it is limited to importing a single class at a time, and the class must be explicitly specified.

This pragma provides Perl with a friendly syntax for performing importing oodles of modules without the oodles of 'use' statements previous Perl programmers had to endure. In addition, you were required to know in advance the names of any modules you would be importing. Thus, Laziness was the primary motivation for writing this module.

Since it isn't really a module or class that is imported into your code, but rather a "helper" for the <C>use</C> operator, Hubris demanded this be developed as a "pragma" type of module. Pragmas are a rare and pretty special type of module, and writing of them occurs after much discussion over their necessity and they are usually authored by the perl-porters. I got Impatient waiting for one of them to see the need and write this module.

METHODS

Top

Public Package Methods

This module defines only one method, import(), as this is the module you are technically 'use'ing in your code.

Internal Package Methods

No internal methods are defined.

Exported Package Variables

No variables are exported.

Internal Package Variables

No internal variables are defined.

RETURN VALUE

Top

The value returned by executing the package is 1 (or true).

ENVIRONMENT

Top

FILES

Top

ERRORS

Top

WARNINGS

Top

DIAGNOSTICS

Top

BUGS

Top

RESTRICTIONS

Top

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

CPAN DEPENDENCIES

Top

LOCAL DEPENDENCIES

Top

SEE ALSO

Top

Carp, DirHandle

NOTES

Top

This pragma removes itself from the %INC hash, allowing it to be 'use'd again.

ACKNOWLEDGEMENTS

Top

AUTHOR(S)

Top

mak - Michael King ( mike808@mo.net )

HISTORY

Top

 import.pm
 v1.01 10/10/99 mak

CHANGE LOG

Top

 1.01 first posting to CPAN

MODIFICATIONS

Top

COPYRIGHT

Top

AVAILABILITY

Top

The latest version of this module is likely to be available from:

 http://walden.mo.net/~mike808/LogCarp

The best place to discuss this code is via email with the author.


import documentation  | view source Contained in the import distribution.