line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::ListMoreUtilsVMethods; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
79768
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
113
|
|
4
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
66
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
48
|
use vars qw($VERSION @ISA $VMETHOD_PACKAGE @LIST_OPS); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
174
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1821
|
use Template::Plugin::VMethods; |
|
2
|
|
|
|
|
21950
|
|
|
2
|
|
|
|
|
16
|
|
9
|
|
|
|
|
|
|
$VERSION = '0.02'; |
10
|
|
|
|
|
|
|
@ISA = qw(Template::Plugin::VMethods); |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
764
|
use Template::Plugin::ListMoreUtils; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
489
|
|
13
|
|
|
|
|
|
|
$VMETHOD_PACKAGE = 'Template::Plugin::ListMoreUtils'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
@LIST_OPS = ( |
16
|
|
|
|
|
|
|
qw(mesh zip uniq minmax), |
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
|
|
|
|
|
|
|
insert_after => \&insert_after, |
28
|
|
|
|
|
|
|
insert_after_string => \&insert_after_string, |
29
|
|
|
|
|
|
|
apply => \&apply, |
30
|
|
|
|
|
|
|
after => \&after, |
31
|
|
|
|
|
|
|
after_incl => \&after_incl, |
32
|
|
|
|
|
|
|
before => \&before, |
33
|
|
|
|
|
|
|
before_incl => \&before_incl, |
34
|
|
|
|
|
|
|
indexes => \&indexes, |
35
|
|
|
|
|
|
|
firstval => \&firstval, |
36
|
|
|
|
|
|
|
first_value => \&first_value, |
37
|
|
|
|
|
|
|
lastval => \&lastval, |
38
|
|
|
|
|
|
|
last_value => \&last_value, |
39
|
|
|
|
|
|
|
pairwise => \&pairwise, |
40
|
|
|
|
|
|
|
part => \&part |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Template::Plugin::ListMoreUtilsVMethods - TT2 plugin to use List::MoreUtils as virtual methods of lists |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SYNOPSIS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
[% my1to9even = [ 2, 4, 6, 8 ]; |
50
|
|
|
|
|
|
|
my1to9prim = [ 2, 3, 5, 7 ]; |
51
|
|
|
|
|
|
|
my1to9odd = [ 1, 3, 5, 7, 9 ]; %] |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
[% USE ListMoreUtilsVMethods %] |
54
|
|
|
|
|
|
|
[% my1and9 = my1to9all.minmax; %] |
55
|
|
|
|
|
|
|
[% my1and9[0] %] is the smalled number of 1 .. 9, the largest is [% my1and9[1] %] |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 DESCRIPTION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
This module provides an Template::Toolkit interface to Tassilo von Parseval's |
60
|
|
|
|
|
|
|
L. It extends the built-in functions dealing with lists as |
61
|
|
|
|
|
|
|
well as L. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 USAGE |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
To use this module from templates, you can choose between class interface |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
[% my1to9even = [ 2, 4, 6, 8 ]; |
68
|
|
|
|
|
|
|
my1to9prim = [ 2, 3, 5, 7 ]; |
69
|
|
|
|
|
|
|
my1to9odd = [ 1, 3, 5, 7, 9 ]; %] |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
[% USE ListMoreUtilsVMethods %] |
72
|
|
|
|
|
|
|
[% my1and9 = my1to9all.minmax; %] |
73
|
|
|
|
|
|
|
[% my1and9[0] %] is the smalled number of 1 .. 9, the largest is [% my1and9[1] %] |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 FUNCTIONS PROVIDED |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
The functions/methods provided are the same as in |
78
|
|
|
|
|
|
|
L, regardless the preferred interface. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
2
|
|
|
2
|
|
12
|
no strict 'refs'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1882
|
|
83
|
|
|
|
|
|
|
|
84
|
2
|
|
|
2
|
0
|
41147
|
sub any(\@&) { List::MoreUtils::any( \&{ $_[1] }, @{ $_[0] } ); } |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
25
|
|
85
|
|
|
|
|
|
|
|
86
|
2
|
|
|
2
|
0
|
28244
|
sub all(\@&) { List::MoreUtils::all( \&{ $_[1] }, @{ $_[0] } ); } |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
19
|
|
87
|
|
|
|
|
|
|
|
88
|
2
|
|
|
2
|
0
|
41303
|
sub none(\@&) { List::MoreUtils::none( \&{ $_[1] }, @{ $_[0] } ); } |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
13
|
|
89
|
|
|
|
|
|
|
|
90
|
2
|
|
|
2
|
0
|
27329
|
sub notall(\@&) { List::MoreUtils::notall( \&{ $_[1] }, @{ $_[0] } ); } |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
15
|
|
91
|
|
|
|
|
|
|
|
92
|
3
|
|
|
3
|
0
|
35723
|
sub true(\@&) { List::MoreUtils::true( \&{ $_[1] }, @{ $_[0] } ); } |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
34
|
|
93
|
|
|
|
|
|
|
|
94
|
3
|
|
|
3
|
0
|
37242
|
sub false(\@&) { List::MoreUtils::false( \&{ $_[1] }, @{ $_[0] } ); } |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
21
|
|
95
|
|
|
|
|
|
|
|
96
|
3
|
|
|
3
|
0
|
43993
|
sub firstidx(\@&) { List::MoreUtils::firstidx( \&{ $_[1] }, @{ $_[0] } ); } |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
26
|
|
97
|
|
|
|
|
|
|
sub first_index(\@&); |
98
|
|
|
|
|
|
|
*first_index = *{'firstidx'}{CODE}; |
99
|
|
|
|
|
|
|
|
100
|
3
|
|
|
3
|
0
|
33606
|
sub lastidx(\@&) { List::MoreUtils::lastidx( \&{ $_[1] }, @{ $_[0] } ); } |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
17
|
|
101
|
|
|
|
|
|
|
sub last_index(\@&); |
102
|
|
|
|
|
|
|
*last_index = *{'lastidx'}{CODE}; |
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
1
|
0
|
13396
|
sub insert_after (\@&$) { List::MoreUtils::insert_after( \&{ $_[1] }, $_[2], @{ $_[0] } ); } |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
7
|
|
105
|
1
|
|
|
1
|
0
|
13453
|
sub insert_after_string (\@$$) { List::MoreUtils::insert_after_string( $_[1], $_[2], @{ $_[0] } ); } |
|
1
|
|
|
|
|
8
|
|
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
1
|
0
|
13074
|
sub apply(\@&) { List::MoreUtils::apply( \&{ $_[1] }, @{ $_[0] } ); } |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
18
|
|
108
|
|
|
|
|
|
|
|
109
|
1
|
|
|
1
|
0
|
13668
|
sub after(\@&) { List::MoreUtils::after( \&{ $_[1] }, @{ $_[0] } ); } |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
110
|
|
|
|
|
|
|
|
111
|
1
|
|
|
1
|
0
|
13668
|
sub after_incl(\@&) { List::MoreUtils::after_incl( \&{ $_[1] }, @{ $_[0] } ); } |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
8
|
|
112
|
|
|
|
|
|
|
|
113
|
1
|
|
|
1
|
0
|
13938
|
sub before(\@&) { List::MoreUtils::before( \&{ $_[1] }, @{ $_[0] } ); } |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
7
|
|
114
|
|
|
|
|
|
|
|
115
|
1
|
|
|
1
|
0
|
13536
|
sub before_incl(\@&) { List::MoreUtils::before_incl( \&{ $_[1] }, @{ $_[0] } ); } |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
116
|
|
|
|
|
|
|
|
117
|
1
|
|
|
1
|
0
|
13256
|
sub indexes(\@&) { List::MoreUtils::indexes( \&{ $_[1] }, @{ $_[0] } ); } |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
6
|
|
118
|
|
|
|
|
|
|
|
119
|
3
|
|
|
3
|
0
|
39110
|
sub firstval(\@&) { List::MoreUtils::firstval( \&{ $_[1] }, @{ $_[0] } ); } |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
26
|
|
120
|
|
|
|
|
|
|
sub first_value(\@&); |
121
|
|
|
|
|
|
|
*first_value = *{'firstval'}{CODE}; |
122
|
|
|
|
|
|
|
|
123
|
3
|
|
|
3
|
0
|
54184
|
sub lastval(\@&) { List::MoreUtils::lastval( \&{ $_[1] }, @{ $_[0] } ); } |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
22
|
|
124
|
|
|
|
|
|
|
sub last_value(\@&); |
125
|
|
|
|
|
|
|
*last_value = *{'lastval'}{CODE}; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub pairwise(\@&\@) |
128
|
|
|
|
|
|
|
{ |
129
|
2
|
|
|
2
|
0
|
25673
|
my $userfn = $_[1]; |
130
|
2
|
|
|
8
|
|
12
|
List::MoreUtils::pairwise( sub { &{$userfn}( $a, $b ); }, @{ $_[0] }, @{ $_[2] } ); |
|
8
|
|
|
|
|
303
|
|
|
8
|
|
|
|
|
20
|
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
16
|
|
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
1
|
|
|
1
|
0
|
14905
|
sub part(\@&) { List::MoreUtils::part( \&{ $_[1] }, @{ $_[0] } ) } |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
if ( defined( *{'List::MoreUtils::bsearch'}{CODE} ) ) |
136
|
|
|
|
|
|
|
{ |
137
|
|
|
|
|
|
|
eval <<'EOBS'; |
138
|
|
|
|
|
|
|
sub bsearch(\@&) |
139
|
|
|
|
|
|
|
{ |
140
|
|
|
|
|
|
|
my $userfn = $_[1]; |
141
|
|
|
|
|
|
|
List::MoreUtils::bsearch( sub { &{$userfn}( $_ ); }, @{$_[0]} ); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
push( @LIST_OPS, bsearch => \&bsearch ); |
144
|
|
|
|
|
|
|
EOBS |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 LIMITATION |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Except the typical limitations known from perl functions embedded in |
150
|
|
|
|
|
|
|
L, the only limitation I currently miss is being |
151
|
|
|
|
|
|
|
able to use TT2 defined macros as callback. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 SUPPORT |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Free support can be requested via regular CPAN bug-tracking system. There is |
156
|
|
|
|
|
|
|
no guaranteed reaction time or solution time. It depends on business load. |
157
|
|
|
|
|
|
|
That doesn't mean that ticket via rt aren't handles as soon as possible, that |
158
|
|
|
|
|
|
|
means that soon depends on how much I have to do. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Business and commercial support should be aquired via preferred freelancer |
161
|
|
|
|
|
|
|
agencies. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 AUTHOR |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Jens Rehsack |
166
|
|
|
|
|
|
|
CPAN ID: REHSACK |
167
|
|
|
|
|
|
|
rehsack@cpan.org |
168
|
|
|
|
|
|
|
http://search.cpan.org/~rehsack/ |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 COPYRIGHT |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
This program is free software; you can redistribute |
173
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
The full text of the license can be found in the |
176
|
|
|
|
|
|
|
LICENSE file included with this module. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 SEE ALSO |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
perl(1), L, |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
1; |