EO/Array.pm

filter: Statementstmt 89.7% 96 / 107 Branchbran 73.3% 22 / 30 Conditioncond 66.6% 6 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 95.4% 21 / 22 Podpod 81.2% 13 / 16 totaltotal 84.2% 160 / 190 CC 21 SCAR 13.5
CC
21
Cov
85%
new_with_array
9.8
splice
5.0
at
4.2
CRAP 3.9
« EO/Message.pm ↑ Summary EO/File.pm »
1 package EO::Array;
2  
3 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use EO::Collection;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 13 our $VERSION = 0.96;
8 13 our @ISA = qw( EO::Collection );
9  
10 13 ▶use overload '@{}' => 'get_reference',
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 'fallback' => 1;
12  
13 40 ▶sub init {
Subroutine init: called CC=2 SCAR=7.4
Pod undocumented
14 40 my $self = CORE::shift;
15 40 ▶ if ($self->SUPER::init( @_ )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->SUPER::init(@_)) 40 0 40
16 40 $self->element( [] );
17 40 return 1;
18 }
19 0 return 0;
20 }
21  
22 109 ▶sub get_reference {
Subroutine get_reference: called CC=1 SCAR=0.0
Pod undocumented
23 109 my $self = shift;
24 109 return $self->element;
25 }
26  
27 9 ▶sub new_with_array {
Subroutine new_with_array: called CC=8 SCAR=22.8
Pod documented
28 9 my $class = CORE::shift;
29 9 my $array;
30 9 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) { } 5 4 9
31 5 $array = [ @_ ];
32 } else {
33 4 $array = CORE::shift;
34 4 ▶ if (defined($array) && !ref($array)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $array and not ref $array) 0 4 4
Condition66%2/3
defined $array and not ref $array
!ll&&!rl&&r
220
MC/DC0%0/2
defined $array and not ref $array
defined $array not ref $array
Truth table66%2/3
A and not(B)
A= defined $arrayB= not ref $array
ABresult
0X0
100
111
35 0 print "Not an array, making it one...\n";
36 0 $array = [ $array ];
37 }
38 }
39 9 ▶ if (!$array) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($array) 2 7 9
40 2 throw EO::Error::InvalidParameters text => 'no array specified';
41 }
42 7 ▶ if (!ref($array)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $array) 0 7 7
43 0 throw EO::Error::InvalidParameters text => 'not a reference';
44 }
45 7 ▶ if (ref($array) && ref($array) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $array and ref $array ne "ARRAY") 0 7 7
Condition33%1/3
ref $array and ref $array ne "ARRAY"
!ll&&!rl&&r
070
MC/DC0%0/2
ref $array and ref $array ne "ARRAY"
ref $array ref $array ne "ARRAY"
Truth table33%1/3
A and B
A= ref $arrayB= ref $array ne "ARRAY"
ABresult
0X0
100
111
46 0 throw EO::Error::InvalidParameters text => 'not an array reference';
47 }
48 7 my $self = $class->new();
49 7 $self->element( $array );
50 7 return $self;
51 }
52  
53 2 ▶sub do {
Subroutine do: called CC=2 SCAR=6.9
Pod documented
54 2 my $self = CORE::shift;
55 2 my $code = CORE::shift;
56 2 my $array = ref($self)->new();
57 2 foreach my $element (@{ $self->element }) {
58 14 local $_ = $element;
59 14 $array->push( $code->( $element ) );
60 }
61 2 return $array;
62 }
63  
64 2 ▶sub reverse {
Subroutine reverse: called CC=1 SCAR=0.0
Pod documented
65 2 my $self = CORE::shift;
66 2 ref($self)->new_with_array( CORE::reverse( @{ $self->element } ) );
67 }
68  
69 2 ▶sub select {
Subroutine select: called CC=3 SCAR=11.0
Pod documented
70 2 my $self = CORE::shift;
71 2 my $code = CORE::shift;
72 2 my $array = ref($self)->new();
73 2 foreach my $element (@{ $self->element }) {
74 14 local $_ = $element;
75 14 ▶ $array->push( $element ) if $code->( $element );
Branch: 1 branch
BranchTrueFalseTotal
if &$code($element) 8 6 14
76 }
77 2 return $array;
78 }
79  
80 57 ▶sub at {
Subroutine at: called CC=4 SCAR=14.5
Pod documented
81 57 my $self = CORE::shift;
82 57 my $idx = CORE::shift;
83 57 ▶ if (!defined($idx)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $idx) 0 57 57
84 0 throw EO::Error::InvalidParameters
85 text => 'no index provided for the array';
86 }
87 57 ▶ if ($idx =~ /\D/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx =~ /\D/) 0 57 57
88 0 throw EO::Error::InvalidParameters
89 text => 'non-integer index specified';
90 }
91 57 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 21 36 57
92 21 $self->element->[ $idx ] = CORE::shift;
93 21 return $self;
94 }
95 36 return $self->element->[ $idx ];
96 }
97  
98 0 ▶sub object_at_index : Deprecated {
Subroutine object_at_index: not called CC=1 SCAR=6.9
99 0 my $self = shift;
100 0 $self->at( @_ );
101 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
102  
103 6 ▶sub delete {
Subroutine delete: called CC=3 SCAR=11.2
Pod documented
104 6 my $self = CORE::shift;
105 6 my $idx = CORE::shift;
106 6 ▶ if (!defined($idx)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $idx) 2 4 6
107 2 throw EO::Error::InvalidParameters text => "no index provided for the array";
108 }
109 4 ▶ if ($idx =~ /\D/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx =~ /\D/) 0 4 4
110 0 throw EO::Error::InvalidParameters text => 'non-integer index specified';
111 }
112 4 $self->splice( $idx, 1 );
113 }
114  
115 103 ▶sub splice {
Subroutine splice: called CC=5 SCAR=16.2
Pod documented
116 103 my $self = CORE::shift;
117 103 my $offset = CORE::shift;
118 103 my $length = CORE::shift;
119 103 ▶ if (!@_ && $length) {
Branch: 3 branches
BranchTrueFalseTotal
if (not @_ and $length) { } 6 97 103
elsif (not defined $length) { } 2 95 97
elsif (not defined $offset) { } 0 95 95
Condition100%3/3
not @_ and $length
!ll&&!rl&&r
9346
MC/DC100%2/2
not @_ and $length
not @_ $length
Truth table100%3/3
not(A) and B
A= not @_B= $length
ABresult
0X0
100
111
120  
121 6 return CORE::splice( @$self, $offset, $length );
122  
123 } elsif (!defined $length) {
124  
125 2 return CORE::splice( @$self, $offset );
126  
127 } elsif (!defined $offset) {
128  
129 0 return CORE::splice( @$self );
130  
131 } else {
132  
133 95 return CORE::splice(@$self, $offset, $length, @_);
134  
135 }
136 }
137  
138 114 ▶sub count {
Subroutine count: called CC=1 SCAR=0.0
Pod documented
139 114 my $self = CORE::shift;
140 114 return scalar( $self->iterator );
141 }
142  
143 93 ▶sub push {
Subroutine push: called CC=1 SCAR=0.0
Pod documented
144 93 my $self = CORE::shift;
145 93 $self->splice( $self->count, 0, @_ );
146 93 return $self;
147 }
148  
149 2 ▶sub pop {
Subroutine pop: called CC=1 SCAR=0.0
Pod documented
150 2 my $self = CORE::shift;
151 2 $self->splice( -1 );
152 }
153  
154 2 ▶sub shift {
Subroutine shift: called CC=1 SCAR=0.0
Pod documented
155 2 my $self = CORE::shift;
156 2 $self->splice( 0, 1 );
157 }
158  
159 2 ▶sub unshift {
Subroutine unshift: called CC=1 SCAR=0.0
Pod documented
160 2 my $self = CORE::shift;
161 2 $self->splice( 0, 0, @_ );
162 2 return $self;
163 }
164  
165 5 ▶sub join {
Subroutine join: called CC=1 SCAR=0.0
Pod undocumented
166 5 my $self = CORE::shift;
167 5 my $joiner = CORE::shift;
168 5 return join($joiner, $self->iterator);
169 }
170  
171 123 ▶sub iterator {
Subroutine iterator: called CC=1 SCAR=0.0
Pod documented
172 123 my $self = CORE::shift;
173 123 my @list = @{ $self->element };
174 123 return @list;
175 }
176  
177 13 1;
178  
179 __END__
« EO/Message.pm ↑ Summary EO/File.pm »