File Coverage

blib/lib/PDL/NDBin/Action/Count.pm
Criterion Covered Total %
statement 26 26 100.0
branch 3 4 75.0
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 40 41 97.5


line stmt bran cond sub pod time code
1             package PDL::NDBin::Action::Count;
2             # ABSTRACT: Action for PDL::NDBin that counts elements
3             $PDL::NDBin::Action::Count::VERSION = '0.019';
4              
5 4     4   3954 use strict;
  4         10  
  4         162  
6 4     4   23 use warnings;
  4         8  
  4         116  
7 4     4   21 use PDL::Lite; # do not import any functions into this namespace
  4         8  
  4         43  
8 4     4   612 use PDL::NDBin::Actions_PP;
  4         7  
  4         34  
9 4     4   651 use Params::Validate qw( validate OBJECT SCALAR );
  4         8  
  4         1388  
10              
11              
12             sub new
13             {
14 115     115 1 6369 my $class = shift;
15 115 50       870 my $self = validate( @_, {
16             N => { type => SCALAR, regex => qr/^\d+$/ },
17             type => { type => OBJECT, isa => 'PDL::Type', default => defined(&PDL::indx) ? PDL::indx() : PDL::long }
18             } );
19 115         4191 return bless $self, $class;
20             }
21              
22              
23             sub process
24             {
25 129     129 1 247 my $self = shift;
26 129         251 my $iter = shift;
27 129 100       595 $self->{out} = PDL->zeroes( $self->{type}, $self->{N} ) unless defined $self->{out};
28 129         8464 PDL::NDBin::Actions_PP::_icount_loop( $iter->data, $iter->idx, $self->{out}, $self->{N} );
29             # as the plugin processes all bins at once, every variable
30             # needs to be visited only once
31 129         620 $iter->var_active( 0 );
32 129         574 return $self;
33             }
34              
35              
36             sub result
37             {
38 112     112 1 554 my $self = shift;
39 112         378 return $self->{out};
40             }
41              
42             1;
43              
44             __END__