lib/Archive/Lha/Header/Level0.pm

filter: Statementstmt 38.0% 19 / 50 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 38.2% 26 / 68 CC 6 SCAR 30.7
CC
6
Cov
32%
new
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 21.5
« tools/plha ↑ Summary lib/Archive/Lha/Header/Utils.pm »
1 package Archive::Lha::Header::Level0;
2  
3 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 17 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 17 ▶use Archive::Lha::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 17 ▶use Archive::Lha::Header::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 17 ▶use Archive::Lha::Header::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶sub new {
Subroutine new: not called CC=6 SCAR=37.4
Pod documented
11 0 my ($class, $stream) = @_;
12  
13 0 my $start = $stream->tell;
14 0 my $size = ord($stream->read(1)) + 2;
15  
16 0 ▶ croak "Header is broken: size is too small: $size" if $size < 24;
Branch: 1 branch
BranchTrueFalseTotal
if $size < 24 0 0 0
17  
18 0 $stream->seek($start);
19 0 my $buf = $stream->read($size);
20  
21 0 my $checksum = ord(substr($buf, 1, 1));
22 0 my $checksum1 = _checksum($buf, 2);
23 0 ▶ croak "Header is broken: pos:$start checksum $checksum/$checksum1"
Branch: 1 branch
BranchTrueFalseTotal
unless $checksum == $checksum1 0 0 0
24 unless $checksum == $checksum1;
25  
26 0 my %header;
27 0 $header{header_top} = $start;
28 0 $header{header_size} = $size;
29 0 $header{header_checksum} = $checksum;
30 0 $header{method} = substr($buf, 3, 3);
31 0 $header{encoded_size} = unpack 'V', substr($buf, 7, 4);
32 0 $header{original_size} = unpack 'V', substr($buf, 11, 4);
33 0 $header{timestamp} = unpack 'V', substr($buf, 15, 4);
34  
35 0 my $pathname_length = ord(substr($buf, 21, 1));
36 0 $header{pathname} = substr($buf, 22, $pathname_length);
37 0 ▶ if ($header{pathname} =~ s/\0(.+)//s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($header{"pathname"} =~ s/\0(.+)//s) 0 0 0
38 0 $header{comment} = $1;
39 }
40 0 $header{crc16} = unpack 'v', substr($buf, 22 + $pathname_length, 2);
41  
42 0 my $ext_from = 24 + $pathname_length;
43 0 ▶ if ($ext_from < $size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ext_from < $size) 0 0 0
44 0 my (undef, $ext) = _extended_header_buf($buf, $ext_from, $size - $ext_from);
45 0 ▶ %header = (%header, %{ $ext }) if %{ $ext };
Branch: 1 branch
BranchTrueFalseTotal
if %{$ext;} 0 0 0
46 }
47  
48 0 $header{data_top} = $start + $size;
49 0 $header{next_header} = $header{data_top} + $header{encoded_size};
50  
51 0 bless \%header, $class;
52 }
53  
54 17 1;
55  
56 __END__
« tools/plha ↑ Summary lib/Archive/Lha/Header/Utils.pm »