| 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
| |||||||||||||||||||||||||||||||||||||||
| 41 | 191 | ▶ | return $os_id && $os_id ne '?' ? ( $_os_charset{$os_id} // 'guess' ) : 'guess'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
$os_id and $os_id ne "?"
$_os_charset{$os_id} // "guess"
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 "?"
Truth table50%1/2
A
A= $_os_charset{$os_id}
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $path = _conv_sep( $self->{pathname} ); | |||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||
| 50 | ▶ | elsif ( $self->{directory} && $self->{filename} ) { | |||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"directory"} and $self->{"filename"}
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"}
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||
| 71 | 280 | ▶ | $to //= 'UTF-8'; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$to //= "UTF-8"
MC/DC100%1/1
$to //= "UTF-8"
$to
Truth table100%2/2
A
A= $to
| |||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||
| 73 | 280 | require Encode; | |||||||||||||||||||||||||||||||||||||
| 74 | 280 | ▶ | if ( lc $from eq 'guess' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$trailing_slash and not $path =~ m[/$]
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[/$]
| |||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||