| 1 | package Archive::SimpleExtractor::Zip; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | ▶ | use Archive::Zip qw/ :ERROR_CODES :CONSTANTS /; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 1 | ▶ | use File::Find; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use File::Copy; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 1 | ▶ | use File::Path qw/rmtree/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 1 | ▶ | use Cwd 'abs_path'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | =head1 NAME | ||||||||||||
| 12 | |||||||||||||
| 13 | =head1 VERSION | ||||||||||||
| 14 | |||||||||||||
| 15 | Version 0.04 | ||||||||||||
| 16 | |||||||||||||
| 17 | =cut | ||||||||||||
| 18 | |||||||||||||
| 19 | 1 | our $VERSION = '0.03'; | |||||||||||
| 20 | |||||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||||
| 22 | |||||||||||||
| 23 | =cut | ||||||||||||
| 24 | |||||||||||||
| 25 | =head1 METHODS | ||||||||||||
| 26 | |||||||||||||
| 27 | =head2 new | ||||||||||||
| 28 | |||||||||||||
| 29 | =cut | ||||||||||||
| 30 | |||||||||||||
| 31 | 0 | ▶ | sub extract { | ||||||||||
|
Subroutine
extract: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||
| 32 | 0 | my $self = shift; | |||||||||||
| 33 | 0 | my %arguments = @_; | |||||||||||
| 34 | 0 | my $zip = Archive::Zip->new(); | |||||||||||
| 35 | 0 | $arguments{dir} = abs_path($arguments{dir}).'/'; | |||||||||||
| 36 | 0 | copy($arguments{archive}, $arguments{dir}); | |||||||||||
| 37 | 0 | my ($zipfile) = $arguments{archive} =~ /([^\/]+)$/; | |||||||||||
| 38 | 0 | $arguments{archive} = $arguments{dir}.$zipfile; | |||||||||||
| 39 | 0 | ▶ | unless ( $zip->read($arguments{archive}) == AZ_OK ) { return (0, 'Can not read archive file'.$arguments{archive}) } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 40 | 0 | ▶ | if ($arguments{tree}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | 0 | ▶ | unless ( $zip->extractTree( '' , $arguments{dir} ) == AZ_OK ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | 0 | unlink $arguments{archive}; | |||||||||||
| 43 | 0 | return (0, 'Can not extract archive' ) | |||||||||||
| 44 | } | ||||||||||||
| 45 | 0 | unlink $arguments{archive}; | |||||||||||
| 46 | 0 | return (1, 'Extract finished with directory tree'); | |||||||||||
| 47 | } else { | ||||||||||||
| 48 | 0 | my $tmp_dir = '.tmp'.rand(10000).'/'; | |||||||||||
| 49 | 0 | ▶ | mkdir $arguments{dir}.$tmp_dir || return (0, 'Can not create temp_directory '.$! ); | ||||||||||
|
Condition0%0/2
$arguments{'dir'} . $tmp_dir || (return 0, 'Can not create temp_directory ' . $!)
MC/DC0%0/1
$arguments{'dir'} . $tmp_dir || (return 0, 'Can not create temp_directory ' . $!)
$arguments{'dir'} . $tmp_dir
Truth table0%0/2
A
A= $arguments{'dir'} . $tmp_dir
| |||||||||||||
| 50 | 0 | $tmp_dir = $arguments{dir}.$tmp_dir; | |||||||||||
| 51 | 0 | ▶ | unless ( $zip->extractTree( '' , $tmp_dir ) == AZ_OK ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 52 | 0 | unlink $arguments{archive}; | |||||||||||
| 53 | 0 | return (0, 'Can not extract archive' ); | |||||||||||
| 54 | } | ||||||||||||
| 55 | 0 | ▶ | find( { wanted => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 56 | 0 | ▶ | if (-f $File::Find::name) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | 0 | my ($filename) = $File::Find::name =~ /\/([^\/]+)$/; | |||||||||||
| 58 | 0 | copy($File::Find::name, $arguments{dir}.$filename); | |||||||||||
| 59 | } | ||||||||||||
| 60 | }, | ||||||||||||
| 61 | 0 | no_chdir => 1, | |||||||||||
| 62 | }, | ||||||||||||
| 63 | $tmp_dir, | ||||||||||||
| 64 | ); | ||||||||||||
| 65 | 0 | rmtree($tmp_dir); | |||||||||||
| 66 | 0 | unlink $arguments{archive}; | |||||||||||
| 67 | 0 | return (1, 'Extract finished without directory tree'); | |||||||||||
| 68 | } | ||||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | 1 | 1; | |||||||||||