1Sub::Exporter::Util(3)User Contributed Perl DocumentationSub::Exporter::Util(3)
2
3
4
6 Sub::Exporter::Util - utilities to make Sub::Exporter easier
7
9 version 0.975
10
11 $Id: /my/cs/projects/Sub-Exporter/trunk/lib/Sub/Exporter/Util.pm 31990 2007-07-06T02:33:04.864653Z rjbs $
12
14 This module provides a number of utility functions for performing com‐
15 mon or useful operations when setting up a Sub::Exporter configuration.
16 All of the utilites may be exported, but none are by default.
17
19 curry_method
20
21 exports => {
22 some_method => curry_method,
23 }
24
25 This utility returns a generator which will produce an invocant-curried
26 version of a method. In other words, it will export a method call with
27 the exporting class built in as the invocant.
28
29 A module importing the code some the above example might do this:
30
31 use Some::Module qw(some_method);
32
33 my $x = some_method;
34
35 This would be equivalent to:
36
37 use Some::Module;
38
39 my $x = Some::Module->some_method;
40
41 If Some::Module is subclassed and the subclass's import method is
42 called to import "some_method", the subclass will be curried in as the
43 invocant.
44
45 If an argument is provided for "curry_method" it is used as the name of
46 the curried method to export. This means you could export a Widget
47 constructor like this:
48
49 exports => { widget => curry_method('new') }
50
51 This utility may also be called as "curry_class", for backwards compat‐
52 ibility.
53
54 curry_chain
55
56 "curry_chain" behaves like ""curry_method"", but is meant for generat‐
57 ing exports that will call several methods in succession.
58
59 exports => {
60 reticulate => curry_chain([
61 new => gather_data => analyze => [ detail => 100 ] => results
62 ]),
63 }
64
65 If imported from Spliner, calling the "reticulate" routine will be
66 equivalent to:
67
68 Splinter->new->gather_data->analyze(detail => 100)->results;
69
70 If any method returns something on which methods may not be called, the
71 routine croaks.
72
73 The arguments to "curry_chain" form an optlist. The names are methods
74 to be called and the arguments, if given, are arrayrefs to be derefer‐
75 enced and passed as arguments to those methods. "curry_chain" returns
76 a generator like those expected by Sub::Exporter.
77
78 Achtung! at present, there is no way to pass arguments from the gener‐
79 ated routine to the method calls. This will probably be solved in
80 future revisions by allowing the opt list's values to be subroutines
81 that will be called with the generated routine's stack.
82
83 merge_col
84
85 exports => {
86 merge_col(defaults => {
87 twiddle => \&_twiddle_gen,
88 tweak => \&_tweak_gen,
89 }),
90 }
91
92 This utility wraps the given generator in one that will merge the named
93 collection into its args before calling it. This means that you can
94 support a "default" collector in multipe exports without writing the
95 code each time.
96
97 mixin_exporter
98
99 use Sub::Exporter -setup => {
100 exporter => Sub::Exporter::Util::mixin_exporter,
101 exports => [ qw(foo bar baz) ],
102 };
103
104 This utility returns an exporter that will export into a superclass and
105 adjust the ISA importing class to include the newly generated super‐
106 class.
107
108 If the target of importing is an object, the hierarchy is reversed: the
109 new class will be ISA the object's class, and the object will be reb‐
110 lessed.
111
112 Prerequisites: This utility requires that Package::Generator be
113 installed.
114
115 like
116
117 It's a collector that adds imports for anything like given regex.
118
119 If you provide this configuration:
120
121 exports => [ qw(igrep imap islurp exhausted) ],
122 collectors => { -like => Sub::Exporter::Util::like },
123
124 A user may import from your module like this:
125
126 use Your::Iterator -like => qr/^i/; # imports igre, imap, islurp
127
128 or
129
130 use Your::Iterator -like => [ qr/^i/ => { -prefix => 'your_' } ];
131
132 The group-like prefix and suffix arguments are respected; other argu‐
133 ments are passed on to the generators for matching exports.
134
136 Ricardo SIGNES, "<rjbs@cpan.org>"
137
139 Please report any bugs or feature requests through the web interface at
140 <http://rt.cpan.org>. I will be notified, and then you'll automatically
141 be notified of progress on your bug as I make changes.
142
144 Copyright 2006-2007, Ricardo SIGNES. This program is free software;
145 you can redistribute it and/or modify it under the same terms as Perl
146 itself.
147
148
149
150perl v5.8.8 2007-07-05 Sub::Exporter::Util(3)