|
NAMENo::Worries::Export - symbol exporting without worriesSYNOPSISuse No::Worries::Export qw(export_control); sub foo () { ... } our $bar = 42; sub import : method { my($pkg, %exported); $pkg = shift(@_); grep($exported{$_}++, qw(foo $bar)); export_control(scalar(caller()), $pkg, \%exported, @_); } DESCRIPTIONThis module eases symbol exporting by providing a simple yet powerful alternative to the Exporter module.The symbols that can be imported are defined in a hash (the third argument of export_control()), the key being the symbol name and the value being:
The normal symbols can be functions (such as "foo"), scalars (<$foo>), arrays (<@foo>) or hashes (<%foo>). All the normal symbols can be imported at once by using an asterisk in the import code: use Foo qw(*); Alternatively, a regular expression can be given to filter what to import: # import "foo" and all the normal symbols starting with "bar" use Foo qw(foo /^bar/); The special symbols can be used to execute any code. For instance: # exporting module our $backend = "stdout"; sub import : method { my($pkg, %exported); $pkg = shift(@_); $exported{syslog} = sub { $backend = "syslog" }; export_control(scalar(caller()), $pkg, \%exported, @_); } # importing code use Foo qw(syslog); Finally, anything looking like a number will trigger a version check: use Foo qw(1.2); # will trigger Foo->VERSION(1.2); See UNIVERSAL for more information on the VERSION() mthod. FUNCTIONSThis module provides the following function (not exported by default):
SEE ALSOExporter, No::Worries.AUTHORLionel Cons <http://cern.ch/lionel.cons>Copyright (C) CERN 2012-2019
Visit the GSP FreeBSD Man Page Interface. |