Compress/Adapter/Lzf.pm

filter: Statementstmt 87.6% 71 / 81 Branchbran 57.1% 16 / 28 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 87.5% 14 / 16 Podpod 0.0% 0 / 10 totaltotal 71.0% 103 / 145 CC 17 SCAR 17.3
CC
17
Cov
77%
c_lzf_header_length
15.0
writeBlock
4.9
writeOneBlock
4.0
CRAP 5.6
« Uncompress/Adapter/Lzf.pm ↑ Summary Uncompress/UnLzf.pm »
1 package IO::Compress::Adapter::Lzf ;
2  
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 10 ▶use IO::Compress::Base::Common 2.217 qw(:Status);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use Compress::LZF ;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 10 our ($VERSION);
11 10 $VERSION = '2.217';
12  
13 10 ▶use constant SIGNATURE => 'ZV';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub mkCompObject
16 {
17 221 ▶ my $blocksize = shift ;
Subroutine mkCompObject: called CC=1 SCAR=0.0
Pod undocumented
18  
19 221 return bless {
20 'Buffer' => '',
21 'BlockSize' => $blocksize,
22 #'CRC' => ! $minimal,
23 'Error' => '',
24 'ErrorNo' => 0,
25 'CompBytes' => 0,
26 'UnCompBytes'=> 0,
27 } ;
28 }
29  
30 sub compr
31 {
32 227 ▶ my $self = shift ;
Subroutine compr: called CC=2 SCAR=7.0
Pod undocumented
33  
34 227 $self->{Buffer} .= ${ $_[0] } ;
35 return $self->writeBlock(\$_[1], 0)
36 227 ▶ if length $self->{Buffer} >= $self->{BlockSize} ;
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"Buffer"} >= $self->{"BlockSize"} 0 227 227
37  
38  
39 227 return STATUS_OK;
40 }
41  
42 sub flush
43 {
44 4 ▶ my $self = shift ;
Subroutine flush: called CC=2 SCAR=7.1
Pod undocumented
45  
46 return STATUS_OK
47 4 ▶ unless length $self->{Buffer};
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"Buffer"} 0 4 4
48  
49 4 return $self->writeBlock(\$_[0], 1);
50 }
51  
52 sub close
53 {
54 220 ▶ my $self = shift ;
Subroutine close: called CC=2 SCAR=6.9
Pod undocumented
55  
56 return STATUS_OK
57 220 ▶ unless length $self->{Buffer};
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"Buffer"} 72 148 220
58  
59 148 return $self->writeBlock(\$_[0], 1);
60 }
61  
62 sub writeBlock
63 {
64 152 ▶ my $self = shift;
Subroutine writeBlock: called CC=4 SCAR=16.0
Pod undocumented
65 152 my $flush = $_[1] ;
66 152 my $blockSize = $self->{BlockSize} ;
67  
68 152 ▶ while (length $self->{Buffer} >= $blockSize) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"Buffer"} >= $blockSize) 0 152 152
69 0 my $buff = substr($self->{Buffer}, 0, $blockSize);
70 0 substr($self->{Buffer}, 0, $blockSize) = '';
71 0 $self->writeOneBlock(\$buff, $_[0]);
72 }
73  
74 152 ▶ if ($flush && length $self->{Buffer} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flush and length $self->{"Buffer"}) 152 0 152
Condition33%1/3
$flush and length $self->{"Buffer"}
!ll&&!rl&&r
00152
MC/DC0%0/2
$flush and length $self->{"Buffer"}
$flush length $self->{"Buffer"}
Truth table33%1/3
A and B
A= $flushB= length $self->{"Buffer"}
ABresult
0X0
100
111
75 152 $self->writeOneBlock(\$self->{Buffer}, $_[0]);
76 152 $self->{Buffer} = '';
77 }
78  
79 152 return STATUS_OK;
80 }
81  
82 sub writeOneBlock
83 {
84 152 ▶ my $self = shift;
Subroutine writeOneBlock: called CC=4 SCAR=13.9
Pod undocumented
85 152 my $buff = shift;
86  
87 152 my $cmp ;
88  
89 152 eval { $cmp = Compress::LZF::compress($$buff) };
90  
91 152 ▶ return STATUS_ERROR
Branch: 1 branch
BranchTrueFalseTotal
if $@ or not defined $cmp 0 152 152
Condition33%1/3
$@ or not defined $cmp
l!l&&r!l&&!r
00152
MC/DC0%0/2
$@ or not defined $cmp
$@ not defined $cmp
Truth table33%1/3
A or not(B)
A= $@B= not defined $cmp
ABresult
1X1
011
000
92 if $@ || ! defined $cmp;
93  
94 152 ${ $_[0] } .= SIGNATURE ;
95  
96 #$self->{UnCompBytes} += length $self->{Buffer} ;
97 152 $self->{UnCompBytes} += length $$buff ;
98  
99 # Remove the Compress::LZF header
100 152 substr($cmp, 0, c_lzf_header_length($cmp)) = '';
101  
102 #if (length($cmp) >= length($self->{Buffer}))
103 152 ▶ if (length($cmp) >= length $$buff)
Branch: 1 branch
BranchTrueFalseTotal
if (length $cmp >= length $$buff) { } 67 85 152
104 {
105 67 ${ $_[0] } .= pack("Cn", 0, length($$buff));
106 67 ${ $_[0] } .= $$buff;
107 67 $self->{CompBytes} += length $$buff;
108 }
109 else {
110  
111 85 ${ $_[0] } .= pack("Cnn", 1, length($cmp), length($$buff));
112 85 ${ $_[0] } .= $cmp;
113 85 $self->{CompBytes} += length $cmp;
114 }
115 #$self->{Buffer} = '';
116  
117 152 return STATUS_OK;
118 }
119  
120 sub c_lzf_header_length
121 {
122 152 ▶ my $firstByte = unpack ("C", substr($_[0], 0, 1));
Subroutine c_lzf_header_length: called CC=8 SCAR=27.1
Pod undocumented
123  
124 152 ▶ return 1 if $firstByte == 0 ;
Branch: 1 branch
BranchTrueFalseTotal
if $firstByte == 0 67 85 152
125 85 ▶ return 1 unless $firstByte & 0x80 ;
Branch: 1 branch
BranchTrueFalseTotal
unless $firstByte & 128 12 73 85
126 73 ▶ return 2 unless $firstByte & 0x20 ;
Branch: 1 branch
BranchTrueFalseTotal
unless $firstByte & 32 45 28 73
127 28 ▶ return 3 unless $firstByte & 0x10 ;
Branch: 1 branch
BranchTrueFalseTotal
unless $firstByte & 16 28 0 28
128 0 ▶ return 4 unless $firstByte & 0x08 ;
Branch: 1 branch
BranchTrueFalseTotal
unless $firstByte & 8 0 0 0
129 0 ▶ return 5 unless $firstByte & 0x04 ;
Branch: 1 branch
BranchTrueFalseTotal
unless $firstByte & 4 0 0 0
130 0 ▶ return 6 unless $firstByte & 0x02 ;
Branch: 1 branch
BranchTrueFalseTotal
unless $firstByte & 2 0 0 0
131  
132 0 return undef;
133 }
134  
135 sub reset
136 {
137 0 ▶ return STATUS_OK;
Subroutine reset: not called CC=1 SCAR=6.9
Pod undocumented
138 }
139  
140 sub compressedBytes
141 {
142 0 ▶ my $self = shift ;
Subroutine compressedBytes: not called CC=1 SCAR=6.9
Pod undocumented
143 0 $self->{CompBytes};
144 }
145  
146 sub uncompressedBytes
147 {
148 220 ▶ my $self = shift ;
Subroutine uncompressedBytes: called CC=1 SCAR=0.0
Pod undocumented
149 220 $self->{UnCompBytes};
150 }
151  
152 10 1;
153  
154 __END__
« Uncompress/Adapter/Lzf.pm ↑ Summary Uncompress/UnLzf.pm »