NDBin/Action/Count.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« NDBin/Action/Avg.pm ↑ Summary NDBin/Action/Max.pm »
1 package PDL::NDBin::Action::Count;
2 # ABSTRACT: Action for PDL::NDBin that counts elements
3 $PDL::NDBin::Action::Count::VERSION = '0.016';
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use PDL::Lite; # do not import any functions into this namespace
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use PDL::NDBin::Actions_PP;
Subroutine BEGIN: called CC=1 SCAR=2.6
9 use Params::Validate qw( validate OBJECT SCALAR );
10  
11  
12 sub new
13 {
14 my $class = shift;
15 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 return bless $self, $class;
20 }
21  
22  
23 sub process
24 {
25 my $self = shift;
26 my $iter = shift;
27 $self->{out} = PDL->zeroes( $self->{type}, $self->{N} ) unless defined $self->{out};
28 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 $iter->var_active( 0 );
32 return $self;
33 }
34  
35  
36 sub result
37 {
38 my $self = shift;
39 return $self->{out};
40 }
41  
42 1;
43  
44 __END__
« NDBin/Action/Avg.pm ↑ Summary NDBin/Action/Max.pm »