Code/Array.pm

filter: Statementstmt 19.3% 12 / 62 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 33.3% 3 / 9 Podpod 100% 6 / 6 totaltotal 16.4% 21 / 128 CC 23 SCAR 38.6
CC
23
Cov
12%
push_back
90.0
at
42.0
output
42.0
CRAP 47.5
↑ Summary Code/Condition.pm »
1 package JavaScript::Code::Array;
2
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use vars qw[ $VERSION ];
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use base qw[ JavaScript::Code::Type ];
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 2 __PACKAGE__->mk_accessors(qw[ elements size ]);
8
9 2 $VERSION = '0.08';
10
11 =head1 NAME
12
13 JavaScript::Code::Array - A JavaScript Array Type
14
15 =head1 SYNOPSIS
16
17 #!/usr/bin/perl
18
19 use strict;
20 use warnings;
21 use JavaScript::Code::Array;
22
23 my $array = JavaScript::Code::Array->new( elements => [] );
24
25 =head1 METHODS
26
27 =head2 new( ... )
28
29 =cut
30
31 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
32 0 my $this = shift;
33 0 ▶ my $class = ref($this) || $this;
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
34
35 0 my $self = $class->SUPER::new(@_);
36
37 # cleanup the elements
38 0 ▶ my $array = delete $self->{elements} || [];
Condition0%0/2
delete $self->{'elements'} || []
l!l
00
MC/DC0%0/1
delete $self->{'elements'} || []
delete $self->{'elements'}
Truth table0%0/2
A
A= delete $self->{'elements'}
Aresult
11
00
39 0 ▶ push @{$array}, @{ delete $self->{value} || [] };
Condition0%0/2
delete $self->{'value'} || []
l!l
00
MC/DC0%0/1
delete $self->{'value'} || []
delete $self->{'value'}
Truth table0%0/2
A
A= delete $self->{'value'}
Aresult
11
00
40 0 $self->elements( [] );
41 0 ▶ $self->push_back($array) if defined $array;
Branch: 1 branch
BranchTrueFalseTotal
if defined $array 0 0 0
42
43 0 return $self;
44 }
45
46 =head2 $self->push_back( $value | \@values )
47
48 Add one or more element(s) to the end of array.
49
50 =cut
51
52 0 ▶sub push_back {
Subroutine push_back: not called CC=9 SCAR=45.0
Pod documented
53 0 my ( $self, $array ) = @_;
54
55 0 ▶ die 'Nothing to add.'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $array 0 0 0
56 unless defined $array;
57
58 0 ▶ $array = [$array] unless ref $array eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $array eq "ARRAY" 0 0 0
59
60 0 my $elements = $self->elements;
61 0 foreach my $value ( @{$array} ) {
62
63 0 ▶ $value = JavaScript::Code::Type->build( value => $value )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value 0 0 0
64 unless ref $value;
65
66 0 ▶ die "'$value' is not a 'JavaScript::Code::Value'."
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value and $value->isa("JavaScript::Code::Value") 0 0 0
Condition0%0/3
ref $value and $value->isa("JavaScript::Code::Value")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $value and $value->isa("JavaScript::Code::Value")
ref $value $value->isa("JavaScript::Code::Value")
Truth table0%0/3
A and B
A= ref $valueB= $value->isa("JavaScript::Code::Value")
ABresult
0X0
100
111
67 unless ref $value
68 and $value->isa('JavaScript::Code::Value');
69
70 0 foreach my $t (qw[ JavaScript::Code::Array JavaScript::Code::Hash ]) {
71 0 ▶ die "Can not add '$t'." if $value->isa($t);
Branch: 1 branch
BranchTrueFalseTotal
if $value->isa($t) 0 0 0
72 }
73
74 0 push @{$elements}, $value;
75 }
76
77 0 $self->elements($elements);
78
79 0 return $self;
80 }
81
82 =head2 $self->at( $index, < $value > )
83
84 Gets or sets the value on the given index.
85
86 Dies if the index is out of range.
87
88 =cut
89
90 0 ▶sub at {
Subroutine at: not called CC=6 SCAR=37.4
Pod documented
91 0 my $self = shift;
92 0 ▶ my $ndx = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
93
94 0 ▶ die "Out of range."
Branch: 1 branch
BranchTrueFalseTotal
if $ndx >= $self->length 0 0 0
95 if $ndx >= $self->length;
96
97 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
98 0 my $value = shift;
99
100 0 ▶ die "'$value' is not a 'JavaScript::Code::Value'."
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value and $value->isa("JavaScript::Code::Value") 0 0 0
Condition0%0/3
ref $value and $value->isa("JavaScript::Code::Value")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $value and $value->isa("JavaScript::Code::Value")
ref $value $value->isa("JavaScript::Code::Value")
Truth table0%0/3
A and B
A= ref $valueB= $value->isa("JavaScript::Code::Value")
ABresult
0X0
100
111
101 unless ref $value
102 and $value->isa('JavaScript::Code::Value');
103
104 0 $self->elements->[$ndx] = $value;
105
106 0 return $self;
107 }
108
109 0 return $self->elements->[$ndx];
110 }
111
112 =head2 $self->length( )
113
114 Returns the number of elements stored in the array.
115
116 =cut
117
118 0 ▶sub length {
Subroutine length: not called CC=1 SCAR=6.9
Pod documented
119 0 my ($self) = @_;
120
121 0 return scalar @{ $self->elements };
122 }
123
124 =head2 $self->type( )
125
126 =cut
127
128 0 ▶sub type {
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
129 0 return "Array";
130 }
131
132 =head2 $self->output( )
133
134 =cut
135
136 0 ▶sub output {
Subroutine output: not called CC=6 SCAR=37.4
Pod documented
137 0 my ($self) = @_;
138
139 0 my $output = 'new Array(';
140 0 ▶ unless ( $self->length ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->length) { } 0 0 0
141 0 ▶ my $size = $self->size || 0;
Condition0%0/2
$self->size || 0
l!l
00
MC/DC0%0/1
$self->size || 0
$self->size
Truth table0%0/2
A
A= $self->size
Aresult
11
00
142 0 ▶ $output .= $size if $size;
Branch: 1 branch
BranchTrueFalseTotal
if $size 0 0 0
143 }
144 else {
145
146 0 my $values = '';
147 0 foreach my $value ( @{ $self->elements } ) {
148
149 0 ▶ $values .= ', ' if $values;
Branch: 1 branch
BranchTrueFalseTotal
if $values 0 0 0
150 0 $values .= "$value";
151 }
152
153 0 $output .= $values;
154 }
155
156 0 $output .= ')';
157
158 0 return $output;
159 }
160
161 =head1 SEE ALSO
162
163 L<JavaScript::Code>
164
165 =head1 AUTHOR
166
167 Sascha Kiefer, C<esskar@cpan.org>
168
169 =head1 LICENSE
170
171 This library is free software, you can redistribute it and/or modify it under
172 the same terms as Perl itself.
173
174 =cut
175
176 2 1;
↑ Summary Code/Condition.pm »