NDim/Dim.pm

filter: Statementstmt 94.3% 67 / 71 Branchbran 71.4% 10 / 14 Conditioncond 55.5% 5 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 93.3% 14 / 15 Podpod 100% 4 / 4 totaltotal 85.7% 102 / 119 CC 15 SCAR 14.0
CC
15
Cov
87%
__ANON__
12.0
__ANON__
5.0
increment
5.0
CRAP 4.0
« NDim/Life.pm ↑ Summary
1 package Game::Life::NDim::Dim;
2  
3 # Created on: 2010-01-08 18:43:32
4 # Create by: Ivan Wills
5 # $Id$
6 # $Revision$, $HeadURL$, $Date$
7 # $Revision$, $Source$, $Date$
8  
9 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Data::Dumper qw/Dumper/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use English qw/ -no_match_vars /;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 use overload
17 1017 ▶ '""' => sub { '[' . ( join ',', @{ $_[0]->elements } ) . ']' },
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: called CC=1 SCAR=0.0
18 13450 ▶ '@{}' => sub { $_[0]->elements },
Subroutine __ANON__: called CC=1 SCAR=0.0
19 0 ▶ '==' => sub { for (0..@{$_->[0]}-1) { return 0 if $_[0][$_] != $_[1][$_] } return 1 },
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if $_[0][$_] != $_[1][$_] 0 0 0
20 4 '+' => \&sum_list;
21  
22 4 our $VERSION = version->new('0.0.4');
23 4 our @EXPORT_OK = qw//;
24 4 our %EXPORT_TAGS = ();
25  
26 4 has elements => (
27 is => 'rw',
28 isa => 'ArrayRef',
29 required => 1,
30 );
31  
32 4 has max => (
33 is => 'rw',
34 isa => 'ArrayRef[Int]',
35 weak_ref => 1,
36 );
37  
38 1696 ▶around new => sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
39 1696 my ($new, $class, @args) = @_;
40  
41 1696 ▶ if ( @args == 1 && ref $args[0] eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args == 1 and ref $args[0] eq 'ARRAY') { } 1692 4 1696
Condition66%2/3
@args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
401692
MC/DC50%1/2
@args == 1 and ref $args[0] eq "ARRAY"
@args == 1 ref $args[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
42 1692 @args = ( elements => $args[0] );
43 }
44 else {
45 4 my %params = @args;
46 4 ▶ if (!exists $params{elements} && exists $params{max}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $params{"elements"} and exists $params{"max"}) 1 3 4
Condition66%2/3
not exists $params{"elements"} and exists $params{"max"}
!ll&&!rl&&r
301
MC/DC50%1/2
not exists $params{"elements"} and exists $params{"max"}
not exists $params{"elements"} exists $params{"max"}
Truth table66%2/3
not(A) and B
A= not exists $params{"elements"}B= exists $params{"max"}
ABresult
0X0
100
111
47 1 $params{elements} = [ @{ $params{max} } ];
48 1 return $new->($class, %params)->zero;
49 }
50 }
51  
52 1695 return $new->($class, @args);
53 4 };
54  
55 1033 ▶sub increment {
Subroutine increment: called CC=5 SCAR=16.1
Pod documented
56 1033 my ($self, $max) = @_;
57 1033 my $last;
58  
59 1033 for my $i ( reverse 0 .. @{ $max } - 1 ) {
60 1156 ▶ die "max[$i] == 0 which is not allowed!" if $max->[$i] == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $max->[$i] == 0 0 1156 1156
61 1156 ▶ if ( $self->[$i] + 1 <= $max->[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[$i] + 1 <= $max->[$i]) 1028 128 1156
62 1028 $self->[$i]++;
63 1028 $last = $i;
64 1028 last;
65 }
66 128 $self->[$i] = 0;
67 }
68  
69 1033 ▶ return if !defined $last;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $last 5 1028 1033
70  
71 1028 return $self;
72 }
73  
74 3 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
75 3 my ($self) = @_;
76  
77 3 return $self->new(elements => [ @{ $self } ]);
78 }
79  
80 2 ▶sub zero {
Subroutine zero: called CC=2 SCAR=6.9
Pod documented
81 2 my ($self) = @_;
82  
83 2 for my $item (@{ $self }) {
84 6 $item = 0;
85 }
86  
87 2 return $self;
88 }
89  
90 36 ▶sub sum_list {
Subroutine sum_list: called CC=4 SCAR=14.5
Pod documented
91 36 my ($self, $list) = @_;
92  
93 36 my @new;
94 36 for my $i ( 0 .. @{ $self } - 1 ) {
95 96 ▶ die Dumper $i, $self, $list if !defined $self->[$i] || !defined $list->[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->[$i] and defined $list->[$i] 0 96 96
Condition33%1/3
defined $self->[$i] and defined $list->[$i]
!ll&&!rl&&r
0096
MC/DC0%0/2
defined $self->[$i] and defined $list->[$i]
defined $self->[$i] defined $list->[$i]
Truth table33%1/3
A and B
A= defined $self->[$i]B= defined $list->[$i]
ABresult
0X0
100
111
96 96 $new[$i] = $self->[$i] + $list->[$i];
97 }
98  
99 36 return __PACKAGE__->new(\@new);
100 }
101  
102 4 1;
103  
104 __END__
« NDim/Life.pm ↑ Summary