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.987
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

THE UTILITIES

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

AUTHOR

133       Ricardo Signes <rjbs@cpan.org>
134
136       This software is copyright (c) 2007 by Ricardo Signes.
137
138       This is free software; you can redistribute it and/or modify it under
139       the same terms as the Perl 5 programming language system itself.
140
141
142
143perl v5.30.1                      2020-01-30            Sub::Exporter::Util(3)
Impressum