| 1 | package Template::Plugin::ListMoreUtilsVMethods; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use vars qw($VERSION @ISA $VMETHOD_PACKAGE @LIST_OPS); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use Template::Plugin::VMethods; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | $VERSION = '0.02'; | |||||||||
| 10 | 2 | @ISA = qw(Template::Plugin::VMethods); | |||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use Template::Plugin::ListMoreUtils; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | $VMETHOD_PACKAGE = 'Template::Plugin::ListMoreUtils'; | |||||||||
| 14 | |||||||||||
| 15 | 2 | @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<List::MoreUtils>. It extends the built-in functions dealing with lists as | ||||||||||
| 61 | well as L<Template::Plugin::ListUtil>. | ||||||||||
| 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<Template::Plugin::ListMoreUtils>, regardless the preferred interface. | ||||||||||
| 79 | |||||||||||
| 80 | =cut | ||||||||||
| 81 | |||||||||||
| 82 | 2 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 83 | |||||||||||
| 84 | 2 | ▶ | sub any(\@&) { List::MoreUtils::any( \&{ $_[1] }, @{ $_[0] } ); } | ||||||||
|
Subroutine
any: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 85 | |||||||||||
| 86 | 2 | ▶ | sub all(\@&) { List::MoreUtils::all( \&{ $_[1] }, @{ $_[0] } ); } | ||||||||
|
Subroutine
all: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 87 | |||||||||||
| 88 | 2 | ▶ | sub none(\@&) { List::MoreUtils::none( \&{ $_[1] }, @{ $_[0] } ); } | ||||||||
|
Subroutine
none: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 89 | |||||||||||
| 90 | 2 | ▶ | sub notall(\@&) { List::MoreUtils::notall( \&{ $_[1] }, @{ $_[0] } ); } | ||||||||
|
Subroutine
notall: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 91 | |||||||||||
| 92 | 3 | ▶ | sub true(\@&) { List::MoreUtils::true( \&{ $_[1] }, @{ $_[0] } ); } | ||||||||
|
Subroutine
true: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 93 | |||||||||||
| 94 | 3 | ▶ | sub false(\@&) { List::MoreUtils::false( \&{ $_[1] }, @{ $_[0] } ); } | ||||||||
|
Subroutine
false: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 95 | |||||||||||
| 96 | 3 | ▶ | sub firstidx(\@&) { List::MoreUtils::firstidx( \&{ $_[1] }, @{ $_[0] } ); } | ||||||||
|
Subroutine
firstidx: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 97 | sub first_index(\@&); | ||||||||||
| 98 | 2 | *first_index = *{'firstidx'}{CODE}; | |||||||||
| 99 | |||||||||||
| 100 | 3 | ▶ | sub lastidx(\@&) { List::MoreUtils::lastidx( \&{ $_[1] }, @{ $_[0] } ); } | ||||||||
|
Subroutine
lastidx: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 101 | sub last_index(\@&); | ||||||||||
| 102 | 2 | *last_index = *{'lastidx'}{CODE}; | |||||||||
| 103 | |||||||||||
| 104 | 1 | ▶ | sub insert_after (\@&$) { List::MoreUtils::insert_after( \&{ $_[1] }, $_[2], @{ $_[0] } ); } | ||||||||
|
Subroutine
insert_after: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 105 | 1 | ▶ | sub insert_after_string (\@$$) { List::MoreUtils::insert_after_string( $_[1], $_[2], @{ $_[0] } ); } | ||||||||
|
Subroutine
insert_after_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 106 | |||||||||||
| 107 | 1 | ▶ | sub apply(\@&) { List::MoreUtils::apply( \&{ $_[1] }, @{ $_[0] } ); } | ||||||||
|
Subroutine
apply: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 108 | |||||||||||
| 109 | 1 | ▶ | sub after(\@&) { List::MoreUtils::after( \&{ $_[1] }, @{ $_[0] } ); } | ||||||||
|
Subroutine
after: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 110 | |||||||||||
| 111 | 1 | ▶ | sub after_incl(\@&) { List::MoreUtils::after_incl( \&{ $_[1] }, @{ $_[0] } ); } | ||||||||
|
Subroutine
after_incl: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 112 | |||||||||||
| 113 | 1 | ▶ | sub before(\@&) { List::MoreUtils::before( \&{ $_[1] }, @{ $_[0] } ); } | ||||||||
|
Subroutine
before: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 114 | |||||||||||
| 115 | 1 | ▶ | sub before_incl(\@&) { List::MoreUtils::before_incl( \&{ $_[1] }, @{ $_[0] } ); } | ||||||||
|
Subroutine
before_incl: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 116 | |||||||||||
| 117 | 1 | ▶ | sub indexes(\@&) { List::MoreUtils::indexes( \&{ $_[1] }, @{ $_[0] } ); } | ||||||||
|
Subroutine
indexes: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 118 | |||||||||||
| 119 | 3 | ▶ | sub firstval(\@&) { List::MoreUtils::firstval( \&{ $_[1] }, @{ $_[0] } ); } | ||||||||
|
Subroutine
firstval: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 120 | sub first_value(\@&); | ||||||||||
| 121 | 2 | *first_value = *{'firstval'}{CODE}; | |||||||||
| 122 | |||||||||||
| 123 | 3 | ▶ | sub lastval(\@&) { List::MoreUtils::lastval( \&{ $_[1] }, @{ $_[0] } ); } | ||||||||
|
Subroutine
lastval: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 124 | sub last_value(\@&); | ||||||||||
| 125 | 2 | *last_value = *{'lastval'}{CODE}; | |||||||||
| 126 | |||||||||||
| 127 | sub pairwise(\@&\@) | ||||||||||
| 128 | { | ||||||||||
| 129 | 2 | ▶ | my $userfn = $_[1]; | ||||||||
|
Subroutine
pairwise: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 130 | 2 | ▶ | List::MoreUtils::pairwise( sub { &{$userfn}( $a, $b ); }, @{ $_[0] }, @{ $_[2] } ); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 131 | } | ||||||||||
| 132 | |||||||||||
| 133 | 1 | ▶ | sub part(\@&) { List::MoreUtils::part( \&{ $_[1] }, @{ $_[0] } ) } | ||||||||
|
Subroutine
part: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 134 | |||||||||||
| 135 | 2 | ▶ | if ( defined( *{'List::MoreUtils::bsearch'}{CODE} ) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 136 | { | ||||||||||
| 137 | 7 | ▶ | eval <<'EOBS'; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
bsearch: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 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<Template::Toolkit>, 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<List::MoreUtils>, <Template::Plugin::VMethods> | ||||||||||
| 181 | |||||||||||
| 182 | =cut | ||||||||||
| 183 | |||||||||||
| 184 | 2 | 1; | |||||||||