1Sub::Exporter::Util(3)User Contributed Perl DocumentationSub::Exporter::Util(3)
2
3
4

NAME

6       Sub::Exporter::Util - utilities to make Sub::Exporter easier
7

VERSION

9       version 0.989
10

DESCRIPTION

12       This module provides a number of utility functions for performing
13       common or useful operations when setting up a Sub::Exporter
14       configuration.  All of the utilities may be exported, but none are by
15       default.
16

PERL VERSION

18       This library should run on perls released even a long time ago.  It
19       should work on any version of perl released in the last five years.
20
21       Although it may work on older versions of perl, no guarantee is made
22       that the minimum required version will not be increased.  The version
23       may be increased for any reason, and there is no promise that patches
24       will be accepted to lower the minimum required perl.
25

THE UTILITIES

27   curry_method
28         exports => {
29           some_method => curry_method,
30         }
31
32       This utility returns a generator which will produce an invocant-curried
33       version of a method.  In other words, it will export a method call with
34       the exporting class built in as the invocant.
35
36       A module importing the code some the above example might do this:
37
38         use Some::Module qw(some_method);
39
40         my $x = some_method;
41
42       This would be equivalent to:
43
44         use Some::Module;
45
46         my $x = Some::Module->some_method;
47
48       If Some::Module is subclassed and the subclass's import method is
49       called to import "some_method", the subclass will be curried in as the
50       invocant.
51
52       If an argument is provided for "curry_method" it is used as the name of
53       the curried method to export.  This means you could export a Widget
54       constructor like this:
55
56         exports => { widget => curry_method('new') }
57
58       This utility may also be called as "curry_class", for backwards
59       compatibility.
60
61   curry_chain
62       "curry_chain" behaves like "curry_method", but is meant for generating
63       exports that will call several methods in succession.
64
65         exports => {
66           reticulate => curry_chain(
67             new => gather_data => analyze => [ detail => 100 ] => 'results'
68           ),
69         }
70
71       If imported from Spliner, calling the "reticulate" routine will be
72       equivalent to:
73
74         Spliner->new->gather_data->analyze(detail => 100)->results;
75
76       If any method returns something on which methods may not be called, the
77       routine croaks.
78
79       The arguments to "curry_chain" form an optlist.  The names are methods
80       to be called and the arguments, if given, are arrayrefs to be
81       dereferenced and passed as arguments to those methods.  "curry_chain"
82       returns a generator like those expected by Sub::Exporter.
83
84       Achtung! at present, there is no way to pass arguments from the
85       generated routine to the method calls.  This will probably be solved in
86       future revisions by allowing the opt list's values to be subroutines
87       that will be called with the generated routine's stack.
88
89   merge_col
90         exports => {
91           merge_col(defaults => {
92             twiddle => \'_twiddle_gen',
93             tweak   => \&_tweak_gen,
94           }),
95         }
96
97       This utility wraps the given generator in one that will merge the named
98       collection into its args before calling it.  This means that you can
99       support a "default" collector in multiple exports without writing the
100       code each time.
101
102       You can specify as many pairs of collection names and generators as you
103       like.
104
105   mixin_installer
106         use Sub::Exporter -setup => {
107           installer => Sub::Exporter::Util::mixin_installer,
108           exports   => [ qw(foo bar baz) ],
109         };
110
111       This utility returns an installer that will install into a superclass
112       and adjust the ISA importing class to include the newly generated
113       superclass.
114
115       If the target of importing is an object, the hierarchy is reversed: the
116       new class will be ISA the object's class, and the object will be
117       reblessed.
118
119       Prerequisites: This utility requires that Package::Generator be
120       installed.
121
122   like
123       It's a collector that adds imports for anything like given regex.
124
125       If you provide this configuration:
126
127         exports    => [ qw(igrep imap islurp exhausted) ],
128         collectors => { -like => Sub::Exporter::Util::like },
129
130       A user may import from your module like this:
131
132         use Your::Iterator -like => qr/^i/; # imports igre, imap, islurp
133
134       or
135
136         use Your::Iterator -like => [ qr/^i/ => { -prefix => 'your_' } ];
137
138       The group-like prefix and suffix arguments are respected; other
139       arguments are passed on to the generators for matching exports.
140

AUTHOR

142       Ricardo Signes <cpan@semiotic.systems>
143
145       This software is copyright (c) 2007 by Ricardo Signes.
146
147       This is free software; you can redistribute it and/or modify it under
148       the same terms as the Perl 5 programming language system itself.
149
150
151
152perl v5.36.0                      2023-01-20            Sub::Exporter::Util(3)
Impressum