PDL/Logical.pm

filter: Statementstmt 100% 43 / 43 Branchbran 91.6% 11 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 2 totaltotal 91.7% 67 / 73 CC 8 SCAR 9.4
CC
8
Cov
97%
new
5.0
__ANON__
3.0
initialize
2.0
CRAP 2.6
« PDL/Role/Stringifiable.pm ↑ Summary PDL/Role/RowNameable.pm »
1 package PDL::Logical;
2 14 $PDL::Logical::VERSION = '0.006005';
3 # ABSTRACT: PDL subclass for keeping logical data
4  
5 14 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 14 ▶use PDL::Lite (); # PDL::Lite is the minimal to get PDL work
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 ▶use PDL::Core qw(pdl);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 14 ▶use Ref::Util qw(is_plain_arrayref);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 14 ▶use Safe::Isa;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 14 ▶use parent 'PDL';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 14 ▶use Class::Method::Modifiers;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 12 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
Pod undocumented
18 12 my ( $class, @args ) = @_;
19  
20 12 my $data;
21 12 ▶ if ( @args % 2 != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args % 2 != 0) 12 0 12
22 12 $data = shift @args; # first arg
23 }
24 12 my %opt = @args;
25  
26 12 ▶ if ( $data->$_DOES('PDL') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($data->$PDL::Logical::_DOES('PDL')) { } 4 8 12
elsif (is_plain_arrayref($data)) { } 6 2 8
27 4 $data = !!$data;
28 }
29 elsif ( is_plain_arrayref($data) ) {
30  
31 # this is faster than Data::Rmap::rmap().
32 34 ▶ state $rmap = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
33 34 my ($x) = @_;
34 is_plain_arrayref($x)
35 34 ▶ ? [ map { __SUB__->($_) } @$x ]
Branch: 2 branches
BranchTrueFalseTotal
is_plain_arrayref($x) ? : 10 24 34
$x ? : 12 12 24
36 : ( $x ? 1 : 0 );
37 6 };
38  
39 6 $data = pdl( $rmap->($data) );
40 }
41 else {
42 2 ▶ $data = pdl( $data ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$data ? : 1 1 2
43 }
44  
45 12 my $self = $class->initialize();
46 12 $self->{PDL} .= $data;
47  
48 12 return $self;
49 }
50  
51 66 ▶sub initialize {
Subroutine initialize: called CC=2 SCAR=7.1
Pod undocumented
52 66 my ($class) = @_;
53 66 ▶ return bless( { PDL => PDL::Core::null }, ref $class || $class );
Condition66%2/3
ref $class || $class
l!l&&r!l&&!r
44220
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table66%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
54 }
55  
56 14 1;
57  
58 __END__
« PDL/Role/Stringifiable.pm ↑ Summary PDL/Role/RowNameable.pm »