blib/lib/Compress/Zlib/Perl.pm

filter: Statementstmt 93.4% 269 / 288 Branchbran 81.8% 90 / 110 Conditioncond 56.5% 13 / 23 MC/DCmcdc 46.6% 7 / 15 Subroutinesub 91.1% 31 / 34 Podpod 0.0% 0 / 23 totaltotal 83.1% 410 / 493 CC 73 SCAR 17.4
CC
73
Cov
88%
_crc16
20.0
stateReadType
14.6
make_huffman
8.0
CRAP 5.7
↑ Summary
1 package Compress::Zlib::Perl;
2  
3 1 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # use if $] > 5.006, 'warnings';
6 # use warnings;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 require Exporter;
10  
11 1 ▶use vars qw($VERSION @ISA @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 @ISA = qw(Exporter);
13  
14 # Items to export into callers namespace by default. Note: do not export
15 # names by default without a very good reason. Use EXPORT_OK instead.
16 # Do not simply export all your public functions/methods/constants.
17  
18 1 ▶use constant Z_OK => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use constant Z_STREAM_END => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use constant MAX_WBITS => 16;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 @EXPORT = qw(
23 Z_OK Z_STREAM_END MAX_WBITS crc32
24 );
25  
26 1 $VERSION = '0.02';
27  
28 {
29 1 my @crc32;
30  
31 1 ▶ sub _init_crc32 {
Subroutine _init_crc32: called CC=3 SCAR=11.0
32 # I'm not sure why Ton wanted to reverse the order of the bits in this
33 # constant, rather than using the bit-reversed constant
34 # my $p=oct reverse sprintf"%032bb0", 0x04C11DB7;
35 # But the only 5.005 friendly way I can find is this:
36 1 my $p
37 = unpack "I", pack "b*", scalar reverse unpack "b*", pack "I", 0x04C11DB7;
38 1 ▶ @crc32 = map{for my$s(0..7) {$_ = $_>>1 ^ ($_&1 && $p)} $_} 0..255;
Condition66%2/3
$_ & 1 && $p
!ll&&!rl&&r
102401024
MC/DC50%1/2
$_ & 1 && $p
$_ & 1 $p
Truth table66%2/3
A && B
A= $_ & 1B= $p
ABresult
0X0
100
111
39 }
40  
41 # Calculate gzip header 16 bit CRCs
42 0 ▶ sub _crc16 {
Subroutine _crc16: not called CC=4 SCAR=30.0
43 0 my $crc16 = shift;
44 0 ▶ _init_crc32() unless @crc32;
Branch: 1 branch
BranchTrueFalseTotal
unless @crc32 0 0 0
45 0 foreach my $input (@_) {
46 # I have no way to test this, as nothing that I can find generates
47 # gzip files with the header CRC.
48 # Ton's code is this:
49 $crc16 = $crc16>>8^$crc32[$crc16&0xff^ord(substr $input,$_,1)]
50 0 for 0..length($input)-1;
51 # I believe that the following is functionally equivalent, but should
52 # be faster:
53 # while ($input =~ /(.)/gs) {
54 # $crc16 = $crc16 >> 8 ^ $crc32[$crc16 & 0xff ^ ord $1];
55 # }
56 0 return $crc16;
57 }
58 }
59  
60 # Public interface starts here:
61  
62 # Calculate 32 bit CRCs
63 7411 ▶ sub crc32 {
Subroutine crc32: called CC=4 SCAR=13.9
Pod undocumented
64 7411 ▶ _init_crc32() unless @crc32;
Branch: 1 branch
BranchTrueFalseTotal
unless @crc32 1 7410 7411
65 7411 my ($buffer, $crc32) = @_;
66 7411 ▶ $crc32 ||= 0;
Condition50%1/2
$crc32 ||= 0
l!l
07411
MC/DC0%0/1
$crc32 ||= 0
$crc32
Truth table50%1/2
A
A= $crc32
Aresult
11
00
67 7411 $crc32 ^= 0xffffffff;
68 7411 my $pos = -length $buffer;
69 7411 ▶ $crc32 = $crc32>>8 ^ $crc32[$crc32&0xff^ord(substr($buffer, $pos++, 1))]
Branch: 1 branch
BranchTrueFalseTotal
$pos and do { $crc32 = $crc32 >> 8 ^ $crc32[$crc32 & 255 ^ ord substr($buffer, $pos++, 1)] } 85368 7411 92779
70 while $pos;
71 7411 $crc32 ^ 0xffffffff;
72 }
73 }
74  
75 1 ▶sub inflateInit {
Subroutine inflateInit: called CC=4 SCAR=15.0
Pod undocumented
76 8 my %args = @_;
77 die "Please specify negative window size"
78 8 ▶ unless $args{-WindowBits} && $args{-WindowBits} < 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"-WindowBits"} and $args{"-WindowBits"} < 0 0 8 8
Condition33%1/3
$args{"-WindowBits"} and $args{"-WindowBits"} < 0
!ll&&!rl&&r
008
MC/DC0%0/2
$args{"-WindowBits"} and $args{"-WindowBits"} < 0
$args{"-WindowBits"} $args{"-WindowBits"} < 0
Truth table33%1/3
A and B
A= $args{"-WindowBits"}B= $args{"-WindowBits"} < 0
ABresult
0X0
100
111
79 8 my $self = bless {isize=>0,
80 osize=>0,
81 result=>"",
82 huffman=>"",
83 type0length=>"",
84 state=>\&stateReadFinal
85 };
86 8 $self->_reset_bits_have;
87 8 ▶ wantarray ? ($self, Z_OK) : $self;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 8 0 8
88 }
89  
90 0 ▶sub total_in {
Subroutine total_in: not called CC=1 SCAR=6.9
Pod undocumented
91 0 $_[0]->{isize};
92 }
93  
94 0 ▶sub total_out {
Subroutine total_out: not called CC=1 SCAR=6.9
Pod undocumented
95 0 $_[0]->{osize};
96 }
97  
98 7403 ▶sub inflate {
Subroutine inflate: called CC=5 SCAR=16.2
Pod undocumented
99 7403 $_[0]->{input} = \$_[1];
100 7403 my ($return, $status);
101 7403 $_[0]->{izize} += length $_[1];
102 7403 ▶ if (&{$_[0]->{state}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (&{$_[0]{'state'};}) { } 8 7395 7403
103 # Finished, so flush everything
104 8 $return = length $_[0]->{result};
105 8 $status = Z_STREAM_END;
106 } else {
107 7395 ▶ die length ($_[1]) . " input remaining" if length $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if length $_[1] 0 7395 7395
108 7395 $return = length ($_[0]->{result}) - 0x8000;
109 7395 ▶ $return = 0 if $return < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $return < 0 7395 0 7395
110 7395 $status = Z_OK;
111 }
112 7403 $_[0]->{izize} -= length $_[1];
113 7403 $_[0]->{osize} += $return;
114 wantarray ? (substr ($_[0]->{result}, 0, $return, ""), $status)
115 7403 ▶ : substr ($_[0]->{result}, 0, $return, "");
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7403 0 7403
116 }
117  
118 # Public interface ends here
119  
120 16 ▶sub _reset_bits_have {
Subroutine _reset_bits_have: called CC=1 SCAR=0.0
121 16 my $self = shift;
122 16 $self->{val} = $self->{have} = 0;
123 }
124  
125  
126 # get arg bits (little endian)
127 6884 ▶sub _get_bits {
Subroutine _get_bits: called CC=3 SCAR=11.0
128 6884 my ($self, $want) = @_;
129 6884 my ($bits_val, $bits_have) = @{$self}{qw(val have)};
130 6884 ▶ while ($want > $bits_have) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want > $bits_have) 3600 6128 9728
131 # inlined input read
132 3600 my $byte = substr ${$_[0]->{input}}, 0, 1, "";
133 3600 ▶ if (!length $byte) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $byte) 756 2844 3600
134 756 @{$self}{qw(val have)} = ($bits_val, $bits_have);
135 756 return;
136 }
137 2844 $bits_val |= ord($byte) << $bits_have;
138 2844 $bits_have += 8;
139 }
140 6128 my $result = $bits_val & (1 << $want)-1;
141 6128 $bits_val >>= $want;
142 6128 $bits_have -= $want;
143 6128 @{$self}{qw(val have)} = ($bits_val, $bits_have);
144 6128 return $result;
145 }
146  
147 # Get one huffman code
148 12709 ▶sub _get_huffman {
Subroutine _get_huffman: called CC=5 SCAR=16.1
149 12709 my ($self, $code) = @_;
150 12709 $code = $self->{$code};
151 12709 my ($bits_val, $bits_have, $str) = @{$self}{qw(val have huffman)};
152 do {
153 55909 ▶ if (--$bits_have < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$bits_have < 0) 8537 47372 55909
154 # inlined input read
155 8537 my $byte = substr ${$_[0]->{input}}, 0, 1, "";
156 8537 ▶ if (!length $byte) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $byte) 1789 6748 8537
157 # bits_have is -1, but really should be zero, so fix in save
158 1789 @{$self}{qw(val have huffman)} = ($bits_val, 0, $str);
159 1789 return;
160 }
161 6748 $bits_val = ord $byte;
162 6748 $bits_have = 7;
163 }
164 54120 $str .= $bits_val & 1;
165 54120 $bits_val >>= 1;
166 12709 ▶ } until exists $code->{$str};
Branch: 1 branch
BranchTrueFalseTotal
exists $code->{$str} or do { do { if (--$bits_have < 0) { my $byte = substr(${$_[0]{"input"};}, 0, 1, ""); unless (length $byte) { @{$self;}{"val", "have", "huffman"} = ($bits_val, 0, $str); return; } ; $bits_val = ord $byte; $bits_have = 7; } ; $str .= ($bits_val & 1); $bits_val >>= 1 } } 10920 43200 54120
167 10920 ▶ defined($code->{$str}) || die "Bad code $str";
Branch: 1 branch
BranchTrueFalseTotal
defined $code->{$str} or die "Bad code $str" 10920 0 10920
168 10920 @{$self}{qw(val have huffman)} = ($bits_val, $bits_have, "");
169 10920 return $code->{$str};
170 }
171  
172 # construct huffman code
173 12 ▶sub make_huffman {
Subroutine make_huffman: called CC=8 SCAR=20.8
Pod undocumented
174 12 my $counts = shift;
175 12 my (%code, @counts);
176 12 push @{$counts[$counts->[$_]]}, $_ for 0..$#$counts;
177 12 my $value = 0;
178 12 my $bits = -1;
179 12 for (@counts) {
180 116 $value *= 2;
181 116 ▶ next unless ++$bits && $_;
Branch: 1 branch
BranchTrueFalseTotal
unless ++$bits and $_ 40 76 116
Condition100%3/3
++$bits and $_
!ll&&!rl&&r
122876
MC/DC100%2/2
++$bits and $_
++$bits $_
Truth table100%3/3
A and B
A= ++$bitsB= $_
ABresult
0X0
100
111
182 # Ton used sprintf"%0${bits}b", $value;
183 76 $code{reverse unpack "b$bits", pack "V", $value++} = $_ for @$_;
184 }
185 # Close the code to avoid infinite loops (and out of memory)
186 12 $code{reverse unpack "b$bits", pack "V", $value++} = undef for
187 $value .. (1 << $bits)-1;
188 12 ▶ @code{0, 1} = () unless %code;
Branch: 1 branch
BranchTrueFalseTotal
unless %code 0 12 12
189 12 return \%code;
190 }
191  
192 # Inflate state machine.
193 {
194 1 my ($static_lit_code, $static_dist_code, @lit_base, @dist_base);
195  
196 1 my @lit_extra = (-1,
197 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,
198 3,3,3,3,4,4,4,4,5,5,5,5,0,-2,-2);
199 1 my @dist_extra = (0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,
200 9,9,10,10,11,11,12,12,13,13,-1,-1);
201 1 my @alpha_map = (16, 17, 18, 0, 8, 7, 9, 6, 10,
202 5, 11, 4, 12, 3, 13, 2, 14, 1, 15);
203 1 ▶ sub prepare_tables {
Subroutine prepare_tables: called CC=5 SCAR=16.1
Pod undocumented
204 1 my $length = 3;
205 1 for (@lit_extra) {
206 32 push @lit_base, $length;
207 32 ▶ $length += 1 << $_ if $_ >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $_ >= 0 29 3 32
208 }
209 # Exceptional case
210 1 splice(@lit_base, -3, 3, 258);
211  
212 1 my $dist = 1;
213 1 for (@dist_extra) {
214 32 push @dist_base, $dist;
215 32 ▶ $dist += 1 << $_ if $_ >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $_ >= 0 30 2 32
216 }
217 1 splice(@dist_base, -2, 2);
218 }
219  
220 8 ▶ sub stateReadFinal {
Subroutine stateReadFinal: called CC=2 SCAR=7.2
Pod undocumented
221 8 my $bit = _get_bits($_[0], 1);
222 8 ▶ if (!defined $bit) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bit) 0 8 8
223 # STALL
224 0 return;
225 }
226 8 $_[0]->{final} = $bit;
227 8 goto &{$_[0]->{state} = \&stateReadType};
228 }
229 8 ▶ sub stateReadType {
Subroutine stateReadType: called CC=8 SCAR=26.8
Pod undocumented
230 8 my $type = _get_bits($_[0], 2);
231 8 ▶ if (!defined $type) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $type) 0 8 8
232 # STALL
233 0 return;
234 }
235 8 $_[0]->{type} = $type;
236 8 ▶ if ($type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) 4 4 8
237 4 ▶ prepare_tables() unless @lit_base;
Branch: 1 branch
BranchTrueFalseTotal
unless @lit_base 1 3 4
238 4 ▶ if ($type == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type == 1) { } 0 4 4
elsif ($type == 2) { } 4 0 4
239 0 ▶ $_[0]->{lit} = $static_lit_code ||=
Condition0%0/3
$static_lit_code ||= make_huffman([(8) x 144, (9) x 112, (7) x 24, (8) x 8])
l!l&&r!l&&!r
000
MC/DC0%0/2
$static_lit_code ||= make_huffman([(8) x 144, (9) x 112, (7) x 24, (8) x 8])
$static_lit_code make_huffman([(8) x 144, (9) x 112, (7) x 24, (8) x 8])
Truth table0%0/3
A ||= B
A= $static_lit_codeB= make_huffman([(8) x 144, (9) x 112, (7) x 24, (8) x 8])
ABresult
1X1
011
000
240 make_huffman([(8)x144,(9)x112, (7)x24, (8)x8]);
241 0 ▶ $_[0]->{dist} = $static_dist_code ||=
Condition0%0/3
$static_dist_code ||= make_huffman([(5) x 32])
l!l&&r!l&&!r
000
MC/DC0%0/2
$static_dist_code ||= make_huffman([(5) x 32])
$static_dist_code make_huffman([(5) x 32])
Truth table0%0/3
A ||= B
A= $static_dist_codeB= make_huffman([(5) x 32])
ABresult
1X1
011
000
242 make_huffman([(5)x32]);
243 # This is the main inflation loop.
244 0 goto &{$_[0]->{state} = \&stateReadLit};
245 } elsif ($type == 2) {
246 4 goto &{$_[0]->{state} = \&stateReadHLit};
247 } else {
248 0 die "deflate subtype $type not supported\n";
249 }
250 }
251 4 goto &{$_[0]->{state} = \&stateReadUncompressedLen};
252 }
253  
254 8 ▶ sub stateReadUncompressedLen {
Subroutine stateReadUncompressedLen: called CC=3 SCAR=11.0
Pod undocumented
255 # Not compressed;
256 8 $_[0]->_reset_bits_have;
257 # inlined input read
258 $_[0]->{type0length}
259 8 .= substr ${$_[0]->{input}}, 0, 4 - length $_[0]->{type0length}, "";
260 8 ▶ if (length $_[0]->{type0length} < 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_[0]{"type0length"} < 4) 4 4 8
261 # STALL
262 4 return;
263 }
264 4 my ($len, $nlen) = unpack("vv", $_[0]->{type0length});
265 4 $_[0]->{type0length} = "";
266 4 ▶ $len == (~$nlen & 0xffff) ||
Branch: 1 branch
BranchTrueFalseTotal
$len == (~$nlen & 65535) or die "$len is not the 1-complement of $nlen" 4 0 4
267 die "$len is not the 1-complement of $nlen";
268 4 $_[0]->{type0left} = $len;
269 4 goto &{$_[0]->{state} = \&stateReadUncompressed};
270 }
271  
272 4850 ▶ sub stateReadUncompressed {
Subroutine stateReadUncompressed: called CC=3 SCAR=11.3
Pod undocumented
273 # inlined input read
274 4850 my $got = substr ${$_[0]->{input}}, 0, $_[0]->{type0left}, "";
275 4850 $_[0]->{result} .= $got;
276 4850 ▶ if ($_[0]->{type0left} -= length $got) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"type0left"} -= length $got) 4846 4 4850
277 # Still need more.
278 # STALL
279 4846 return;
280 }
281 4 ▶ if ($_[0]->{final}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"final"}) 4 0 4
282 # Finished.
283 4 return 1;
284 }
285 # Begin the next block
286 0 goto &{$_[0]->{state} = \&stateReadFinal};
287 }
288  
289 4 ▶ sub stateReadHLit {
Subroutine stateReadHLit: called CC=2 SCAR=7.2
Pod undocumented
290 4 my $hlit = _get_bits($_[0], 5);
291 4 ▶ if (!defined $hlit) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $hlit) 0 4 4
292 # STALL
293 0 return;
294 }
295 4 $_[0]->{hlit} = $hlit + 257;
296 4 goto &{$_[0]->{state} = \&stateReadHDist};
297 }
298 5 ▶ sub stateReadHDist {
Subroutine stateReadHDist: called CC=2 SCAR=6.9
Pod undocumented
299 5 my $hdist = _get_bits($_[0], 5);
300 5 ▶ if (!defined $hdist) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $hdist) 1 4 5
301 # STALL
302 1 return;
303 }
304 4 $_[0]->{hdist} = $hdist + 1;
305 4 goto &{$_[0]->{state} = \&stateReadHCLen};
306 }
307 5 ▶ sub stateReadHCLen {
Subroutine stateReadHCLen: called CC=2 SCAR=6.9
Pod undocumented
308 5 my $hclen = _get_bits($_[0], 4);
309 5 ▶ if (!defined $hclen) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $hclen) 1 4 5
310 # STALL
311 1 return;
312 }
313 4 $_[0]->{alphaleft} = $_[0]->{hclen} = $hclen + 4;
314 # Determine the code length huffman code
315 4 $_[0]->{alpha_raw} = [(0) x @alpha_map];
316  
317 4 goto &{$_[0]->{state} = \&stateReadAlphaCode};
318 }
319 9 ▶ sub stateReadAlphaCode {
Subroutine stateReadAlphaCode: called CC=3 SCAR=11.0
Pod undocumented
320 9 my $alpha_code = $_[0]->{alpha_raw};
321 9 ▶ while ($_[0]->{alphaleft}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"alphaleft"}) 61 4 65
322 61 my $code = _get_bits($_[0], 3);
323 61 ▶ if (!defined $code) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code) 5 56 61
324 # STALL
325 5 return;
326 }
327 # my $where = $_[0]->{hclen} - $_[0]->{alphaleft};
328 56 $alpha_code->[$alpha_map[$_[0]->{hclen} - $_[0]->{alphaleft}--]] = $code;
329 }
330 4 $_[0]->{alpha} = make_huffman($alpha_code);
331 4 delete $_[0]->{alpha_raw};
332  
333 # Get lit/length and distance tables
334 4 $_[0]->{code_len} = [];
335 4 goto &{$_[0]->{state} = \&stateBuildAlphaCode};
336 }
337  
338 89 ▶ sub stateBuildAlphaCode {
Subroutine stateBuildAlphaCode: called CC=7 SCAR=19.5
Pod undocumented
339 89 my $code_len = $_[0]->{code_len};
340 89 ▶ while (@$code_len < $_[0]->{hlit}+$_[0]->{hdist}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$code_len < $_[0]{"hlit"} + $_[0]{"hdist"}) 565 4 569
341 565 my $alpha = _get_huffman($_[0], 'alpha');
342 565 ▶ if (!defined $alpha) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $alpha) 57 508 565
343 # STALL
344 57 return;
345 }
346 508 ▶ if ($alpha < 16) {
Branch: 3 branches
BranchTrueFalseTotal
if ($alpha < 16) { } 480 28 508
elsif ($alpha == 16) { } 4 24 28
elsif ($alpha == 17) { } 16 8 24
347 480 push @$code_len, $alpha;
348 } elsif ($alpha == 16) {
349 4 goto &{$_[0]->{state} = \&stateReadAlphaCode16};
350 } elsif ($alpha == 17) {
351 16 goto &{$_[0]->{state} = \&stateReadAlphaCode17};
352 } else {
353 8 goto &{$_[0]->{state} = \&stateReadAlphaCodeOther};
354 }
355 }
356 4 ▶ @$code_len == $_[0]->{hlit}+$_[0]->{hdist} || die "too many codes";
Branch: 1 branch
BranchTrueFalseTotal
@$code_len == $_[0]{"hlit"} + $_[0]{"hdist"} or die "too many codes" 4 0 4
357 4 my @lit_len = splice(@$code_len, 0, $_[0]->{hlit});
358 4 $_[0]->{lit} = make_huffman(\@lit_len);
359 4 $_[0]->{dist} = make_huffman($code_len);
360 4 delete $_[0]->{code_len};
361 4 goto &{$_[0]->{state} = \&stateReadLit};
362 }
363  
364 5 ▶ sub stateReadAlphaCode16 {
Subroutine stateReadAlphaCode16: called CC=2 SCAR=6.9
Pod undocumented
365 5 my $code_len = $_[0]->{code_len};
366 5 my $bits = _get_bits($_[0], 2);
367 5 ▶ if (!defined $bits) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bits) 1 4 5
368 # STALL
369 1 return;
370 }
371 4 push @$code_len, ($code_len->[-1]) x (3+$bits);
372 4 goto &{$_[0]->{state} = \&stateBuildAlphaCode};
373 }
374  
375 19 ▶ sub stateReadAlphaCode17 {
Subroutine stateReadAlphaCode17: called CC=2 SCAR=6.9
Pod undocumented
376 19 my $code_len = $_[0]->{code_len};
377 19 my $bits = _get_bits($_[0], 3);
378 19 ▶ if (!defined $bits) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bits) 3 16 19
379 # STALL
380 3 return;
381 }
382 16 push @$code_len, (0) x (3+$bits);
383 16 goto &{$_[0]->{state} = \&stateBuildAlphaCode};
384 }
385  
386 10 ▶ sub stateReadAlphaCodeOther {
Subroutine stateReadAlphaCodeOther: called CC=2 SCAR=6.9
Pod undocumented
387 10 my $code_len = $_[0]->{code_len};
388 10 my $bits = _get_bits($_[0], 7);
389 10 ▶ if (!defined $bits) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bits) 2 8 10
390 # STALL
391 2 return;
392 }
393 8 push @$code_len, (0) x (11+$bits);
394 8 goto &{$_[0]->{state} = \&stateBuildAlphaCode};
395 }
396  
397 4318 ▶ sub stateReadLit {
Subroutine stateReadLit: called CC=6 SCAR=18.2
Pod undocumented
398 4318 while (1) {
399 8710 my $lit = _get_huffman($_[0], 'lit');
400 8710 ▶ if (!defined $lit) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $lit) 1306 7404 8710
401 # STALL
402 1306 return;
403 }
404 7404 ▶ if ($lit >= 256) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lit >= 256) 3012 4392 7404
405 3012 ▶ if ($lit_extra[$lit -= 256] < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lit_extra[$lit -= 256] < 0) 4 3008 3012
406 4 ▶ die "Invalid literal code" if $lit;
Branch: 1 branch
BranchTrueFalseTotal
if $lit 0 4 4
407  
408 4 ▶ if ($_[0]->{final}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"final"}) 4 0 4
409 # Finished.
410 4 return 1;
411 }
412 # Begin the next block
413 0 goto &{$_[0]->{state} = \&stateReadFinal};
414 }
415 3008 $_[0]->{litcode} = $lit;
416 # BREAK
417 3008 goto &{$_[0]->{state} = \&stateGetLength};
418 }
419  
420 4392 $_[0]->{result} .= chr $lit;
421 # Back to the main inflation loop
422 # goto &stateReadLit;
423 # ie loop
424 }
425 }
426  
427 3030 ▶ sub stateGetLength {
Subroutine stateGetLength: called CC=3 SCAR=11.0
Pod undocumented
428 3030 my $lit = $_[0]->{litcode};
429 3030 my $bits = _get_bits($_[0], $lit_extra[$lit]);
430 3030 ▶ if (!defined $bits) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bits) 22 3008 3030
431 # STALL
432 22 return;
433 }
434 3008 ▶ $_[0]->{length} = $lit_base[$lit] + ($lit_extra[$lit] && $bits);
Condition100%3/3
$lit_extra[$lit] && $bits
!ll&&!rl&&r
2564216228
MC/DC100%2/2
$lit_extra[$lit] && $bits
$lit_extra[$lit] $bits
Truth table100%3/3
A && B
A= $lit_extra[$lit]B= $bits
ABresult
0X0
100
111
435 3008 goto &{$_[0]->{state} = \&stateGetDCode};
436 }
437  
438 3434 ▶ sub stateGetDCode {
Subroutine stateGetDCode: called CC=2 SCAR=6.9
Pod undocumented
439 3434 my $d = _get_huffman($_[0], 'dist');
440 3434 ▶ if (!defined $d) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $d) 426 3008 3434
441 # STALL
442 426 return;
443 }
444 3008 $_[0]->{dcode} = $d;
445 3008 goto &{$_[0]->{state} = \&stateGetDistDecompress};
446 }
447  
448 3729 ▶ sub stateGetDistDecompress {
Subroutine stateGetDistDecompress: called CC=7 SCAR=19.5
Pod undocumented
449 3729 my $d = $_[0]->{dcode};
450 3729 ▶ die "Invalid distance code" if $d >= 30;
Branch: 1 branch
BranchTrueFalseTotal
if $d >= 30 0 3729 3729
451 3729 my $bits = _get_bits($_[0], $dist_extra[$d]);
452 3729 ▶ if (!defined $bits) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bits) 721 3008 3729
453 # STALL
454 721 return;
455 }
456 3008 ▶ my $dist = $dist_base[$d] + ($dist_extra[$d] && $bits);
Condition100%3/3
$dist_extra[$d] && $bits
!ll&&!rl&&r
8362964
MC/DC100%2/2
$dist_extra[$d] && $bits
$dist_extra[$d] $bits
Truth table100%3/3
A && B
A= $dist_extra[$d]B= $bits
ABresult
0X0
100
111
457  
458 # Go for it
459 3008 my $length = $_[0]->{length};
460 3008 ▶ if ($dist >= $length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist >= $length) { } 3004 4 3008
461 3004 my $section = substr ($_[0]->{result}, -$dist, $length);
462 3004 $_[0]->{result} .= $section;
463 } else {
464 4 my $remaining = $length;
465 4 ▶ while ($remaining) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remaining) 12 4 16
466 12 ▶ my $take
Branch: 1 branch
BranchTrueFalseTotal
$dist >= $remaining ? : 4 8 12
467 = $dist >= $remaining ? $remaining : $dist;
468 12 $_[0]->{result} .= substr($_[0]->{result}, -$dist, $take);
469 12 $remaining -= $take;
470 }
471 }
472 # Back to the main inflation loop
473 3008 goto &{$_[0]->{state} = \&stateReadLit};
474 }
475 }
476  
477 1 1;
478 __END__
↑ Summary