package Template::Plugin::SumOf; use strict; use warnings; use base qw(Template::Plugin); use Carp; use Template::Stash; use List::Util qw/sum/; use Scalar::Util qw/blessed/; use version; our $VERSION = '0.02'; $Template::Stash::LIST_OPS->{sum_of} = sub { my ( $self, $column ) = @_; return sum map { blessed $_ ? $_->$column : $_->{$column} } @$self; }; 1; # Magic true value required at end of module __END__ =head1 NAME Template::Plugin::SumOf - calcurate the sum with VMETHODS. =head1 SYNOPSIS # in your script use Template; use Template::Plugin::SumOf; my $tt = Template->new; $tt->process( 'template.html', { ary => [ { date => '2006-09-13', price => 300 }, { date => '2006-09-14', price => 500 } ] } ) or die $tt->error; # in your template. [% USE SumOf -%] [%- FOR elem IN objects -%] [% elem.date %],[% elem.price %] [% END -%] ,[% objects.sum_of('price') %] # result. 2006-09-13,300 2006-09-14,500 ,800 =head1 DESCRIPTION You can easy to calcurate sum of array, with VMETHODS. =head1 BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests to C, or through the web interface at L. =head1 AUTHOR Tokuhiro Matsuno C<< >> =head1 SEE ALSO L