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