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.020';
4              
5 4     4   3894 use strict;
  4         9  
  4         131  
6 4     4   23 use warnings;
  4         9  
  4         103  
7 4     4   19 use PDL::Lite; # do not import any functions into this namespace
  4         7  
  4         35  
8 4     4   606 use PDL::NDBin::Actions_PP;
  4         8  
  4         28  
9 4     4   674 use Params::Validate qw( validate OBJECT SCALAR );
  4         7  
  4         1306  
10              
11              
12             sub new
13             {
14 115     115 1 6242 my $class = shift;
15 115 50       877 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         4176 return bless $self, $class;
20             }
21              
22              
23             sub process
24             {
25 129     129 1 232 my $self = shift;
26 129         185 my $iter = shift;
27 129 100       563 $self->{out} = PDL->zeroes( $self->{type}, $self->{N} ) unless defined $self->{out};
28 129         7952 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         622 $iter->var_active( 0 );
32 129         902 return $self;
33             }
34              
35              
36             sub result
37             {
38 112     112 1 565 my $self = shift;
39 112         372 return $self->{out};
40             }
41              
42             1;
43              
44             __END__