| 1 | package Template::Plugin::ListMoreUtils; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 3 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use vars qw($VERSION @ISA); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 3 | ▶ | use List::MoreUtils; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 3 | ▶ | use Template::Plugin::Procedural; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 3 | ▶ | use vars qw(@ISA $VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 3 | $VERSION = '0.02'; | |||||||||
| 15 | 3 | @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<List::MoreUtils>. It extends the built-in functions dealing with lists as | ||||||||||
| 35 | well as L<Template::Plugin::ListUtil>. | ||||||||||
| 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<Template::Plugin::ListMoreUtilsVMethods>. | ||||||||||
| 51 | |||||||||||
| 52 | =head1 FUNCTIONS PROVIDED | ||||||||||
| 53 | |||||||||||
| 54 | All functions behave as documented in L<List::MoreUtils>. I don't plan to | ||||||||||
| 55 | copy the entire POD from there. | ||||||||||
| 56 | L<Template::Toolkit> provides lists as list reference, so they were expanded | ||||||||||
| 57 | before the appropriate function in C<List::MoreUtils> is called. | ||||||||||
| 58 | |||||||||||
| 59 | =head2 any BLOCK LIST | ||||||||||
| 60 | |||||||||||
| 61 | =cut | ||||||||||
| 62 | |||||||||||
| 63 | 2 | ▶ | sub any(&\@) { List::MoreUtils::any( \&{ $_[0] }, @{ $_[1] } ); } | ||||||||
|
Subroutine
any: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 64 | |||||||||||
| 65 | =head2 all BLOCK LIST | ||||||||||
| 66 | |||||||||||
| 67 | =cut | ||||||||||
| 68 | |||||||||||
| 69 | 2 | ▶ | sub all(&\@) { List::MoreUtils::all( \&{ $_[0] }, @{ $_[1] } ); } | ||||||||
|
Subroutine
all: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 70 | |||||||||||
| 71 | =head2 none BLOCK LIST | ||||||||||
| 72 | |||||||||||
| 73 | =cut | ||||||||||
| 74 | |||||||||||
| 75 | 2 | ▶ | sub none(&\@) { List::MoreUtils::none( \&{ $_[0] }, @{ $_[1] } ); } | ||||||||
|
Subroutine
none: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 76 | |||||||||||
| 77 | =head2 notall BLOCK LIST | ||||||||||
| 78 | |||||||||||
| 79 | =cut | ||||||||||
| 80 | |||||||||||
| 81 | 2 | ▶ | sub notall(&\@) { List::MoreUtils::notall( \&{ $_[0] }, @{ $_[1] } ); } | ||||||||
|
Subroutine
notall: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 82 | |||||||||||
| 83 | =head2 true BLOCK LIST | ||||||||||
| 84 | |||||||||||
| 85 | =cut | ||||||||||
| 86 | |||||||||||
| 87 | 3 | ▶ | sub true(&\@) { List::MoreUtils::true( \&{ $_[0] }, @{ $_[1] } ); } | ||||||||
|
Subroutine
true: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 88 | |||||||||||
| 89 | =head2 false BLOCK LIST | ||||||||||
| 90 | |||||||||||
| 91 | =cut | ||||||||||
| 92 | |||||||||||
| 93 | 3 | ▶ | sub false(&\@) { List::MoreUtils::false( \&{ $_[0] }, @{ $_[1] } ); } | ||||||||
|
Subroutine
false: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 94 | |||||||||||
| 95 | =head2 firstidx BLOCK LIST | ||||||||||
| 96 | |||||||||||
| 97 | =head2 first_index BLOCK LIST | ||||||||||
| 98 | |||||||||||
| 99 | =cut | ||||||||||
| 100 | |||||||||||
| 101 | 3 | ▶ | sub firstidx(&\@) { List::MoreUtils::firstidx( \&{ $_[0] }, @{ $_[1] } ); } | ||||||||
|
Subroutine
firstidx: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 102 | 3 | *first_index = *{'firstidx'}{CODE}; | |||||||||
| 103 | |||||||||||
| 104 | =head2 lastidx BLOCK LIST | ||||||||||
| 105 | |||||||||||
| 106 | =head2 last_index BLOCK LIST | ||||||||||
| 107 | |||||||||||
| 108 | =cut | ||||||||||
| 109 | |||||||||||
| 110 | 3 | ▶ | sub lastidx(&\@) { List::MoreUtils::lastidx( \&{ $_[0] }, @{ $_[1] } ); } | ||||||||
|
Subroutine
lastidx: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 111 | 3 | *last_index = *{'lastidx'}{CODE}; | |||||||||
| 112 | |||||||||||
| 113 | =head2 insert_after BLOCK VALUE LIST | ||||||||||
| 114 | |||||||||||
| 115 | =cut | ||||||||||
| 116 | |||||||||||
| 117 | 3 | ▶ | *insert_after = *{'List::MoreUtils::insert_after'}{CODE} if ( defined( *{'List::MoreUtils::insert_after'}{CODE} ) ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | |||||||||||
| 119 | =head2 insert_after_string STRING VALUE LIST | ||||||||||
| 120 | |||||||||||
| 121 | =cut | ||||||||||
| 122 | |||||||||||
| 123 | 3 | *insert_after_string = *{'List::MoreUtils::insert_after_string'}{CODE} | |||||||||
| 124 | 3 | ▶ | if ( defined( *{'List::MoreUtils::insert_after_string'}{CODE} ) ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 125 | |||||||||||
| 126 | =head2 apply BLOCK LIST | ||||||||||
| 127 | |||||||||||
| 128 | =cut | ||||||||||
| 129 | |||||||||||
| 130 | 1 | ▶ | sub apply(&\@) { List::MoreUtils::apply( \&{ $_[0] }, @{ $_[1] } ); } | ||||||||
|
Subroutine
apply: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 131 | |||||||||||
| 132 | =head2 after BLOCK LIST | ||||||||||
| 133 | |||||||||||
| 134 | =cut | ||||||||||
| 135 | |||||||||||
| 136 | 1 | ▶ | sub after(&\@) { List::MoreUtils::after( \&{ $_[0] }, @{ $_[1] } ); } | ||||||||
|
Subroutine
after: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 137 | |||||||||||
| 138 | =head2 after_incl BLOCK LIST | ||||||||||
| 139 | |||||||||||
| 140 | =cut | ||||||||||
| 141 | |||||||||||
| 142 | 1 | ▶ | sub after_incl(&\@) { List::MoreUtils::after_incl( \&{ $_[0] }, @{ $_[1] } ); } | ||||||||
|
Subroutine
after_incl: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 143 | |||||||||||
| 144 | =head2 before BLOCK LIST | ||||||||||
| 145 | |||||||||||
| 146 | =cut | ||||||||||
| 147 | |||||||||||
| 148 | 1 | ▶ | sub before(&\@) { List::MoreUtils::before( \&{ $_[0] }, @{ $_[1] } ); } | ||||||||
|
Subroutine
before: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 149 | |||||||||||
| 150 | =head2 before_incl BLOCK LIST | ||||||||||
| 151 | |||||||||||
| 152 | =cut | ||||||||||
| 153 | |||||||||||
| 154 | 1 | ▶ | sub before_incl(&\@) { List::MoreUtils::before_incl( \&{ $_[0] }, @{ $_[1] } ); } | ||||||||
|
Subroutine
before_incl: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 155 | |||||||||||
| 156 | =head2 indexes BLOCK LIST | ||||||||||
| 157 | |||||||||||
| 158 | =cut | ||||||||||
| 159 | |||||||||||
| 160 | 1 | ▶ | sub indexes(&\@) { List::MoreUtils::indexes( \&{ $_[0] }, @{ $_[1] } ); } | ||||||||
|
Subroutine
indexes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 161 | |||||||||||
| 162 | =head2 firstval BLOCK LIST | ||||||||||
| 163 | |||||||||||
| 164 | =head2 first_value BLOCK LIST | ||||||||||
| 165 | |||||||||||
| 166 | =cut | ||||||||||
| 167 | |||||||||||
| 168 | 3 | ▶ | sub firstval(&\@) { List::MoreUtils::firstval( \&{ $_[0] }, @{ $_[1] } ); } | ||||||||
|
Subroutine
firstval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 169 | 3 | *first_value = *{'firstval'}{CODE}; | |||||||||
| 170 | |||||||||||
| 171 | =head2 lastval BLOCK LIST | ||||||||||
| 172 | |||||||||||
| 173 | =head2 last_value BLOCK LIST | ||||||||||
| 174 | |||||||||||
| 175 | =cut | ||||||||||
| 176 | |||||||||||
| 177 | 3 | ▶ | sub lastval(&\@) { List::MoreUtils::lastval( \&{ $_[0] }, @{ $_[1] } ); } | ||||||||
|
Subroutine
lastval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 178 | 3 | *last_value = *{'lastval'}{CODE}; | |||||||||
| 179 | |||||||||||
| 180 | =head2 pairwise BLOCK LIST LIST | ||||||||||
| 181 | |||||||||||
| 182 | Unlike the original C<pairwise>, 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 | ▶ | my $userfn = $_[0]; | ||||||||
|
Subroutine
pairwise: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 191 | 2 | ▶ | List::MoreUtils::pairwise( sub { &{$userfn}( $a, $b ); }, @{ $_[1] }, @{ $_[2] } ); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 192 | } | ||||||||||
| 193 | |||||||||||
| 194 | =head2 minmax LIST | ||||||||||
| 195 | |||||||||||
| 196 | =cut | ||||||||||
| 197 | |||||||||||
| 198 | 4 | ▶ | sub minmax(\@) { List::MoreUtils::minmax( @{ $_[0] } ); } | ||||||||
|
Subroutine
minmax: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 199 | |||||||||||
| 200 | =head2 uniq LIST | ||||||||||
| 201 | |||||||||||
| 202 | =cut | ||||||||||
| 203 | |||||||||||
| 204 | 4 | ▶ | sub uniq(\@) { List::MoreUtils::uniq( @{ $_[0] } ); } | ||||||||
|
Subroutine
uniq: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 205 | |||||||||||
| 206 | =head2 mesh | ||||||||||
| 207 | |||||||||||
| 208 | =head2 zip | ||||||||||
| 209 | |||||||||||
| 210 | =cut | ||||||||||
| 211 | |||||||||||
| 212 | 3 | ▶ | *mesh = *{'List::MoreUtils::mesh'}{CODE} if ( defined( *{'List::MoreUtils::mesh'}{CODE} ) ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 213 | 3 | ▶ | *zip = *{'List::MoreUtils::zip'}{CODE} if ( defined( *{'List::MoreUtils::zip'}{CODE} ) ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 214 | |||||||||||
| 215 | =head2 part BLOCK LIST | ||||||||||
| 216 | |||||||||||
| 217 | =cut | ||||||||||
| 218 | |||||||||||
| 219 | 1 | ▶ | sub part(&\@) { List::MoreUtils::part( \&{ $_[0] }, @{ $_[1] } ) } | ||||||||
|
Subroutine
part: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 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<bsearch>, 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 | 3 | ▶ | if ( defined( *{'List::MoreUtils::bsearch'}{CODE} ) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 232 | { | ||||||||||
| 233 | 7 | ▶ | eval <<'EOBS'; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
bsearch: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 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<Template::Toolkit>, 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<List::MoreUtils>, <Template::Plugin::ListUtil> | ||||||||||
| 285 | |||||||||||
| 286 | =cut | ||||||||||
| 287 | |||||||||||
| 288 | 3 | 1; | |||||||||