1Sub::Exporter::GlobExpoUrsteerr(C3o)ntributed Perl DocumSeunbt:a:tEixopnorter::GlobExporter(3)
2
3
4
6 Sub::Exporter::GlobExporter - export shared globs with Sub::Exporter
7 collectors
8
10 version 0.006
11
13 First, you write something that exports globs:
14
15 package Shared::Symbol;
16
17 use Sub::Exporter;
18 use Sub::Exporter::GlobExport qw(glob_exporter);
19
20 use Sub::Exporter -setup => {
21 ...
22 collectors => { '$Symbol' => glob_exporter(Symbol => \'_shared_globref') },
23 };
24
25 sub _shared_globref { return \*Common }
26
27 Now other code can import $Symbol and get their *Symbol made an alias
28 to *Shared::Symbol::Common.
29
30 If you don't know what this means or why you'd want to do it, you may
31 want to stop reading now.
32
33 The other class can do something like this:
34
35 use Shared::Symbol '$Symbol';
36
37 print $Symbol; # prints the scalar entry of *Shared::Symbol::Common
38
39 ...or...
40
41 use Shared::Symbol '$Symbol' => { -as => 'SharedSymbol' };
42
43 print $SharedSymbol; # prints the scalar entry of *Shared::Symbol::Common
44
45 ...or...
46
47 my $glob;
48 use Shared::Symbol '$Symbol' => { -as => \$glob };
49
50 print $$glob; # prints the scalar entry of *Shared::Symbol::Common
51
53 Sub::Exporter::GlobExporter provides only one routine, "glob_exporter",
54 which may be called either by its full name or may be imported on
55 request.
56
57 my $exporter = glob_exporter( $default_name, $globref_locator );
58
59 The routine returns a collection validator that will export a glob into
60 the importing package. It will export it under the name $default_name,
61 unless an alternate name is given (as shown above). The glob that is
62 installed is specified by the $globref_locator, which can be either the
63 globref itself, or a reference to a string which will be called on the
64 exporter
65
66 For an example, see the "SYNOPSIS", in which a method is defined to
67 produce the globref to share. This allows the glob-exporting package
68 to be subclassed, so the subclass may choose to either re-use the same
69 glob when exporting or to export a new one.
70
71 If there are entries in the arguments to the globref-exporting
72 collector other than those beginning with a dash, a hashref of them
73 will be passed to the globref locator. In other words, if we were to
74 write this:
75
76 use Shared::Symbol '$Symbol' => { arg => 1, -as => 2 };
77
78 It would result in a call like the following:
79
80 my $globref = Shared::Symbol->_shared_globref({ arg => 1 });
81
83 This library should run on perls released even a long time ago. It
84 should work on any version of perl released in the last five years.
85
86 Although it may work on older versions of perl, no guarantee is made
87 that the minimum required version will not be increased. The version
88 may be increased for any reason, and there is no promise that patches
89 will be accepted to lower the minimum required perl.
90
92 Ricardo Signes <cpan@semiotic.systems>
93
95 • David Steinbrunner <dsteinbrunner@pobox.com>
96
97 • Ricardo Signes <rjbs@semiotic.systems>
98
100 This software is copyright (c) 2010 by Ricardo Signes.
101
102 This is free software; you can redistribute it and/or modify it under
103 the same terms as the Perl 5 programming language system itself.
104
105
106
107perl v5.36.0 2023-01-20 Sub::Exporter::GlobExporter(3)