| 1 | package Zuzu::Module::Archive; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | our $VERSION = '0.007002'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Archive::Tar (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Archive::Zip qw( :ERROR_CODES ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use File::Basename qw( basename ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use File::Temp qw( tempfile ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use IO::Compress::Bzip2 qw( bzip2 $Bzip2Error ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use IO::Compress::Gzip qw( gzip $GzipError ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use IO::Uncompress::Bunzip2 qw( bunzip2 $Bunzip2Error ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use IO::Uncompress::Gunzip qw( gunzip $GunzipError ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Zuzu::Error; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use Zuzu::Util::NativeHelpers qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | native_class | ||||||||||||||||||||||||||||||||||||||||||
| 20 | native_function | ||||||||||||||||||||||||||||||||||||||||||
| 21 | perl_to_zuzu | ||||||||||||||||||||||||||||||||||||||||||
| 22 | zuzu_to_perl | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use Zuzu::Value::BinaryString; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub _type_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_type_name: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | return 'Null' if not defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | return 'BinaryString' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
builtin::blessed($value)
$value->isa("Zuzu::Value::BinaryString")
Truth table0%0/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::BinaryString")
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | if blessed($value) and $value->isa('Zuzu::Value::BinaryString'); | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | return 'Array' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($value) and $value->isa("Zuzu::Value::Array")
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Zuzu::Value::Array")
builtin::blessed($value)
$value->isa("Zuzu::Value::Array")
Truth table0%0/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::Array")
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | if blessed($value) and $value->isa('Zuzu::Value::Array'); | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | return 'Dict' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($value) and $value->isa("Zuzu::Value::Dict")
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Zuzu::Value::Dict")
builtin::blessed($value)
$value->isa("Zuzu::Value::Dict")
Truth table0%0/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::Dict")
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | if blessed($value) and $value->isa('Zuzu::Value::Dict'); | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | return 'Object' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($value) and $value->isa("Zuzu::Value::Object")
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Zuzu::Value::Object")
builtin::blessed($value)
$value->isa("Zuzu::Value::Object")
Truth table0%0/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::Object")
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | if blessed($value) and $value->isa('Zuzu::Value::Object'); | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | return 'String'; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub _error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my ( $message ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | die Zuzu::Error->new_runtime( | |||||||||||||||||||||||||||||||||||||||||
| 45 | message => $message, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | file => '<std/archive>', | ||||||||||||||||||||||||||||||||||||||||||
| 47 | line => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub _assert_binary_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_binary_string: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my ( $value, $label ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | return $value->bytes | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
builtin::blessed($value)
$value->isa("Zuzu::Value::BinaryString")
Truth table0%0/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::BinaryString")
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | if blessed($value) and $value->isa('Zuzu::Value::BinaryString'); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $type = _type_name( $value ); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | _error( "TypeException: $label expects BinaryString, got $type" ); | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub _path_tiny_from_object { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_path_tiny_from_object: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my ( $path_obj, $method_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
builtin::blessed($path_obj) and $path_obj->isa("Zuzu::Value::Object") and exists $path_obj->slots->{"_path_tiny"}
builtin::blessed($path_obj) and $path_obj->isa("Zuzu::Value::Object")
MC/DC0%0/3
builtin::blessed($path_obj) and $path_obj->isa("Zuzu::Value::Object") and exists $path_obj->slots->{"_path_tiny"}
builtin::blessed($path_obj)
$path_obj->isa("Zuzu::Value::Object")
exists $path_obj->slots->{"_path_tiny"}
Truth table0%0/4
A and B and C
A= builtin::blessed($path_obj)B= $path_obj->isa("Zuzu::Value::Object")C= exists $path_obj->slots->{"_path_tiny"}
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | blessed($path_obj) | ||||||||||||||||||||||||||||||||||||||||||
| 66 | and $path_obj->isa('Zuzu::Value::Object') | ||||||||||||||||||||||||||||||||||||||||||
| 67 | and exists $path_obj->slots->{_path_tiny} | ||||||||||||||||||||||||||||||||||||||||||
| 68 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | return $path_obj->slots->{_path_tiny}; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( ref($path_obj) eq 'HASH' and exists $path_obj->{_path_tiny} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $path_obj eq "HASH" and exists $path_obj->{"_path_tiny"}
MC/DC0%0/2
ref $path_obj eq "HASH" and exists $path_obj->{"_path_tiny"}
ref $path_obj eq "HASH"
exists $path_obj->{"_path_tiny"}
Truth table0%0/3
A and B
A= ref $path_obj eq "HASH"B= exists $path_obj->{"_path_tiny"}
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | return $path_obj->{_path_tiny}; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | _error( "TypeException: $method_name expects Path as first argument" ); | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub _normalize_format { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_format: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my ( $raw ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | return 'auto' if !defined $raw or $raw eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $raw or $raw eq ""
MC/DC0%0/2
not defined $raw or $raw eq ""
not defined $raw
$raw eq ""
Truth table0%0/3
not(A) or B
A= not defined $rawB= $raw eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $format = lc "$raw"; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $format =~ s/\A\.//; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my %map = ( | |||||||||||||||||||||||||||||||||||||||||
| 86 | auto => 'auto', | ||||||||||||||||||||||||||||||||||||||||||
| 87 | zip => 'zip', | ||||||||||||||||||||||||||||||||||||||||||
| 88 | tar => 'tar', | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 'tar.gz' => 'tar.gz', | ||||||||||||||||||||||||||||||||||||||||||
| 90 | tgz => 'tar.gz', | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 'gzip+tar' => 'tar.gz', | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 'tar.bz2' => 'tar.bz2', | ||||||||||||||||||||||||||||||||||||||||||
| 93 | tbz => 'tar.bz2', | ||||||||||||||||||||||||||||||||||||||||||
| 94 | tbz2 => 'tar.bz2', | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 'bzip2+tar' => 'tar.bz2', | ||||||||||||||||||||||||||||||||||||||||||
| 96 | gz => 'gz', | ||||||||||||||||||||||||||||||||||||||||||
| 97 | gzip => 'gz', | ||||||||||||||||||||||||||||||||||||||||||
| 98 | bz2 => 'bz2', | ||||||||||||||||||||||||||||||||||||||||||
| 99 | bzip2 => 'bz2', | ||||||||||||||||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | return $map{$format} if exists $map{$format}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | _error( "Unsupported archive format '$raw'" ); | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub _format_from_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_format_from_name: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my ( $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | return undef if !defined $name or $name eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $name or $name eq ""
MC/DC0%0/2
not defined $name or $name eq ""
not defined $name
$name eq ""
Truth table0%0/3
not(A) or B
A= not defined $nameB= $name eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $lower = lc "$name"; | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | return 'tar.gz' if $lower =~ /\.tar\.gz\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | return 'tar.gz' if $lower =~ /\.tgz\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | return 'tar.bz2' if $lower =~ /\.tar\.bz2\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | return 'tar.bz2' if $lower =~ /\.tbz2?\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | return 'zip' if $lower =~ /\.zip\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | return 'tar' if $lower =~ /\.tar\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | return 'gz' if $lower =~ /\.gz\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | return 'bz2' if $lower =~ /\.bz2\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub _looks_like_tar { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_looks_like_tar: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my ( $bytes ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | return 0 if !defined $bytes or length($bytes) < 512; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $bytes or length $bytes < 512
MC/DC0%0/2
not defined $bytes or length $bytes < 512
not defined $bytes
length $bytes < 512
Truth table0%0/3
not(A) or B
A= not defined $bytesB= length $bytes < 512
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | return 1 if substr( $bytes, 257, 5 ) eq 'ustar'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub _gunzip_bytes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gunzip_bytes: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my ( $bytes ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | gunzip( \$bytes => \$out ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | or _error( "Archive decode failed: $GunzipError" ); | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub _bunzip2_bytes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bunzip2_bytes: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my ( $bytes ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | bunzip2( \$bytes => \$out ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | or _error( "Archive decode failed: $Bunzip2Error" ); | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub _detect_format_from_bytes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_detect_format_from_bytes: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my ( $bytes ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | if ( substr( $bytes, 0, 4 ) =~ /\APK[\x03\x05\x07][\x04\x06\x08]/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | return 'zip'; | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if ( substr( $bytes, 0, 2 ) eq "\x1f\x8b" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $raw = _gunzip_bytes($bytes); | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | return _looks_like_tar( $raw ) ? 'tar.gz' : 'gz'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | if ( substr( $bytes, 0, 3 ) eq 'BZh' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | my $raw = _bunzip2_bytes($bytes); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | return _looks_like_tar( $raw ) ? 'tar.bz2' : 'bz2'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if ( _looks_like_tar($bytes) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | return 'tar'; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | _error( 'Could not detect archive format from bytes' ); | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | sub _read_all_bytes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_all_bytes: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | my ( $path_tiny ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | return $path_tiny->slurp; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | sub _write_all_bytes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_all_bytes: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | my ( $path_tiny, $bytes ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $path_tiny->spew( $bytes ); | |||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub _archive_to_zuzu { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_archive_to_zuzu: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my ( $format, $entries ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | return perl_to_zuzu( | |||||||||||||||||||||||||||||||||||||||||
| 190 | { | ||||||||||||||||||||||||||||||||||||||||||
| 191 | format => $format, | ||||||||||||||||||||||||||||||||||||||||||
| 192 | entries => $entries, | ||||||||||||||||||||||||||||||||||||||||||
| 193 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 194 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | sub _entry_data_bytes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_entry_data_bytes: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | my ( $entry, $label ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if ( exists $entry->{data_value} and defined $entry->{data_value} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $entry->{"data_value"} and defined $entry->{"data_value"}
MC/DC0%0/2
exists $entry->{"data_value"} and defined $entry->{"data_value"}
exists $entry->{"data_value"}
defined $entry->{"data_value"}
Truth table0%0/3
A and B
A= exists $entry->{"data_value"}B= defined $entry->{"data_value"}
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | return _assert_binary_string( | ||||||||||||||||||||||||||||||||||||||||||
| 202 | $entry->{data_value}, | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | "$label.data", | |||||||||||||||||||||||||||||||||||||||||
| 204 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if ( exists $entry->{data_from_path} and defined $entry->{data_from_path} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $entry->{"data_from_path"} and defined $entry->{"data_from_path"}
MC/DC0%0/2
exists $entry->{"data_from_path"} and defined $entry->{"data_from_path"}
exists $entry->{"data_from_path"}
defined $entry->{"data_from_path"}
Truth table0%0/3
A and B
A= exists $entry->{"data_from_path"}B= defined $entry->{"data_from_path"}
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my $path_tiny = $entry->{data_from_path}; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | return $path_tiny->slurp; | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | _error( "TypeException: $label expects BinaryString data or Path data_from" ); | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | sub _entries_from_archive_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_entries_from_archive_value: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my ( $archive_value, $label ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | my $archive = zuzu_to_perl($archive_value); | |||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | _error( "TypeException: $label expects Dict archive, got " . _type_name( $archive_value ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | if ref($archive) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my $entries = $archive->{entries}; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | _error( "TypeException: $label expects archive.entries to be an Array" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | if ref($entries) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my @out; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | for my $idx ( 0 .. $#{ $entries } ) { | |||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | my $entry = $entries->[$idx]; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | _error( "TypeException: $label expects archive.entries[$idx] to be a Dict" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | if ref($entry) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | my $path = exists $entry->{path} | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | ? ( defined $entry->{path} ? "$entry->{path}" : undef ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | : undef; | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my %normalized = ( | |||||||||||||||||||||||||||||||||||||||||
| 236 | path => $path, | ||||||||||||||||||||||||||||||||||||||||||
| 237 | label => "$label archive.entries[$idx]", | ||||||||||||||||||||||||||||||||||||||||||
| 238 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | if ( exists $entry->{data} and defined $entry->{data} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
exists $entry->{"data"} and defined $entry->{"data"}
MC/DC0%0/2
exists $entry->{"data"} and defined $entry->{"data"}
exists $entry->{"data"}
defined $entry->{"data"}
Truth table0%0/3
A and B
A= exists $entry->{"data"}B= defined $entry->{"data"}
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $normalized{data_value} = $entry->{data}; | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | ▶ | elsif ( exists $entry->{data_from} and defined $entry->{data_from} ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
exists $entry->{"data_from"} and defined $entry->{"data_from"}
MC/DC0%0/2
exists $entry->{"data_from"} and defined $entry->{"data_from"}
exists $entry->{"data_from"}
defined $entry->{"data_from"}
Truth table0%0/3
A and B
A= exists $entry->{"data_from"}B= defined $entry->{"data_from"}
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | $normalized{data_from_path} = _path_tiny_from_object( | ||||||||||||||||||||||||||||||||||||||||||
| 244 | $entry->{data_from}, | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | "$label archive.entries[$idx].data_from", | |||||||||||||||||||||||||||||||||||||||||
| 246 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | _error( "TypeException: $label archive.entries[$idx] expects BinaryString data or Path data_from" ); | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | push @out, \%normalized; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 256 | \@out, | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | _normalize_format( $archive->{format} ), | |||||||||||||||||||||||||||||||||||||||||
| 258 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | sub _encode_tar { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_tar: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | my ( $entries, $format ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my $tar = Archive::Tar->new; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | for my $entry ( @{ $entries } ) { | |||||||||||||||||||||||||||||||||||||||||
| 266 | _error( 'Archive.encode requires path for tar entries' ) | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if !defined $entry->{path} or $entry->{path} eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $entry->{"path"} or $entry->{"path"} eq ""
MC/DC0%0/2
not defined $entry->{"path"} or $entry->{"path"} eq ""
not defined $entry->{"path"}
$entry->{"path"} eq ""
Truth table0%0/3
not(A) or B
A= not defined $entry->{"path"}B= $entry->{"path"} eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | $tar->add_data( | ||||||||||||||||||||||||||||||||||||||||||
| 269 | $entry->{path}, | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | _entry_data_bytes( $entry, $entry->{label} ), | |||||||||||||||||||||||||||||||||||||||||
| 271 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my ( $fh, $filename ) = tempfile( UNLINK => 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | my $compress = 0; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | $compress = Archive::Tar::COMPRESS_GZIP() if $format eq 'tar.gz'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | $compress = Archive::Tar::COMPRESS_BZIP() if $format eq 'tar.bz2'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | my $ok = $tar->write( $filename, $compress ); | |||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | _error( 'Archive encode failed while writing tar data' ) if !$ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | open my $in, '<:raw', $filename | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | or _error( "Archive encode failed while reopening '$filename': $!" ); | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | local $/; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my $bytes = <$in>; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | close $in; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | unlink $filename; | |||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | sub _decode_tar { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_tar: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | my ( $bytes, $format ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my ( $fh, $filename ) = tempfile( UNLINK => 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | binmode $fh; | |||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | print {$fh} $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | my $compress = 0; | |||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | $compress = Archive::Tar::COMPRESS_GZIP() if $format eq 'tar.gz'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | $compress = Archive::Tar::COMPRESS_BZIP() if $format eq 'tar.bz2'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | my $tar = Archive::Tar->new; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | my $ok = $tar->read( $filename, $compress ); | |||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my $err = $Archive::Tar::error; | |||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | unlink $filename; | |||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | _error( "Archive decode failed: $err" ) if !$ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my @entries; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | for my $member ( $tar->get_files ) { | |||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | next if $member->is_dir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | next if !$member->is_file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | push @entries, { | |||||||||||||||||||||||||||||||||||||||||
| 316 | path => $member->full_path, | ||||||||||||||||||||||||||||||||||||||||||
| 317 | data => Zuzu::Value::BinaryString->new( | ||||||||||||||||||||||||||||||||||||||||||
| 318 | bytes => $member->get_content, | ||||||||||||||||||||||||||||||||||||||||||
| 319 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 320 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | return \@entries; | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | sub _encode_zip { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_zip: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my ( $entries ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $zip = Archive::Zip->new; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | for my $entry ( @{ $entries } ) { | |||||||||||||||||||||||||||||||||||||||||
| 331 | _error( 'Archive.encode requires path for zip entries' ) | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | if !defined $entry->{path} or $entry->{path} eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $entry->{"path"} or $entry->{"path"} eq ""
MC/DC0%0/2
not defined $entry->{"path"} or $entry->{"path"} eq ""
not defined $entry->{"path"}
$entry->{"path"} eq ""
Truth table0%0/3
not(A) or B
A= not defined $entry->{"path"}B= $entry->{"path"} eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | $zip->addString( | ||||||||||||||||||||||||||||||||||||||||||
| 334 | _entry_data_bytes( $entry, $entry->{label} ), | ||||||||||||||||||||||||||||||||||||||||||
| 335 | $entry->{path}, | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my ( $fh, $filename ) = tempfile( | |||||||||||||||||||||||||||||||||||||||||
| 340 | SUFFIX => '.zip', | ||||||||||||||||||||||||||||||||||||||||||
| 341 | UNLINK => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 342 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | my $status = $zip->writeToFileNamed($filename); | |||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | _error( 'Archive encode failed while writing zip data' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | if $status != AZ_OK; | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | open my $in, '<:raw', $filename | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | or _error( "Archive encode failed while reopening '$filename': $!" ); | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | local $/; | |||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | my $bytes = <$in>; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | close $in; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | unlink $filename; | |||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | sub _decode_zip { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_zip: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my ( $bytes ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | my ( $fh, $filename ) = tempfile( | |||||||||||||||||||||||||||||||||||||||||
| 363 | SUFFIX => '.zip', | ||||||||||||||||||||||||||||||||||||||||||
| 364 | UNLINK => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 365 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | binmode $fh; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | print {$fh} $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | my $zip = Archive::Zip->new; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | my $status = $zip->read($filename); | |||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | _error( 'Archive decode failed while reading zip data' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | if $status != AZ_OK; | ||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | my @entries; | |||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | for my $member ( $zip->members ) { | |||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | next if $member->isDirectory; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | push @entries, { | |||||||||||||||||||||||||||||||||||||||||
| 379 | path => $member->fileName, | ||||||||||||||||||||||||||||||||||||||||||
| 380 | data => Zuzu::Value::BinaryString->new( | ||||||||||||||||||||||||||||||||||||||||||
| 381 | bytes => scalar $member->contents, | ||||||||||||||||||||||||||||||||||||||||||
| 382 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 383 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | unlink $filename; | |||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | return \@entries; | |||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | sub _encode_gzip_like { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_gzip_like: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | my ( $entries, $format ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | _error( "Archive.encode with format '$format' expects exactly one entry" ) | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | if scalar @{ $entries } != 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my $entry = $entries->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | my $bytes = ''; | |||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | if ( $format eq 'gz' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | my %opts; | |||||||||||||||||||||||||||||||||||||||||
| 400 | $opts{Name} = $entry->{path} | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | if defined $entry->{path} and $entry->{path} ne ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $entry->{"path"} and $entry->{"path"} ne ""
MC/DC0%0/2
defined $entry->{"path"} and $entry->{"path"} ne ""
defined $entry->{"path"}
$entry->{"path"} ne ""
Truth table0%0/3
A and B
A= defined $entry->{"path"}B= $entry->{"path"} ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | my $input = _entry_data_bytes( $entry, $entry->{label} ); | |||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | gzip( \$input => \$bytes, %opts ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | or _error( "Archive encode failed: $GzipError" ); | ||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | my $input = _entry_data_bytes( $entry, $entry->{label} ); | |||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | bzip2( \$input => \$bytes ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | or _error( "Archive encode failed: $Bzip2Error" ); | ||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | sub _decode_gzip_like { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_gzip_like: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | my ( $bytes, $format, $default_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | my $content; | |||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | my $path = $default_name; | |||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | if ( $format eq 'gz' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | my $gunzip = IO::Uncompress::Gunzip->new( \$bytes ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | or _error( "Archive decode failed: $GunzipError" ); | ||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | while ( my $read = $gunzip->read( my $chunk ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $out .= $chunk; | |||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | _error( "Archive decode failed: $GunzipError" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $gunzip or $gunzip->error
MC/DC0%0/2
not defined $gunzip or $gunzip->error
not defined $gunzip
$gunzip->error
Truth table0%0/3
not(A) or B
A= not defined $gunzipB= $gunzip->error
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | if !defined $gunzip or $gunzip->error; | ||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | my $info = $gunzip->getHeaderInfo; | |||||||||||||||||||||||||||||||||||||||||
| 431 | $path = $info->{Name} | ||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | if defined $info and defined $info->{Name} and $info->{Name} ne ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $info and defined $info->{"Name"} and $info->{"Name"} ne ""
defined $info and defined $info->{"Name"}
MC/DC0%0/3
defined $info and defined $info->{"Name"} and $info->{"Name"} ne ""
defined $info
defined $info->{"Name"}
$info->{"Name"} ne ""
Truth table0%0/4
A and B and C
A= defined $infoB= defined $info->{"Name"}C= $info->{"Name"} ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $content = $out; | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | $content = _bunzip2_bytes($bytes); | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | return [ | ||||||||||||||||||||||||||||||||||||||||||
| 440 | { | ||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | path => $path, | |||||||||||||||||||||||||||||||||||||||||
| 442 | data => Zuzu::Value::BinaryString->new( bytes => $content ), | ||||||||||||||||||||||||||||||||||||||||||
| 443 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 444 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | sub _derive_single_entry_name_from_path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_derive_single_entry_name_from_path: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | my ( $path_tiny, $format ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | my $name = basename( $path_tiny->stringify ); | |||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | ▶ | return undef if !defined $name or $name eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $name or $name eq ""
MC/DC0%0/2
not defined $name or $name eq ""
not defined $name
$name eq ""
Truth table0%0/3
not(A) or B
A= not defined $nameB= $name eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | if ( $format eq 'gz' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | $name =~ s/\.(?:gz|gzip)\z//i; | |||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||
| 456 | elsif ( $format eq 'bz2' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | $name =~ s/\.bz2\z//i; | |||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | return $name; | |||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | sub _resolve_format_for_encode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_format_for_encode: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | my ( $path_name, $archive_format, $given_format ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | my $path_format = _format_from_name($path_name); | |||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | my $format = _normalize_format($given_format); | |||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | $format = $archive_format if $format eq 'auto' and $archive_format ne 'auto'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$format eq "auto" and $archive_format ne "auto"
MC/DC0%0/2
$format eq "auto" and $archive_format ne "auto"
$format eq "auto"
$archive_format ne "auto"
Truth table0%0/3
A and B
A= $format eq "auto"B= $archive_format ne "auto"
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | $format = $path_format if $format eq 'auto' and defined $path_format; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$format eq "auto" and defined $path_format
MC/DC0%0/2
$format eq "auto" and defined $path_format
$format eq "auto"
defined $path_format
Truth table0%0/3
A and B
A= $format eq "auto"B= defined $path_format
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | _error( 'Archive format is required when it cannot be inferred from path' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | if $format eq 'auto'; | ||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | return $format; | |||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | 4 | ▶ | sub IMPORT { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
IMPORT: called CC=1 SCAR=6.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | 4 | my ( $class, $runtime ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | 4 | my $archive_class = native_class( | |||||||||||||||||||||||||||||||||||||||||
| 480 | name => 'Archive', | ||||||||||||||||||||||||||||||||||||||||||
| 481 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | $archive_class->static_methods->{decode} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 484 | name => 'decode', | ||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | my ( $class_value, $bytes_value, $format_value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | my $bytes = _assert_binary_string( $bytes_value, 'Archive.decode' ); | |||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | my $format = _normalize_format($format_value); | |||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | $format = _detect_format_from_bytes($bytes) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | if $format eq 'auto'; | ||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | my $entries; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | if ( $format eq 'zip' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | $entries = _decode_zip($bytes); | |||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||
| 496 | ▶ | elsif ( $format eq 'tar' or $format eq 'tar.gz' or $format eq 'tar.bz2' ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$format eq "tar" or $format eq "tar.gz" or $format eq "tar.bz2"
$format eq "tar" or $format eq "tar.gz"
MC/DC0%0/3
$format eq "tar" or $format eq "tar.gz" or $format eq "tar.bz2"
$format eq "tar"
$format eq "tar.gz"
$format eq "tar.bz2"
Truth table0%0/4
A or B or C
A= $format eq "tar"B= $format eq "tar.gz"C= $format eq "tar.bz2"
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | $entries = _decode_tar( $bytes, $format ); | |||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 499 | ▶ | elsif ( $format eq 'gz' or $format eq 'bz2' ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$format eq "gz" or $format eq "bz2"
MC/DC0%0/2
$format eq "gz" or $format eq "bz2"
$format eq "gz"
$format eq "bz2"
Truth table0%0/3
A or B
A= $format eq "gz"B= $format eq "bz2"
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | $entries = _decode_gzip_like( $bytes, $format, undef ); | |||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||
| 502 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | _error( "Unsupported archive format '$format'" ); | |||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | return _archive_to_zuzu( $format, $entries ); | |||||||||||||||||||||||||||||||||||||||||
| 507 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 508 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | $archive_class->static_methods->{encode} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 511 | name => 'encode', | ||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | my ( $class_value, $archive_value, $format_value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | my ( $entries, $archive_format ) = _entries_from_archive_value( | |||||||||||||||||||||||||||||||||||||||||
| 515 | $archive_value, | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 'Archive.encode', | ||||||||||||||||||||||||||||||||||||||||||
| 517 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | my $format = _normalize_format($format_value); | |||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | $format = $archive_format | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$format eq "auto" and $archive_format ne "auto"
MC/DC0%0/2
$format eq "auto" and $archive_format ne "auto"
$format eq "auto"
$archive_format ne "auto"
Truth table0%0/3
A and B
A= $format eq "auto"B= $archive_format ne "auto"
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | if $format eq 'auto' and $archive_format ne 'auto'; | ||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | ▶ | _error( 'Archive.encode requires an explicit format' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 522 | if $format eq 'auto'; | ||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | my $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | ▶ | if ( $format eq 'zip' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | $bytes = _encode_zip($entries); | |||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||
| 528 | ▶ | elsif ( $format eq 'tar' or $format eq 'tar.gz' or $format eq 'tar.bz2' ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$format eq "tar" or $format eq "tar.gz" or $format eq "tar.bz2"
$format eq "tar" or $format eq "tar.gz"
MC/DC0%0/3
$format eq "tar" or $format eq "tar.gz" or $format eq "tar.bz2"
$format eq "tar"
$format eq "tar.gz"
$format eq "tar.bz2"
Truth table0%0/4
A or B or C
A= $format eq "tar"B= $format eq "tar.gz"C= $format eq "tar.bz2"
| |||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | $bytes = _encode_tar( $entries, $format ); | |||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||
| 531 | ▶ | elsif ( $format eq 'gz' or $format eq 'bz2' ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$format eq "gz" or $format eq "bz2"
MC/DC0%0/2
$format eq "gz" or $format eq "bz2"
$format eq "gz"
$format eq "bz2"
Truth table0%0/3
A or B
A= $format eq "gz"B= $format eq "bz2"
| |||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | $bytes = _encode_gzip_like( $entries, $format ); | |||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||
| 534 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | _error( "Unsupported archive format '$format'" ); | |||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | return Zuzu::Value::BinaryString->new( bytes => $bytes ); | |||||||||||||||||||||||||||||||||||||||||
| 539 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 540 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | $archive_class->static_methods->{load} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 543 | name => 'load', | ||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | my ( $class_value, $path_obj, $format_value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | $runtime->assert_capability( | |||||||||||||||||||||||||||||||||||||||||
| 547 | 'fs', | ||||||||||||||||||||||||||||||||||||||||||
| 548 | 'Archive.load is denied by runtime policy', | ||||||||||||||||||||||||||||||||||||||||||
| 549 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | my $path_tiny = _path_tiny_from_object( $path_obj, 'Archive.load' ); | |||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | my $format = _normalize_format($format_value); | |||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | my $path_name = $path_tiny->stringify; | |||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | ▶ | $format = _format_from_name($path_name) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | if $format eq 'auto'; | ||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | my $bytes = _read_all_bytes($path_tiny); | |||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | ▶ | $format = _detect_format_from_bytes($bytes) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $format or $format eq "auto"
MC/DC0%0/2
not defined $format or $format eq "auto"
not defined $format
$format eq "auto"
Truth table0%0/3
not(A) or B
A= not defined $formatB= $format eq "auto"
| |||||||||||||||||||||||||||||||||||||||||||
| 557 | if !defined $format or $format eq 'auto'; | ||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | my $entries; | |||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | ▶ | if ( $format eq 'zip' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | $entries = _decode_zip($bytes); | |||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||
| 563 | ▶ | elsif ( $format eq 'tar' or $format eq 'tar.gz' or $format eq 'tar.bz2' ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$format eq "tar" or $format eq "tar.gz" or $format eq "tar.bz2"
$format eq "tar" or $format eq "tar.gz"
MC/DC0%0/3
$format eq "tar" or $format eq "tar.gz" or $format eq "tar.bz2"
$format eq "tar"
$format eq "tar.gz"
$format eq "tar.bz2"
Truth table0%0/4
A or B or C
A= $format eq "tar"B= $format eq "tar.gz"C= $format eq "tar.bz2"
| |||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | $entries = _decode_tar( $bytes, $format ); | |||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||
| 566 | ▶ | elsif ( $format eq 'gz' or $format eq 'bz2' ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$format eq "gz" or $format eq "bz2"
MC/DC0%0/2
$format eq "gz" or $format eq "bz2"
$format eq "gz"
$format eq "bz2"
Truth table0%0/3
A or B
A= $format eq "gz"B= $format eq "bz2"
| |||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | my $default_name = _derive_single_entry_name_from_path( | |||||||||||||||||||||||||||||||||||||||||
| 568 | $path_tiny, | ||||||||||||||||||||||||||||||||||||||||||
| 569 | $format, | ||||||||||||||||||||||||||||||||||||||||||
| 570 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | $entries = _decode_gzip_like( | |||||||||||||||||||||||||||||||||||||||||
| 572 | $bytes, | ||||||||||||||||||||||||||||||||||||||||||
| 573 | $format, | ||||||||||||||||||||||||||||||||||||||||||
| 574 | $default_name, | ||||||||||||||||||||||||||||||||||||||||||
| 575 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||
| 577 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | _error( "Unsupported archive format '$format'" ); | |||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | return _archive_to_zuzu( $format, $entries ); | |||||||||||||||||||||||||||||||||||||||||
| 582 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 583 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||
| 585 | $archive_class->static_methods->{dump} = native_function( | ||||||||||||||||||||||||||||||||||||||||||
| 586 | name => 'dump', | ||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | native => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | my ( $class_value, $path_obj, $archive_value, $format_value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | $runtime->assert_capability( | |||||||||||||||||||||||||||||||||||||||||
| 590 | 'fs', | ||||||||||||||||||||||||||||||||||||||||||
| 591 | 'Archive.dump is denied by runtime policy', | ||||||||||||||||||||||||||||||||||||||||||
| 592 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | my $path_tiny = _path_tiny_from_object( $path_obj, 'Archive.dump' ); | |||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | my $path_name = $path_tiny->stringify; | |||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | my ( $entries, $archive_format ) = _entries_from_archive_value( | |||||||||||||||||||||||||||||||||||||||||
| 596 | $archive_value, | ||||||||||||||||||||||||||||||||||||||||||
| 597 | 'Archive.dump', | ||||||||||||||||||||||||||||||||||||||||||
| 598 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | my $format = _resolve_format_for_encode( | |||||||||||||||||||||||||||||||||||||||||
| 600 | $path_name, | ||||||||||||||||||||||||||||||||||||||||||
| 601 | $archive_format, | ||||||||||||||||||||||||||||||||||||||||||
| 602 | $format_value, | ||||||||||||||||||||||||||||||||||||||||||
| 603 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | my $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | ▶ | if ( $format eq 'zip' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | $bytes = _encode_zip($entries); | |||||||||||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||||||||||||
| 609 | ▶ | elsif ( $format eq 'tar' or $format eq 'tar.gz' or $format eq 'tar.bz2' ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$format eq "tar" or $format eq "tar.gz" or $format eq "tar.bz2"
$format eq "tar" or $format eq "tar.gz"
MC/DC0%0/3
$format eq "tar" or $format eq "tar.gz" or $format eq "tar.bz2"
$format eq "tar"
$format eq "tar.gz"
$format eq "tar.bz2"
Truth table0%0/4
A or B or C
A= $format eq "tar"B= $format eq "tar.gz"C= $format eq "tar.bz2"
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | $bytes = _encode_tar( $entries, $format ); | |||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||
| 612 | ▶ | elsif ( $format eq 'gz' or $format eq 'bz2' ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$format eq "gz" or $format eq "bz2"
MC/DC0%0/2
$format eq "gz" or $format eq "bz2"
$format eq "gz"
$format eq "bz2"
Truth table0%0/3
A or B
A= $format eq "gz"B= $format eq "bz2"
| |||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | $bytes = _encode_gzip_like( $entries, $format ); | |||||||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||||||
| 615 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | _error( "Unsupported archive format '$format'" ); | |||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | _write_all_bytes( $path_tiny, $bytes ); | |||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | return $path_obj; | |||||||||||||||||||||||||||||||||||||||||
| 621 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 622 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 625 | 4 | Archive => $archive_class, | |||||||||||||||||||||||||||||||||||||||||
| 626 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||
| 633 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | Zuzu::Module::Archive - std/archive bindings for ZuzuScript. | ||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||
| 637 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||
| 639 | Implements the C<std/archive> module, exporting the C<Archive> class. | ||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||
| 641 | This first backend concentrates on a small, portable surface: | ||||||||||||||||||||||||||||||||||||||||||
| 642 | C<decode>, C<encode>, C<load>, and C<dump>. | ||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||
| 644 | Archive values are represented as a dict: | ||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||
| 646 | { | ||||||||||||||||||||||||||||||||||||||||||
| 647 | format: "zip", | ||||||||||||||||||||||||||||||||||||||||||
| 648 | entries: [ | ||||||||||||||||||||||||||||||||||||||||||
| 649 | { path: "hello.txt", data: BinaryString }, | ||||||||||||||||||||||||||||||||||||||||||
| 650 | { path: "nested/world.txt", data: BinaryString }, | ||||||||||||||||||||||||||||||||||||||||||
| 651 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | Only regular file entries are preserved in this API. Directory entries | ||||||||||||||||||||||||||||||||||||||||||
| 655 | and other archive metadata are intentionally ignored to keep the | ||||||||||||||||||||||||||||||||||||||||||
| 656 | surface small and portable. | ||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||
| 658 | =head1 CLASS | ||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||
| 660 | =head2 Archive | ||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||
| 662 | Static methods: | ||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||
| 664 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||
| 666 | =item * C<Archive.decode(bytes, format?)> | ||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | Decodes C<BinaryString> archive bytes into an archive dict. When the | ||||||||||||||||||||||||||||||||||||||||||
| 669 | format is omitted or C<auto>, the backend attempts to detect it from | ||||||||||||||||||||||||||||||||||||||||||
| 670 | the bytes. | ||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||
| 672 | =item * C<Archive.encode(archive, format?)> | ||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | Encodes an archive dict into C<BinaryString> bytes. The format may be | ||||||||||||||||||||||||||||||||||||||||||
| 675 | taken from C<archive.format>. | ||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||
| 677 | =item * C<Archive.load(path, format?)> | ||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||
| 679 | Reads archive bytes from a C<std/io> C<Path> and decodes them. | ||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||
| 681 | =item * C<Archive.dump(path, archive, format?)> | ||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||
| 683 | Encodes an archive dict and writes it to a C<std/io> C<Path>. | ||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||
| 687 | Perl currently supports C<zip>, C<tar>, C<tar.gz>, C<tar.bz2>, | ||||||||||||||||||||||||||||||||||||||||||
| 688 | C<gz>, and C<bz2>. | ||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||
| 690 | =head1 COPYRIGHT AND LICENCE | ||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||
| 692 | B<< Zuzu::Module::Archive >> is copyright Toby Inkster. | ||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||
| 694 | It is free software; you may redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 695 | the terms of either the Artistic License 1.0 or the GNU General Public | ||||||||||||||||||||||||||||||||||||||||||
| 696 | License version 2. | ||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||
| 698 | =cut | ||||||||||||||||||||||||||||||||||||||||||