line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::ListMoreUtils; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
112475
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
119
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
95
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
14
|
no strict 'refs'; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
86
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
14
|
use vars qw($VERSION @ISA); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
179
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
2788
|
use List::MoreUtils; |
|
3
|
|
|
|
|
4010
|
|
|
3
|
|
|
|
|
173
|
|
11
|
3
|
|
|
3
|
|
3242
|
use Template::Plugin::Procedural; |
|
3
|
|
|
|
|
11743
|
|
|
3
|
|
|
|
|
109
|
|
12
|
3
|
|
|
3
|
|
24
|
use vars qw(@ISA $VERSION); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
3997
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION = '0.02'; |
15
|
|
|
|
|
|
|
@ISA = qw(Template::Plugin::Procedural); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Template::Plugin::ListMoreUtils - TT2 plugin to use List::MoreUtils |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
[% my1to9even = [ 2, 4, 6, 8 ]; |
24
|
|
|
|
|
|
|
my1to9prim = [ 2, 3, 5, 7 ]; |
25
|
|
|
|
|
|
|
my1to9odd = [ 1, 3, 5, 7, 9 ]; %] |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
[% USE ListMoreUtils %] |
28
|
|
|
|
|
|
|
[% my1to9all = ListMoreUtils.uniq( my1to9even.merge( my1to9prim, my1to9odd ) ); %] |
29
|
|
|
|
|
|
|
1 .. 9 are [% my1to9all.size() %] |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This module provides an Template::Toolkit interface to Tassilo von Parseval's |
34
|
|
|
|
|
|
|
L. It extends the built-in functions dealing with lists as |
35
|
|
|
|
|
|
|
well as L. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 USAGE |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
To use this module from templates, you can choose between class interface |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
[% my1to9even = [ 2, 4, 6, 8 ]; |
42
|
|
|
|
|
|
|
my1to9prim = [ 2, 3, 5, 7 ]; |
43
|
|
|
|
|
|
|
my1to9odd = [ 1, 3, 5, 7, 9 ]; %] |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
[% USE ListMoreUtils %] |
46
|
|
|
|
|
|
|
[% my1to9all = ListMoreUtils.uniq( my1to9even.merge( my1to9prim, my1to9odd ) ); %] |
47
|
|
|
|
|
|
|
1 .. 9 are [% my1to9all.size() %] |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
or the virtual method interface, which is described in |
50
|
|
|
|
|
|
|
L. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 FUNCTIONS PROVIDED |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
All functions behave as documented in L. I don't plan to |
55
|
|
|
|
|
|
|
copy the entire POD from there. |
56
|
|
|
|
|
|
|
L provides lists as list reference, so they were expanded |
57
|
|
|
|
|
|
|
before the appropriate function in C is called. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 any BLOCK LIST |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
2
|
|
|
2
|
1
|
39103
|
sub any(&\@) { List::MoreUtils::any( \&{ $_[0] }, @{ $_[1] } ); } |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
27
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 all BLOCK LIST |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
2
|
1
|
26849
|
sub all(&\@) { List::MoreUtils::all( \&{ $_[0] }, @{ $_[1] } ); } |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
23
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 none BLOCK LIST |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
2
|
1
|
32990
|
sub none(&\@) { List::MoreUtils::none( \&{ $_[0] }, @{ $_[1] } ); } |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
47
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 notall BLOCK LIST |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
2
|
|
|
2
|
1
|
22718
|
sub notall(&\@) { List::MoreUtils::notall( \&{ $_[0] }, @{ $_[1] } ); } |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
15
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 true BLOCK LIST |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
3
|
|
|
3
|
1
|
36131
|
sub true(&\@) { List::MoreUtils::true( \&{ $_[0] }, @{ $_[1] } ); } |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
34
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 false BLOCK LIST |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
3
|
|
|
3
|
1
|
32403
|
sub false(&\@) { List::MoreUtils::false( \&{ $_[0] }, @{ $_[1] } ); } |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
21
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 firstidx BLOCK LIST |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 first_index BLOCK LIST |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
3
|
|
|
3
|
1
|
37583
|
sub firstidx(&\@) { List::MoreUtils::firstidx( \&{ $_[0] }, @{ $_[1] } ); } |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
19
|
|
102
|
|
|
|
|
|
|
*first_index = *{'firstidx'}{CODE}; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 lastidx BLOCK LIST |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 last_index BLOCK LIST |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
3
|
|
|
3
|
1
|
31842
|
sub lastidx(&\@) { List::MoreUtils::lastidx( \&{ $_[0] }, @{ $_[1] } ); } |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
17
|
|
111
|
|
|
|
|
|
|
*last_index = *{'lastidx'}{CODE}; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 insert_after BLOCK VALUE LIST |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
*insert_after = *{'List::MoreUtils::insert_after'}{CODE} if ( defined( *{'List::MoreUtils::insert_after'}{CODE} ) ); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 insert_after_string STRING VALUE LIST |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
*insert_after_string = *{'List::MoreUtils::insert_after_string'}{CODE} |
124
|
|
|
|
|
|
|
if ( defined( *{'List::MoreUtils::insert_after_string'}{CODE} ) ); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 apply BLOCK LIST |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
1
|
|
|
1
|
1
|
34354
|
sub apply(&\@) { List::MoreUtils::apply( \&{ $_[0] }, @{ $_[1] } ); } |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
22
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 after BLOCK LIST |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
1
|
|
|
1
|
1
|
13216
|
sub after(&\@) { List::MoreUtils::after( \&{ $_[0] }, @{ $_[1] } ); } |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
22
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 after_incl BLOCK LIST |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
1
|
|
|
1
|
1
|
11845
|
sub after_incl(&\@) { List::MoreUtils::after_incl( \&{ $_[0] }, @{ $_[1] } ); } |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
9
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 before BLOCK LIST |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
147
|
|
|
|
|
|
|
|
148
|
1
|
|
|
1
|
1
|
17945
|
sub before(&\@) { List::MoreUtils::before( \&{ $_[0] }, @{ $_[1] } ); } |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
6
|
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 before_incl BLOCK LIST |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |
153
|
|
|
|
|
|
|
|
154
|
1
|
|
|
1
|
1
|
11272
|
sub before_incl(&\@) { List::MoreUtils::before_incl( \&{ $_[0] }, @{ $_[1] } ); } |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 indexes BLOCK LIST |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |
159
|
|
|
|
|
|
|
|
160
|
1
|
|
|
1
|
1
|
12161
|
sub indexes(&\@) { List::MoreUtils::indexes( \&{ $_[0] }, @{ $_[1] } ); } |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
8
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 firstval BLOCK LIST |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 first_value BLOCK LIST |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=cut |
167
|
|
|
|
|
|
|
|
168
|
3
|
|
|
3
|
1
|
36206
|
sub firstval(&\@) { List::MoreUtils::firstval( \&{ $_[0] }, @{ $_[1] } ); } |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
27
|
|
169
|
|
|
|
|
|
|
*first_value = *{'firstval'}{CODE}; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 lastval BLOCK LIST |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 last_value BLOCK LIST |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
176
|
|
|
|
|
|
|
|
177
|
3
|
|
|
3
|
1
|
34008
|
sub lastval(&\@) { List::MoreUtils::lastval( \&{ $_[0] }, @{ $_[1] } ); } |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
18
|
|
178
|
|
|
|
|
|
|
*last_value = *{'lastval'}{CODE}; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 pairwise BLOCK LIST LIST |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Unlike the original C, both variables are given through C<@_>. |
183
|
|
|
|
|
|
|
Template::Toolkit uses eval to evaluate the perl code declared there and |
184
|
|
|
|
|
|
|
passes neither C<$a> nor C<$b> (which sounds reasonable to me). |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=cut |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub pairwise(&\@\@) |
189
|
|
|
|
|
|
|
{ |
190
|
2
|
|
|
2
|
1
|
22576
|
my $userfn = $_[0]; |
191
|
2
|
|
|
8
|
|
12
|
List::MoreUtils::pairwise( sub { &{$userfn}( $a, $b ); }, @{ $_[1] }, @{ $_[2] } ); |
|
8
|
|
|
|
|
274
|
|
|
8
|
|
|
|
|
20
|
|
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
20
|
|
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 minmax LIST |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |
197
|
|
|
|
|
|
|
|
198
|
4
|
|
|
4
|
1
|
60862
|
sub minmax(\@) { List::MoreUtils::minmax( @{ $_[0] } ); } |
|
4
|
|
|
|
|
62
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head2 uniq LIST |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |
203
|
|
|
|
|
|
|
|
204
|
4
|
|
|
4
|
1
|
29696
|
sub uniq(\@) { List::MoreUtils::uniq( @{ $_[0] } ); } |
|
4
|
|
|
|
|
124
|
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head2 mesh |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head2 zip |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=cut |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
*mesh = *{'List::MoreUtils::mesh'}{CODE} if ( defined( *{'List::MoreUtils::mesh'}{CODE} ) ); |
213
|
|
|
|
|
|
|
*zip = *{'List::MoreUtils::zip'}{CODE} if ( defined( *{'List::MoreUtils::zip'}{CODE} ) ); |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head2 part BLOCK LIST |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=cut |
218
|
|
|
|
|
|
|
|
219
|
1
|
|
|
1
|
1
|
15140
|
sub part(&\@) { List::MoreUtils::part( \&{ $_[0] }, @{ $_[1] } ) } |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
8
|
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head2 bsearch BLOCK LIST |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
This function is available only when List::MoreUtils 0.23 or newer is used. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Unlike the original C, the value to compare with is passed in |
226
|
|
|
|
|
|
|
C<$_[0]>. Template::Toolkit uses eval to evaluate the perl code declared |
227
|
|
|
|
|
|
|
there and don't pass C<$_> (which sounds reasonable to me). |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=cut |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
if ( defined( *{'List::MoreUtils::bsearch'}{CODE} ) ) |
232
|
|
|
|
|
|
|
{ |
233
|
|
|
|
|
|
|
eval <<'EOBS'; |
234
|
|
|
|
|
|
|
sub bsearch(&\@) |
235
|
|
|
|
|
|
|
{ |
236
|
|
|
|
|
|
|
my $userfn = $_[0]; |
237
|
|
|
|
|
|
|
List::MoreUtils::bsearch( sub { &{$userfn}( $_ ); }, @{$_[1]} ); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
EOBS |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 INSTALL |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
To install this module, use |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
perl Build.PL |
247
|
|
|
|
|
|
|
./Build |
248
|
|
|
|
|
|
|
./Build test |
249
|
|
|
|
|
|
|
./Build install |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head1 LIMITATION |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
Except the typical limitations known from perl functions embedded in |
254
|
|
|
|
|
|
|
L, the only limitation I currently miss is being |
255
|
|
|
|
|
|
|
able to use TT2 defined macros as callback. |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head1 SUPPORT |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
Free support can be requested via regular CPAN bug-tracking system. There is |
260
|
|
|
|
|
|
|
no guaranteed reaction time or solution time. It depends on business load. |
261
|
|
|
|
|
|
|
That doesn't mean that ticket via rt aren't handles as soon as possible, that |
262
|
|
|
|
|
|
|
means that soon depends on how much I have to do. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
Business and commercial support should be aquired via preferred freelancer |
265
|
|
|
|
|
|
|
agencies. |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=head1 AUTHOR |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
Jens Rehsack |
270
|
|
|
|
|
|
|
CPAN ID: REHSACK |
271
|
|
|
|
|
|
|
rehsack@cpan.org |
272
|
|
|
|
|
|
|
http://search.cpan.org/~rehsack/ |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=head1 COPYRIGHT |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
This program is free software; you can redistribute |
277
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
The full text of the license can be found in the |
280
|
|
|
|
|
|
|
LICENSE file included with this module. |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=head1 SEE ALSO |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
perl(1), L, |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=cut |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
1; |