Sub::Import - import routines from most anything using Sub::Exporter
version 1.002
use Sub::Import 'Some::Library' => ( some_routine => { -as => 'some_other_name' }, other_routine => undef, );
Some more examples:
# import a function with a custom name use Sub::Import 'Digest::MD5', md5_hex => {-as => 'md5sum'}; # import multiple functions, each with its own name use Sub::Import 'MIME::Base64', encode_base64 => {-as => 'e64'}, decode_base64 => {-as => 'd64'}; # Import most functions with the "trig_" prefix, e.g. "trig_log", # "trig_sin", "trig_cos", etc. use Sub::Import 'Math::Trig', -all => {-prefix => 'trig_'}; # Import PI-related functions with the "_the_great" suffix, e.g. # "pi_the_great", "pi2_the_great", etc. use Sub::Import 'Math::Trig', -pi => {-suffix => '_the_great'};
Sub::Import is the companion to Sub::Exporter. You can use Sub::Import to get Sub::Exporter-like import semantics, even if the library you're importing from used Exporter.pm.
The synopsis above should say it all. Where you would usually say:
use Some::Library qw(foo bar baz);
...to get Exporter.pm semantics, you can now get Sub::Exporter semantics with:
use Sub::Import 'Some::Library' => qw(foo bar baz);
This library should run on perls released even a long time ago. It should work on any version of perl released in the last five years.
Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl.
While you can rename imports, there is no way to customize them, because they are not being built by generators. At present, extra arguments for each import will be thrown away. In the future, they may become a fatal error.
Non-subroutine imports will not be importable via this mechanism.
The regex-like import features of Exporter.pm will be unavailable. (Will anyone miss them?)
Ricardo Signes <cpan@semiotic.systems>
Ricardo Signes <rjbs@semiotic.systems>
This software is copyright (c) 2022 by Ricardo Signes.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Sub::Import, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sub::Import
CPAN shell
perl -MCPAN -e shell install Sub::Import
For more information on module installation, please visit the detailed CPAN module installation guide.