Typed/Array.pm

filter: Statementstmt 32.8% 21 / 64 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 31.5% 6 / 19 Podpod n/a totaltotal 29.6% 27 / 91 CC 5 SCAR 20.6
CC
5
Cov
29%
SPLICE
30.0
FETCHSIZE
2.0
STORESIZE
2.0
CRAP 7.8
« Typed.pm ↑ Summary Typed/Code.pm »
1 package Variable::Strongly::Typed::Array;
2  
3 8 ▶use version; $VERSION = qv('1.0.0');
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 8 ▶use base qw(Variable::Strongly::Typed);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 {
12 1 ▶ sub TIEARRAY {
Subroutine TIEARRAY: called CC=1 SCAR=0.0
13 1 my($class, $type) = @_;
14  
15 1 my $self = bless \my($anon_scalar), $class;
16 1 $self->_init([], $type);
17 }
18  
19 ### Bummer have to implement all the array functions...
20 0 ▶ sub FETCHSIZE {
Subroutine FETCHSIZE: not called CC=1 SCAR=6.9
21 0 my $arr = shift->_get_object;
22 0 return scalar @{$arr};
23 }
24  
25 0 ▶ sub STORESIZE {
Subroutine STORESIZE: not called CC=1 SCAR=6.9
26 0 my $arr = shift->_get_object;
27 0 $#{$arr} = $_[0]-1;
28 }
29  
30 0 ▶ sub STORE {
Subroutine STORE: not called CC=1 SCAR=6.9
31 0 my ($self, $index, $value) = @_;
32 0 my $arr = $self->_get_object;
33  
34 0 $self->_check_values($value);
35 0 $arr->[$index] = $value;
36 }
37  
38 # Note we don't currently check on the way out as
39 # Tie::Constrained does...
40 0 ▶ sub FETCH {
Subroutine FETCH: not called CC=1 SCAR=6.9
41 0 my $arr = shift->_get_object;
42 0 $arr->[$_[0]];
43 }
44  
45 0 ▶ sub CLEAR {
Subroutine CLEAR: not called CC=1 SCAR=6.9
46 0 my $arr = shift->_get_object;
47 0 @{$arr} = ();
48 }
49  
50 0 ▶ sub POP {
Subroutine POP: not called CC=1 SCAR=6.9
51 0 my $arr = shift->_get_object;
52 0 pop(@{$arr});
53 }
54  
55 0 ▶ sub PUSH {
Subroutine PUSH: not called CC=1 SCAR=6.9
56 0 my ($self, @values) = @_;
57 0 my $arr = $self->_get_object;
58  
59 0 $self->_check_values(@values);
60 0 push(@$arr, @values);
61 }
62  
63 0 ▶ sub SHIFT {
Subroutine SHIFT: not called CC=1 SCAR=6.9
64 0 my $arr = shift->_get_object;
65 0 shift(@{$arr});
66 }
67  
68 0 ▶ sub UNSHIFT {
Subroutine UNSHIFT: not called CC=1 SCAR=6.9
69 0 my ($self, @values) = @_;
70 0 my $arr = $self->_get_object;
71  
72 0 $self->_check_values(@values);
73 0 unshift(@$arr, @values);
74 }
75  
76 0 ▶ sub EXISTS {
Subroutine EXISTS: not called CC=1 SCAR=6.9
77 0 my $arr = shift->_get_object;
78 0 exists $arr->[$_[0]];
79 }
80  
81 0 ▶ sub DELETE {
Subroutine DELETE: not called CC=1 SCAR=6.9
82 0 my $arr = shift->_get_object;
83 0 delete $arr->[$_[0]];
84 }
85
86 0 ▶ sub SPLICE {
Subroutine SPLICE: not called CC=5 SCAR=34.0
87 0 my ($self) = shift;
88 0 my $arr = $self->_get_object;
89  
90 0 my $sz = $arr->FETCHSIZE;
91 0 ▶ my $off = @_ ? shift : 0;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
92 0 ▶ $off += $sz if $off < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $off < 0 0 0 0
93 0 ▶ my $len = @_ ? shift : $sz - $off;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
94  
95 0 ▶ $self->_check_values(@_) if (@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
96  
97 0 return splice(@$arr, $off, $len, @_);
98 }
99  
100 0 ▶ sub EXTEND {
Subroutine EXTEND: not called CC=1 SCAR=6.9
101 0 my ($self) = shift;
102 0 $self->STORESIZE(shift);
103 }
104 }
105  
106 8 1;
107  
108 __END__
« Typed.pm ↑ Summary Typed/Code.pm »