|
NAMEExporter::Easy - Takes the drudgery out of Exporting symbolsSYNOPSISIn module YourModule.pm:package YourModule; use Exporter::Easy ( OK => [ '$munge', 'frobnicate' ] # symbols to export on request ); In other files which wish to use YourModule: use ModuleName qw(frobnicate); # import listed symbols frobnicate ($left, $right) # calls YourModule::frobnicate DESCRIPTIONExporter::Easy makes using Exporter easy. In its simplest case, it allows you to drop the boilerplate code that comes with using Exporter, sorequire Exporter; use base qw( Exporter ); use vars qw( @EXPORT ); @EXPORT = ( 'init' ); becomes use Exporter::Easy ( EXPORT => [ 'init' ] ); and more complicated situations where you use tags to build lists and more tags become easy, like this use Exporter::Easy ( EXPORT => [qw( init :base )], TAGS => [ base => [qw( open close )], read => [qw( read sysread readline )], write => [qw( print write writeline )], misc => [qw( select flush )], all => [qw( :base :read :write :misc)], no_misc => [qw( :all !:misc )], ], OK => [qw( some other stuff )], ); This will set @EXPORT, @EXPORT_OK, @EXPORT_FAIL and %EXPORT_TAGS in the current package, add Exporter to that package's @ISA and do a "use vars" on all the variables mentioned. The rest is handled as normal by Exporter. HOW TO USE ITPutuse Exporter::Easy ( KEY => value, ...); in your package. Arguments are passes as key-value pairs, the following keys are available
PROCESSING ORDERWe need take the information provided and build @EXPORT, @EXPORT_OK, @EXPORT_FAIL and %EXPORT_TAGS in the calling package. We may also need to build a tag with all of the symbols and to make all the variables useable under strict.The arguments are processed in the following order: TAGS, EXPORT, OK, OK_ONLY and FAIL, ALL, VARS and finally ISA. This means you cannot use the tag created by ALL anywhere except in VARS (although vars defaults to using all symbols anyway). SEE ALSOExporter is the grandaddy of all Exporter modules, and bundled with Perl itself, unlike the rest of the modules listed here. Look at the documentation for this module to see more explanation of the OK, EXPORT and other variables.Attribute::Exporter defines attributes which you use to mark which subs and variables you want to export, and how. Exporter::Simple also uses attributes to control the export of functions and variables from your module. Const::Exporter makes it easy to create a module that exports constants. Constant::Exporter is another module that makes it easy to create modules that define and export constants. Sub::Exporter is a "sophisticated exporter for custom-built routines"; it lets you provide generators that can be used to customise what gets imported when someone uses your module. Exporter::Tiny provides the same features as Sub::Exporter, but relying only on core dependencies. Exporter::Shiny is a shortcut for Exporter::Tiny that provides a more concise notation for providing optional exports. Exporter::Declare provides syntactic sugar to make the export status of your functions part of their declaration. Kind of. AppConfig::Exporter lets you export part of an AppConfig-based configuration. Exporter::Lexical lets you export lexical subs from your module. Constant::Exporter::Lazy lets you write a module that exports function-style constants, which are instantiated lazily. Exporter::Auto will export everything from your module that it thinks is a public function (name doesn't start with an underscore). Class::Exporter lets you export class methods as regular subroutines. Xporter is like Exporter, but with persistent defaults and auto-ISA. REPOSITORY<https://github.com/neilb/Exporter-Easy>AUTHORWritten by Fergal Daly <fergal@esatclear.ie>.LICENSEUnder the same license as Perl itself
Visit the GSP FreeBSD Man Page Interface. |