line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::ListMoreUtilsVMethods; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
51692
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
75
|
|
4
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
63
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
8
|
use vars qw($VERSION @ISA $VMETHOD_PACKAGE @LIST_OPS); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
129
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
944
|
use Template::Plugin::VMethods; |
|
2
|
|
|
|
|
15614
|
|
|
2
|
|
|
|
|
13
|
|
9
|
|
|
|
|
|
|
$VERSION = '0.03'; |
10
|
|
|
|
|
|
|
@ISA = qw(Template::Plugin::VMethods); |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
515
|
use Template::Plugin::ListMoreUtils; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
483
|
|
13
|
|
|
|
|
|
|
$VMETHOD_PACKAGE = 'Template::Plugin::ListMoreUtils'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
@LIST_OPS = ( |
16
|
|
|
|
|
|
|
qw(mesh zip uniq minmax singleton), |
17
|
|
|
|
|
|
|
any => \&any, |
18
|
|
|
|
|
|
|
all => \&all, |
19
|
|
|
|
|
|
|
none => \&none, |
20
|
|
|
|
|
|
|
notall => \¬all, |
21
|
|
|
|
|
|
|
true => \&true, |
22
|
|
|
|
|
|
|
false => \&false, |
23
|
|
|
|
|
|
|
firstidx => \&firstidx, |
24
|
|
|
|
|
|
|
first_index => \&first_index, |
25
|
|
|
|
|
|
|
lastidx => \&lastidx, |
26
|
|
|
|
|
|
|
last_index => \&last_index, |
27
|
|
|
|
|
|
|
onlyidx => \&onlyidx, |
28
|
|
|
|
|
|
|
only_index => \&only_index, |
29
|
|
|
|
|
|
|
firstval => \&firstval, |
30
|
|
|
|
|
|
|
first_value => \&first_value, |
31
|
|
|
|
|
|
|
lastval => \&lastval, |
32
|
|
|
|
|
|
|
last_value => \&last_value, |
33
|
|
|
|
|
|
|
onlyval => \&onlyval, |
34
|
|
|
|
|
|
|
only_value => \&only_value, |
35
|
|
|
|
|
|
|
firstval => \&firstval, |
36
|
|
|
|
|
|
|
first_result => \&first_result, |
37
|
|
|
|
|
|
|
lastval => \&lastval, |
38
|
|
|
|
|
|
|
last_result => \&last_result, |
39
|
|
|
|
|
|
|
onlyval => \&onlyval, |
40
|
|
|
|
|
|
|
only_result => \&only_result, |
41
|
|
|
|
|
|
|
insert_after => \&insert_after, |
42
|
|
|
|
|
|
|
insert_after_string => \&insert_after_string, |
43
|
|
|
|
|
|
|
apply => \&apply, |
44
|
|
|
|
|
|
|
after => \&after, |
45
|
|
|
|
|
|
|
after_incl => \&after_incl, |
46
|
|
|
|
|
|
|
before => \&before, |
47
|
|
|
|
|
|
|
before_incl => \&before_incl, |
48
|
|
|
|
|
|
|
indexes => \&indexes, |
49
|
|
|
|
|
|
|
pairwise => \&pairwise, |
50
|
|
|
|
|
|
|
part => \&part, |
51
|
|
|
|
|
|
|
bsearch => \&bsearch, |
52
|
|
|
|
|
|
|
bsearchidx => \&bsearchidx, |
53
|
|
|
|
|
|
|
bsearch_index => \&bsearch_index, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 NAME |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Template::Plugin::ListMoreUtilsVMethods - TT2 plugin to use List::MoreUtils as virtual methods of lists |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 SYNOPSIS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
[% my1to9even = [ 2, 4, 6, 8 ]; |
63
|
|
|
|
|
|
|
my1to9prim = [ 2, 3, 5, 7 ]; |
64
|
|
|
|
|
|
|
my1to9odd = [ 1, 3, 5, 7, 9 ]; %] |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
[% USE ListMoreUtilsVMethods %] |
67
|
|
|
|
|
|
|
[% my1and9 = my1to9all.minmax; %] |
68
|
|
|
|
|
|
|
[% my1and9[0] %] is the smalled number of 1 .. 9, the largest is [% my1and9[1] %] |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 DESCRIPTION |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This module provides an Template::Toolkit interface to Tassilo von Parseval's |
73
|
|
|
|
|
|
|
L. It extends the built-in functions dealing with lists as |
74
|
|
|
|
|
|
|
well as L. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 USAGE |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
To use this module from templates, you can choose between class interface |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
[% my1to9even = [ 2, 4, 6, 8 ]; |
81
|
|
|
|
|
|
|
my1to9prim = [ 2, 3, 5, 7 ]; |
82
|
|
|
|
|
|
|
my1to9odd = [ 1, 3, 5, 7, 9 ]; %] |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
[% USE ListMoreUtilsVMethods %] |
85
|
|
|
|
|
|
|
[% my1and9 = my1to9all.minmax; %] |
86
|
|
|
|
|
|
|
[% my1and9[0] %] is the smalled number of 1 .. 9, the largest is [% my1and9[1] %] |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 FUNCTIONS PROVIDED |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
The functions/methods provided are the same as in |
91
|
|
|
|
|
|
|
L, regardless the preferred interface. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
2
|
|
|
2
|
|
11
|
no strict 'refs'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2075
|
|
96
|
|
|
|
|
|
|
|
97
|
2
|
|
|
2
|
0
|
29020
|
sub any(\@&) { List::MoreUtils::any( \&{ $_[1] }, @{ $_[0] } ); } |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
20
|
|
98
|
|
|
|
|
|
|
|
99
|
2
|
|
|
2
|
0
|
19911
|
sub all(\@&) { List::MoreUtils::all( \&{ $_[1] }, @{ $_[0] } ); } |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
24
|
|
100
|
|
|
|
|
|
|
|
101
|
2
|
|
|
2
|
0
|
21121
|
sub none(\@&) { List::MoreUtils::none( \&{ $_[1] }, @{ $_[0] } ); } |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
18
|
|
102
|
|
|
|
|
|
|
|
103
|
2
|
|
|
2
|
0
|
20554
|
sub notall(\@&) { List::MoreUtils::notall( \&{ $_[1] }, @{ $_[0] } ); } |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
14
|
|
104
|
|
|
|
|
|
|
|
105
|
3
|
|
|
3
|
0
|
30164
|
sub true(\@&) { List::MoreUtils::true( \&{ $_[1] }, @{ $_[0] } ); } |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
29
|
|
106
|
|
|
|
|
|
|
|
107
|
3
|
|
|
3
|
0
|
29867
|
sub false(\@&) { List::MoreUtils::false( \&{ $_[1] }, @{ $_[0] } ); } |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
30
|
|
108
|
|
|
|
|
|
|
|
109
|
3
|
|
|
3
|
0
|
30207
|
sub firstidx(\@&) { List::MoreUtils::firstidx( \&{ $_[1] }, @{ $_[0] } ); } |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
27
|
|
110
|
|
|
|
|
|
|
sub first_index(\@&); |
111
|
|
|
|
|
|
|
*first_index = *{'firstidx'}{CODE}; |
112
|
|
|
|
|
|
|
|
113
|
3
|
|
|
3
|
0
|
31065
|
sub lastidx(\@&) { List::MoreUtils::lastidx( \&{ $_[1] }, @{ $_[0] } ); } |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
18
|
|
114
|
|
|
|
|
|
|
sub last_index(\@&); |
115
|
|
|
|
|
|
|
*last_index = *{'lastidx'}{CODE}; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
0
|
0
|
0
|
sub onlyidx(\@&) { List::MoreUtils::onlyidx( \&{ $_[1] }, @{ $_[0] } ); } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
118
|
|
|
|
|
|
|
sub only_index(\@&); |
119
|
|
|
|
|
|
|
*only_index = *{'onlyidx'}{CODE}; |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
0
|
0
|
0
|
sub firstres(\@&) { List::MoreUtils::firstres( \&{ $_[1] }, @{ $_[0] } ); } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
122
|
|
|
|
|
|
|
sub first_result(\@&); |
123
|
|
|
|
|
|
|
*first_result = *{'firstres'}{CODE}; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
0
|
0
|
0
|
sub lastres(\@&) { List::MoreUtils::lastres( \&{ $_[1] }, @{ $_[0] } ); } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
126
|
|
|
|
|
|
|
sub last_result(\@&); |
127
|
|
|
|
|
|
|
*last_result = *{'lastres'}{CODE}; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
0
|
0
|
0
|
sub onlyres(\@&) { List::MoreUtils::onlyres( \&{ $_[1] }, @{ $_[0] } ); } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
130
|
|
|
|
|
|
|
sub only_result(\@&); |
131
|
|
|
|
|
|
|
*only_result = *{'onlyres'}{CODE}; |
132
|
|
|
|
|
|
|
|
133
|
3
|
|
|
3
|
0
|
30412
|
sub firstval(\@&) { List::MoreUtils::firstval( \&{ $_[1] }, @{ $_[0] } ); } |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
17
|
|
134
|
|
|
|
|
|
|
sub first_value(\@&); |
135
|
|
|
|
|
|
|
*first_value = *{'firstval'}{CODE}; |
136
|
|
|
|
|
|
|
|
137
|
3
|
|
|
3
|
0
|
29782
|
sub lastval(\@&) { List::MoreUtils::lastval( \&{ $_[1] }, @{ $_[0] } ); } |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
25
|
|
138
|
|
|
|
|
|
|
sub last_value(\@&); |
139
|
|
|
|
|
|
|
*last_value = *{'lastval'}{CODE}; |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
0
|
0
|
0
|
sub onlyval(\@&) { List::MoreUtils::onlyval( \&{ $_[1] }, @{ $_[0] } ); } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
142
|
|
|
|
|
|
|
sub only_value(\@&); |
143
|
|
|
|
|
|
|
*only_value = *{'onlyval'}{CODE}; |
144
|
|
|
|
|
|
|
|
145
|
1
|
|
|
1
|
0
|
9802
|
sub insert_after (\@&$) { List::MoreUtils::insert_after( \&{ $_[1] }, $_[2], @{ $_[0] } ); } |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
7
|
|
146
|
1
|
|
|
1
|
0
|
10025
|
sub insert_after_string (\@$$) { List::MoreUtils::insert_after_string( $_[1], $_[2], @{ $_[0] } ); } |
|
1
|
|
|
|
|
10
|
|
147
|
|
|
|
|
|
|
|
148
|
1
|
|
|
1
|
0
|
10473
|
sub apply(\@&) { List::MoreUtils::apply( \&{ $_[1] }, @{ $_[0] } ); } |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
15
|
|
149
|
|
|
|
|
|
|
|
150
|
1
|
|
|
1
|
0
|
10595
|
sub after(\@&) { List::MoreUtils::after( \&{ $_[1] }, @{ $_[0] } ); } |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
10
|
|
151
|
|
|
|
|
|
|
|
152
|
1
|
|
|
1
|
0
|
10419
|
sub after_incl(\@&) { List::MoreUtils::after_incl( \&{ $_[1] }, @{ $_[0] } ); } |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
16
|
|
153
|
|
|
|
|
|
|
|
154
|
1
|
|
|
1
|
0
|
10796
|
sub before(\@&) { List::MoreUtils::before( \&{ $_[1] }, @{ $_[0] } ); } |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
15
|
|
155
|
|
|
|
|
|
|
|
156
|
1
|
|
|
1
|
0
|
10876
|
sub before_incl(\@&) { List::MoreUtils::before_incl( \&{ $_[1] }, @{ $_[0] } ); } |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
157
|
|
|
|
|
|
|
|
158
|
1
|
|
|
1
|
0
|
10541
|
sub indexes(\@&) { List::MoreUtils::indexes( \&{ $_[1] }, @{ $_[0] } ); } |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
15
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub pairwise(\@&\@) |
161
|
|
|
|
|
|
|
{ |
162
|
2
|
|
|
2
|
0
|
21028
|
my $userfn = $_[1]; |
163
|
2
|
|
|
8
|
|
10
|
List::MoreUtils::pairwise( sub { $userfn->( $a, $b ); }, @{ $_[0] }, @{ $_[2] } ); |
|
8
|
|
|
|
|
214
|
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
19
|
|
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
1
|
|
|
1
|
0
|
13006
|
sub part(\@&) { List::MoreUtils::part( \&{ $_[1] }, @{ $_[0] } ) } |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
7
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub bsearch(\@&) |
169
|
|
|
|
|
|
|
{ |
170
|
4
|
|
|
4
|
0
|
39981
|
my $userfn = $_[1]; |
171
|
4
|
|
|
8
|
|
16
|
List::MoreUtils::bsearch( sub { $userfn->($_) }, @{ $_[0] } ); |
|
8
|
|
|
|
|
283
|
|
|
4
|
|
|
|
|
29
|
|
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub bsearchidx(\@&) |
175
|
|
|
|
|
|
|
{ |
176
|
4
|
|
|
4
|
0
|
41189
|
my $userfn = $_[1]; |
177
|
4
|
|
|
8
|
|
20
|
List::MoreUtils::bsearchidx( sub { $userfn->($_) }, @{ $_[0] } ); |
|
8
|
|
|
|
|
188
|
|
|
4
|
|
|
|
|
26
|
|
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub bsearch_index(\@&) |
181
|
|
|
|
|
|
|
{ |
182
|
0
|
|
|
0
|
0
|
|
my $userfn = $_[1]; |
183
|
0
|
|
|
0
|
|
|
List::MoreUtils::bsearch_index( sub { $userfn->($_) }, @{ $_[0] } ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 LIMITATION |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Except the typical limitations known from perl functions embedded in |
189
|
|
|
|
|
|
|
L, the only limitation I currently miss is being |
190
|
|
|
|
|
|
|
able to use TT2 defined macros as callback. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 BUGS |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
195
|
|
|
|
|
|
|
C, or through the web interface at |
196
|
|
|
|
|
|
|
L. |
197
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress |
198
|
|
|
|
|
|
|
on your bug as I make changes. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head1 SUPPORT |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
perldoc Template::Plugin::ListMoreUtils |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
You can also look for information at: |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=over 4 |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
L |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
L |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item * CPAN Ratings |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
L |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=item * Search CPAN |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
L |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=back |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Business and commercial support should be acquired via preferred freelancer |
229
|
|
|
|
|
|
|
agencies. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Copyright 2009-2015 Jens Rehsack. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
236
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
237
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head1 SEE ALSO |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
perl(1), L, |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=cut |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
1; |