lib/Archive/Lha/Header/Base.pm

filter: Statementstmt 87.6% 57 / 65 Branchbran 68.1% 15 / 22 Conditioncond 75.0% 12 / 16 MC/DCmcdc 50.0% 5 / 10 Subroutinesub 92.3% 12 / 13 Podpod 100% 3 / 3 totaltotal 80.6% 104 / 129 CC 19 SCAR 22.5
CC
19
Cov
82%
pathname
18.1
charset_for_os
5.0
import
2.0
CRAP 9.4
« lib/Archive/Lha/Stream.pm ↑ Summary lib/Archive/Lha/Decode/Base.pm »
1 package Archive::Lha::Header::Base;
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 File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 17 ▶use File::Spec::Unix;
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 124 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
10 124 my $class = shift;
11 124 my $caller = caller;
12
13 124 my @accessors = qw(
14 method header_top data_top next_header
15 encoded_size original_size crc16 timestamp os
16 );
17
18 {
19 17 ▶ no strict 'refs'; no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
20 124 foreach my $name ( @accessors ) {
21 1116 ▶ *{"$class\::$name"} = sub { shift->{$name} };
Subroutine __ANON__: called CC=1 SCAR=0.0
22 }
23 124 push @{"$caller\::ISA"}, $class;
24 }
25 }
26
27 # Map OS identifier to the most likely filename encoding used by that platform.
28 17 my %_os_charset = (
29 'a' => 'iso-8859-15', # Amiga
30 'M' => 'cp1252', # MS-DOS / Windows
31 'w' => 'cp1252', # WinNT / Win95
32 'U' => 'guess', # Unix (encoding varies: UTF-8 on modern, latin-1 on older)
33 'H' => 'cp932', # Human68K (Sharp X68000)
34 'J' => 'cp932', # Java VM (often used with Japanese archives)
35 'm' => 'UTF-8', # Macintosh (modern)
36 );
37
38 191 ▶sub charset_for_os {
Subroutine charset_for_os: called CC=5 SCAR=16.1
Pod documented
39 191 my ($self) = @_;
40 191 ▶ my $os_id = $self->{os} ? $self->{os}[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'os'} ? : 190 1 191
41 191 ▶ return $os_id && $os_id ne '?' ? ( $_os_charset{$os_id} // 'guess' ) : 'guess';
Branch: 1 branch
BranchTrueFalseTotal
$os_id && $os_id ne '?' ? : 189 2 191
Condition80%4/5
$os_id and $os_id ne "?"
!ll&&!rl&&r
11189
$_os_charset{$os_id} // "guess"
l!l
1890
MC/DC100%2/2
$os_id and $os_id ne "?"
$os_id $os_id ne "?"
MC/DC0%0/1
$_os_charset{$os_id} // "guess"
$_os_charset{$os_id}
Truth table100%3/3
A and B
A= $os_idB= $os_id ne "?"
ABresult
0X0
100
111
Truth table50%1/2
A
A= $_os_charset{$os_id}
Aresult
11
00
42 }
43
44 280 ▶sub pathname {
Subroutine pathname: called CC=14 SCAR=28.9
Pod documented
45 280 my ($self, $from, $to) = @_;
46 280 my $path;
47 280 ▶ if ( $self->{pathname} ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->{'pathname'}) { } 0 280 280
elsif ($self->{'directory'} and $self->{'filename'}) { } 266 14 280
elsif ($self->{'filename'}) { } 14 0 14
elsif ($self->{'directory'}) { } 0 0 0
48 0 $path = _conv_sep( $self->{pathname} );
49 }
50 ▶ elsif ( $self->{directory} && $self->{filename} ) {
Condition66%2/3
$self->{"directory"} and $self->{"filename"}
!ll&&!rl&&r
140266
MC/DC50%1/2
$self->{"directory"} and $self->{"filename"}
$self->{"directory"} $self->{"filename"}
Truth table66%2/3
A and B
A= $self->{"directory"}B= $self->{"filename"}
ABresult
0X0
100
111
51 $path = File::Spec::Unix->catfile(
52 _conv_sep( $self->{directory} ),
53 _conv_sep( $self->{filename} )
54 266 );
55 }
56 elsif ( $self->{filename} ) {
57 14 $path = _conv_sep( $self->{filename} );
58 }
59 elsif ( $self->{directory} ) {
60 0 $path = _conv_sep( $self->{directory} . '/' );
61 }
62
63 # avoid traversal
64 280 ▶ if ( File::Spec::Unix->file_name_is_absolute( $path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("File::Spec::Unix"->file_name_is_absolute($path)) 0 280 280
65 0 my ($vol, $dir, $file) = File::Spec::Unix->splitpath( $path );
66 0 $path = File::Spec::Unix->catfile( '.', $dir, $file );
67 }
68
69 # default from-encoding: auto-detect from OS field
70 280 ▶ $from //= $self->charset_for_os;
Condition66%2/3
$from //= $self->charset_for_os
l!l&&r!l&&!r
991810
MC/DC0%0/2
$from //= $self->charset_for_os
$from $self->charset_for_os
Truth table66%2/3
A //= B
A= $fromB= $self->charset_for_os
ABresult
1X1
011
000
71 280 ▶ $to //= 'UTF-8';
Condition100%2/2
$to //= "UTF-8"
l!l
22555
MC/DC100%1/1
$to //= "UTF-8"
$to
Truth table100%2/2
A
A= $to
Aresult
11
00
72
73 280 require Encode;
74 280 ▶ if ( lc $from eq 'guess' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (lc $from eq 'guess') { } 2 278 280
elsif (lc $from ne lc $to) { } 278 0 278
75 2 require Encode::Guess;
76 2 my $enc = Encode::Guess::guess_encoding(
77 $path => qw( latin1 latin2 cp932 euc-jp )
78 );
79 2 ▶ Encode::from_to( $path, ref($enc) ? $enc->name : 'latin1', $to );
Branch: 1 branch
BranchTrueFalseTotal
ref $enc ? : 2 0 2
80 }
81 elsif ( lc $from ne lc $to ) {
82 278 Encode::from_to( $path, $from, $to );
83 }
84
85 280 my $trailing_slash = $path =~ m{/$};
86 280 $path = File::Spec::Unix->canonpath( $path );
87 280 ▶ $path .= '/' if $trailing_slash && $path !~ m{/$};
Branch: 1 branch
BranchTrueFalseTotal
if $trailing_slash and not $path =~ m[/$] 2 278 280
Condition66%2/3
$trailing_slash and not $path =~ m[/$]
!ll&&!rl&&r
27802
MC/DC50%1/2
$trailing_slash and not $path =~ m[/$]
$trailing_slash not $path =~ m[/$]
Truth table66%2/3
A and not(B)
A= $trailing_slashB= not $path =~ m[/$]
ABresult
0X0
100
111
88 280 return $path;
89 }
90
91 0 ▶sub dirname {
Subroutine dirname: not called CC=1 SCAR=6.9
Pod documented
92 0 my $self = shift;
93 0 my $path = $self->pathname(@_);
94 0 require File::Basename;
95 0 return File::Basename::dirname( $path );
96 }
97
98 546 ▶sub _conv_sep {
Subroutine _conv_sep: called CC=1 SCAR=0.0
99 546 my $path = shift;
100
101 546 $path =~ s{\xff|\\}{/}g;
102 546 return $path;
103 }
104
105 17 1;
106
107 __END__
« lib/Archive/Lha/Stream.pm ↑ Summary lib/Archive/Lha/Decode/Base.pm »