1Exporter::Lite(3) User Contributed Perl Documentation Exporter::Lite(3)
2
3
4
6 Exporter::Lite - Lightweight exporting of variables
7
9 package Foo;
10 use Exporter::Lite;
11
12 # Just like Exporter.
13 @EXPORT = qw($This That);
14 @EXPORT_OK = qw(@Left %Right);
15
16 # Meanwhile, in another piece of code!
17 package Bar;
18 use Foo; # exports $This and &That.
19
21 This is an alternative to Exporter intended to provide a lightweight
22 subset of its functionality. It supports "import()", @EXPORT and
23 @EXPORT_OK and not a whole lot else.
24
25 Unlike Exporter, it is not necessary to inherit from Exporter::Lite
26 (ie. no "@ISA = qw(Exporter::Lite)" mantra). Exporter::Lite simply
27 exports its import() function. This might be called a "mix-in".
28
29 Setting up a module to export its variables and functions is simple:
30
31 package My::Module;
32 use Exporter::Lite;
33
34 @EXPORT = qw($Foo bar);
35
36 now when you "use My::Module", $Foo and "bar()" will show up.
37
38 In order to make exporting optional, use @EXPORT_OK.
39
40 package My::Module;
41 use Exporter::Lite;
42
43 @EXPORT_OK = qw($Foo bar);
44
45 when My::Module is used, $Foo and "bar()" will not show up. You have
46 to ask for them. "use My::Module qw($Foo bar)".
47
49 Export::Lite has one public method, import(), which is called automatā
50 icly when your modules is use()'d.
51
52 In normal usage you don't have to worry about this at all.
53
54 import
55 Some::Module->import;
56 Some::Module->import(@symbols);
57
58 Works just like "Exporter::import()" excepting it only honors
59 @Some::Module::EXPORT and @Some::Module::EXPORT_OK.
60
61 The given @symbols are exported to the current package provided
62 they are in @Some::Module::EXPORT or @Some::Module::EXPORT_OK.
63 Otherwise an exception is thrown (ie. the program dies).
64
65 If @symbols is not given, everything in @Some::Module::EXPORT is
66 exported.
67
69 '"%s" is not exported by the %s module'
70 Attempted to import a symbol which is not in @EXPORT or @EXPORT_OK.
71
72 'Can\'t export symbol: %s'
73 Attempted to import a symbol of an unknown type (ie. the leading
74 $@% salad wasn't recognized).
75
77 Its not yet clear if this is actually any lighter or faster than
78 Exporter. I know its at least on par.
79
80 OTOH, the docs are much clearer and not having to say "@ISA =
81 qw(Exporter)" is kinda nice.
82
84 Michael G Schwern <schwern@pobox.com>
85
87 This program is free software; you can redistribute it and/or modify it
88 under the same terms as Perl itself.
89
90 See http://www.perl.com/perl/misc/Artistic.html
91
93 Exporter, Exporter::Simple, UNIVERSAL::exports
94
95
96
97perl v5.8.8 2006-11-11 Exporter::Lite(3)