Steven Lembark > Attribute-Imports-0.1 > Attribute::Imports:


Annotate this POD

View/Report Bugs


Attribute::Imports: pull code, scalar, array, or hash symbols into the current package.


Modules that export items by name can cause confusion due to undocumented exports or collisions due to re-used names. Importing the symbols into explicitly named items in the local package avoids [most] issues.

    # say you wanted to use 'filebase' as the sub 
    # name to determine the base name of a file.

    use File::Basename qw();

    sub filebase :imports( qw( &File::Basename::basename ) );

    # or you wanted to avoid varaible collisions.

    require Foo;
    require Bar;

    our $foo_verbose    :imports( qw( $Foo::verbose ) );
    our $bar_verbose    :imports( qw( $Bar::verbose ) );

    # or give more descriptive values to the 
    # variables in your context.

    our @prefix         :imports( qw( @Mod1::Names ) );
    our @suffix         :imports( qw( @Mod2::Names ) );

    our %matchlist      :imports( qw( %Blah::known_names ) );

    # notice the lack of lexical variables 
    # and anonymous subs: neither of these
    # have a symbol table entry to install
    # the imported symbol into.


This uses the Symbol module to access the value of a requested symbol, and the CODE, SCALAR, ARRAY, or HASH entry of the remote symbol to pull a value into the current package.


This module is released under the same terms as Perl-5.10.0.


Steven Lembark <>

syntax highlighting: