1No::Worries::Export(3)User Contributed Perl DocumentationNo::Worries::Export(3)
2
3
4

NAME

6       No::Worries::Export - symbol exporting without worries
7

SYNOPSIS

9         use No::Worries::Export qw(export_control);
10
11         sub foo () { ... }
12
13         our $bar = 42;
14
15         sub import : method {
16             my($pkg, %exported);
17             $pkg = shift(@_);
18             grep($exported{$_}++, qw(foo $bar));
19             export_control(scalar(caller()), $pkg, \%exported, @_);
20         }
21

DESCRIPTION

23       This module eases symbol exporting by providing a simple yet powerful
24       alternative to the Exporter module.
25
26       The symbols that can be imported are defined in a hash (the third
27       argument of export_control()), the key being the symbol name and the
28       value being:
29
30       ·   a scalar: indicating a normal symbol
31
32       ·   a code reference: to be called at import time
33
34       The normal symbols can be functions (such as "foo"), scalars (<$foo>),
35       arrays (<@foo>) or hashes (<%foo>).
36
37       All the normal symbols can be imported at once by using an asterisk in
38       the import code:
39
40         use Foo qw(*);
41
42       Alternatively, a regular expression can be given to filter what to
43       import:
44
45         # import "foo" and all the normal symbols starting with "bar"
46         use Foo qw(foo /^bar/);
47
48       The special symbols can be used to execute any code. For instance:
49
50         # exporting module
51         our $backend = "stdout";
52         sub import : method {
53             my($pkg, %exported);
54             $pkg = shift(@_);
55             $exported{syslog} = sub { $backend = "syslog" };
56             export_control(scalar(caller()), $pkg, \%exported, @_);
57         }
58
59         # importing code
60         use Foo qw(syslog);
61
62       Finally, anything looking like a number will trigger a version check:
63
64         use Foo qw(1.2);
65         # will trigger
66         Foo->VERSION(1.2);
67
68       See UNIVERSAL for more information on the VERSION() mthod.
69

FUNCTIONS

71       This module provides the following function (not exported by default):
72
73       export_control(CALLERPKG, PKG, EXPORT, NAMES...)
74           control the symbols exported by the module; this should be called
75           from an "import" method
76

SEE ALSO

78       Exporter, No::Worries.
79

AUTHOR

81       Lionel Cons <http://cern.ch/lionel.cons>
82
83       Copyright (C) CERN 2012-2019
84
85
86
87perl v5.32.0                      2020-07-28            No::Worries::Export(3)
Impressum