blib/lib/Tie/Array/PackedC.pm

filter: Statementstmt 64.5% 162 / 251 Branchbran 39.2% 33 / 84 Conditioncond 33.3% 4 / 12 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 62.3% 38 / 61 Podpod 83.3% 5 / 6 totaltotal 57.8% 243 / 420 CC 47 SCAR 19.2
CC
47
Cov
57%
import
27.1
import
22.3
TIEARRAY
6.7
CRAP 6.8
↑ Summary
1 package Tie::Array::PackedC;
2 1 ▶use constant ALLOC=>1024;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use constant PACK=>'l!*';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use constant NULL=>pack PACK,"";
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use constant SIZE=>length NULL;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use base qw(Tie::Array);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 our $DEBUG;
11  
12 2 ▶sub import {
Subroutine import: called CC=10 SCAR=31.1
13 2 ▶ if (@_>1 and $_[1]=~/[A-Z]/ and $_[0] eq __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1 and $_[1] =~ /[A-Z]/ and $_[0] eq __PACKAGE__) { } 1 1 2
Condition66%4/6
@_ > 1 and $_[1] =~ /[A-Z]/ and $_[0] eq __PACKAGE__
!ll&&!rl&&r
101
@_ > 1 and $_[1] =~ /[A-Z]/
!ll&&!rl&&r
011
MC/DC33%1/3
@_ > 1 and $_[1] =~ /[A-Z]/ and $_[0] eq __PACKAGE__
@_ > 1 $_[1] =~ /[A-Z]/ $_[0] eq __PACKAGE__
Truth table50%2/4
A and B and C
A= @_ > 1B= $_[1] =~ /[A-Z]/C= $_[0] eq __PACKAGE__
ABCresult
0XX0
10X0
1100
1111
14 1 my ($class,$name,$format,%args)=@_;
15 1 ▶ $format.="*" unless $format=~/\*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $format =~ /\*$/ 1 0 1
16 1 my $new=$class."::".$name;
17 1 ▶ open my $f,"<",__FILE__ or die __FILE__ . "$!";
Branch: 1 branch
BranchTrueFalseTotal
open my $f, "<", __FILE__ or die '/home/cpancover/.cpan/build/Tie-Array-PackedC-0.03-0/blib/lib/Tie/Array/PackedC.pm' . "$!" 1 0 1
18 1 local $_=do {local $/="\n__END__\n"; scalar <$f>};
19 1 close $f;
20 1 s/(?<=package )\w+(::\w+)*;/$new;/;
21 1 s/(?<=PACK)\s*=>'.+';/=>'$format';/;
22 1 ▶ s/(?<=ALLOC)\s*=>.+;/=>$args{ALLOC};/ if $args{ALLOC};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"ALLOC"} 0 1 1
23 1 ▶ s/(?<=SIZE)\s*=>.+;/=>$args{SIZE};/ if $args{SIZE};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"SIZE"} 0 1 1
24 0 ▶ eval "no warnings; $_";
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine CLEAR: not called CC=1 SCAR=1.6
Subroutine DELETE: called CC=2 SCAR=9.9
Subroutine DESTROY: called CC=1 SCAR=1.6
Subroutine EXISTS: called CC=1 SCAR=1.6
Subroutine EXTEND: not called CC=1 SCAR=1.6
Subroutine FETCH: called CC=2 SCAR=9.9
Subroutine FETCHSIZE: called CC=1 SCAR=1.6
Subroutine POP: not called CC=2 SCAR=9.9
Subroutine PUSH: not called CC=3 SCAR=15.1
Subroutine SHIFT: not called CC=2 SCAR=9.9
Subroutine STORE: called CC=3 SCAR=15.1
Subroutine STORESIZE: not called CC=1 SCAR=1.6
Subroutine TIEARRAY: called CC=4 SCAR=19.1
Subroutine UNSHIFT: not called CC=1 SCAR=1.6
Subroutine _alloc: called CC=3 SCAR=15.1
Subroutine hex_dump: not called CC=2 SCAR=9.9
Subroutine import: not called CC=10 SCAR=33.0
Subroutine packed_array: called CC=1 SCAR=1.6
Subroutine packed_array_string: not called CC=1 SCAR=1.6
Subroutine reallen: not called CC=1 SCAR=1.6
Subroutine string: not called CC=1 SCAR=1.6
Subroutine trim: not called CC=1 SCAR=1.6
Branch: 21 branches
BranchTrueFalseTotal
unless $o < $count{$s} 0 1 1
if $o >= $count{$s} 0 22 22
length $$s ? : 0 0 0
unless @args 0 0 0
if (($count{$s} + @args) * 8 > length $$s) { } 0 0 0
length $$s ? : 0 0 0
if length $$s < ($o + 1) * 8 0 1 1
if $count{$s} <= $o 0 1 1
@_ > 1 ? : 1 0 1
unless defined $$strref 1 0 1
length($$strref) % 8 and Carp::confess("Initialized with bad string length! Expecting multiples of @{[8];} bytes,\ngot @{[length($$strref) % 8];} bytes extra.\n") 0 1 1
if $size < $count{$self} 0 1 1
if $Tie::Array::PackedC::Double::DEBUG 0 1 1
if ($ofs < @words) 0 0 0
if (@_ > 1 and $_[1] =~ /[A-Z]/ and $_[0] eq __PACKAGE__) { } 0 0 0
unless $format =~ /\*$/ 0 0 0
open my $f, "<", __FILE__ or die '(eval 51)[/home/cpancover/.cpan/build/Tie-Array-PackedC-0.03-0/blib/lib/Tie/Array/PackedC.pm:24]' . "$!" 0 0 0
if $args{"ALLOC"} 0 0 0
if $args{"SIZE"} 0 0 0
if $args{"DEBUG"} 0 0 0
$@ and die "Failed to build package $new!\n$@\n$_" 0 0 0
Condition0%0/6
@_ > 1 and $_[1] =~ /[A-Z]/ and $_[0] eq __PACKAGE__
!ll&&!rl&&r
000
@_ > 1 and $_[1] =~ /[A-Z]/
!ll&&!rl&&r
000
MC/DC0%0/3
@_ > 1 and $_[1] =~ /[A-Z]/ and $_[0] eq __PACKAGE__
@_ > 1 $_[1] =~ /[A-Z]/ $_[0] eq __PACKAGE__
Truth table0%0/4
A and B and C
A= @_ > 1B= $_[1] =~ /[A-Z]/C= $_[0] eq __PACKAGE__
ABCresult
0XX0
10X0
1100
1111
25 1 ▶ warn $_ if $args{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"DEBUG"} 0 1 1
26 1 ▶ $@ and die "Failed to build package $new!\n$@\n$_"
Branch: 1 branch
BranchTrueFalseTotal
$@ and die "Failed to build package $new!\n$@\n$_" 0 1 1
27 } else {
28 1 __PACKAGE__->export_to_level(1,@_);
29 }
30 }
31  
32  
33 1 our @ISA=qw(Exporter);
34 1 our $VERSION=0.03;
35 1 our @EXPORT_OK=qw(packed_array packed_array_string $DEBUG);
36  
37 1 my %count;
38 my %type;
39  
40 1 ▶sub packed_array {
Subroutine packed_array: called CC=1 SCAR=0.0
Pod documented
41 1 my (@a,$s);
42 1 tie @a,__PACKAGE__,$s,@_;
43 1 return \@a;
44 }
45  
46 0 ▶sub packed_array_string {
Subroutine packed_array_string: not called CC=1 SCAR=6.9
Pod documented
47 0 my @a;
48 0 tie @a,__PACKAGE__,@_;
49 0 return \@a;
50 }
51  
52  
53 1 ▶sub string { return substr ${$_[0]},0,$count{$_[0]}*SIZE };
Subroutine string: called CC=1 SCAR=0.0
Pod documented
54  
55 1 ▶sub trim {
Subroutine trim: called CC=1 SCAR=0.0
Pod documented
56 #printf STDERR "%d %d %d\n",$count{$_[0]},$count{$_[0]}*SIZE,length(${$_[0]});
57 1 substr ${$_[0]}, $count{$_[0]}*SIZE, length(${$_[0]}) - ($count{$_[0]}*SIZE), "";
58 1 return $_[0];
59 }
60  
61 0 ▶sub reallen { return $count{$_[0]}*SIZE };
Subroutine reallen: not called CC=1 SCAR=6.9
Pod undocumented
62  
63 0 ▶sub hex_dump {
Subroutine hex_dump: not called CC=2 SCAR=17.9
Pod documented
64 0 my @words=map { sprintf "%02x " x SIZE,unpack "C*",pack PACK,$_; } unpack PACK,${$_[0]};
65 0 ▶ for (my $ofs=0;$ofs<@words;$ofs+=4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ofs < @words) 0 0 0
66 0 printf "#%4d : %5d : %s\n",$ofs,$ofs*SIZE,join"| ",grep defined $_,@words[$ofs..$ofs+3]
67 }
68 }
69  
70  
71 2 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
72 2 my $self=shift;
73 2 delete $count{$self};
74 2 delete $type{$self};
75 }
76  
77 3 ▶sub _alloc {
Subroutine _alloc: called CC=3 SCAR=11.0
78 3 my ($self,$size)=@_;
79 3 ▶ return if $size<$count{$self};
Branch: 1 branch
BranchTrueFalseTotal
if $size < $count{$self} 1 2 3
80 2 my $before=length($$self);
81 2 $count{$self}=$size;
82 2 my $alloc=int ($size * 1.2);
83 2 $alloc+=ALLOC - ($alloc % ALLOC);
84 2 $$self.=NULL x ( $alloc - length($$self)/SIZE );
85 2 my $after=length($$self);
86 2 ▶ warn "Resize. Reallen:".$self->reallen()." Len: $before -> $after\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Tie::Array::PackedC::DEBUG 0 2 2
87 2 $self;
88 }
89  
90  
91 2 ▶sub TIEARRAY {
Subroutine TIEARRAY: called CC=4 SCAR=14.7
92 2 my ($class,$str,@args)=@_;
93 0 ▶ my $strref=@_>1 ? \$_[1] : \do{my $x};
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 2 0 2
94 2 ▶ $$strref="" unless defined $$strref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$strref 1 1 2
95 2 my $self=bless $strref,$class;
96  
97  
98 2 ▶ length($$strref) % SIZE and Carp::confess <<BAD_LENGTH;
Branch: 1 branch
BranchTrueFalseTotal
length($$strref) % 8 and Carp::confess("Initialized with bad string length! Expecting multiples of @{[8];} bytes,\ngot @{[length($$strref) % 8];} bytes extra.\n") 0 2 2
99 0 Initialized with bad string length! Expecting multiples of @{[SIZE]} bytes,
100 0 got @{[length($$strref) % SIZE]} bytes extra.
101 BAD_LENGTH
102 2 $count{$self}=int length($$strref)/SIZE;
103 #preallocate a chunk of memory
104 2 $self->_alloc(scalar @args);
105 2 substr($$self,0,@args*SIZE,pack(PACK,@args));
106 2 $self;
107 }
108  
109 42 ▶sub FETCH {
Subroutine FETCH: called CC=2 SCAR=6.9
110 42 my ($s,$o)=@_;
111 42 ▶ return undef if $o>=$count{$s};
Branch: 1 branch
BranchTrueFalseTotal
if $o >= $count{$s} 1 41 42
112 41 return unpack(PACK,substr($$s,$o * SIZE,SIZE));
113 }
114  
115 2 ▶sub STORE {
Subroutine STORE: called CC=3 SCAR=11.0
116 2 my ($s,$o,$v)=@_;
117 2 ▶ $s->_alloc($o+1) if length($$s)<($o+1)*SIZE;
Branch: 1 branch
BranchTrueFalseTotal
if length $$s < ($o + 1) * 8 1 1 2
118 2 ▶ $count{$s}=$o+1 if $count{$s}<=$o;
Branch: 1 branch
BranchTrueFalseTotal
if $count{$s} <= $o 1 1 2
119 2 substr($$s,$o * SIZE,SIZE)=pack(PACK,$v);
120 2 $v
121 }
122  
123 6 ▶sub FETCHSIZE {$count{shift(@_)}}
Subroutine FETCHSIZE: called CC=1 SCAR=0.0
124  
125 0 ▶sub STORESIZE {
Subroutine STORESIZE: not called CC=1 SCAR=6.9
126 0 my ($s,$l)=@_;
127 #print "STORESIZE $l\n";
128 0 $s->_alloc($l+1);
129 0 substr($$s,int($l*SIZE/ALLOC+1)*ALLOC)='';
130 0 $s
131 }
132  
133 0 ▶sub EXTEND {
Subroutine EXTEND: not called CC=1 SCAR=6.9
134 0 my ($s,$l)=@_;
135 0 $s->STORESIZE($l);
136 }
137  
138 1 ▶sub POP{
Subroutine POP: called CC=2 SCAR=7.2
139 1 my ($s)=@_;
140 1 ▶ length($$s) ? unpack PACK,substr($$s,--$count{$s}*SIZE,SIZE,NULL) : undef
Branch: 1 branch
BranchTrueFalseTotal
length $$s ? : 1 0 1
141 }
142  
143 1 ▶sub PUSH{
Subroutine PUSH: called CC=3 SCAR=11.6
144 1 my ($s,@args)=@_;
145 1 ▶ return unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 1 1
146 1 my $tail=$count{$s}*SIZE;
147 1 ▶ if (($count{$s}+@args)*SIZE>length($$s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (($count{$s} + @args) * 8 > length $$s) { } 0 1 1
148 0 $s->_alloc($count{$s}+@args);
149 } else {
150 1 $count{$s}+=@args;
151 }
152 1 substr($$s,$tail,@args*SIZE)=pack(PACK,@args);
153  
154 }
155  
156 0 ▶sub CLEAR { ${$_[0]}=NULL x (ALLOC/SIZE); $count{$_[0]}=0 }
Subroutine CLEAR: not called CC=1 SCAR=6.9
157  
158 0 ▶sub SHIFT {
Subroutine SHIFT: not called CC=2 SCAR=17.9
159 0 my ($s)=@_;
160 0 ▶ length($$s) ? unpack PACK,substr($$s,0,SIZE,'') : undef
Branch: 1 branch
BranchTrueFalseTotal
length $$s ? : 0 0 0
161 }
162 0 ▶sub UNSHIFT {
Subroutine UNSHIFT: not called CC=1 SCAR=6.9
163 0 my ($s,@args)=@_;
164 0 $$s=pack(PACK,@args).$$s;
165 }
166  
167 0 ▶sub EXISTS { $_[1] < $count{$_[0]} }
Subroutine EXISTS: not called CC=1 SCAR=6.9
168 0 ▶sub DELETE {
Subroutine DELETE: not called CC=2 SCAR=17.9
169 0 my ($s,$o)=@_;
170 0 ▶ return unless $o < $count{$s};
Branch: 1 branch
BranchTrueFalseTotal
unless $o < $count{$s} 0 0 0
171 0 my $v=unpack PACK,substr($$s,$o * SIZE,SIZE);
172 0 substr($$s,$o * SIZE,SIZE,NULL);
173 0 return $v
174 }
175  
176 #sub SPLICE {
177 #
178 #}
179  
180 1 1;
181  
182  
183 __END__
↑ Summary