File Coverage

blib/lib/Archive/SimpleExtractor/Zip.pm
Criterion Covered Total %
statement 21 49 42.8
branch 0 10 0.0
condition 0 2 0.0
subroutine 7 9 77.7
pod 0 1 0.0
total 28 71 39.4


line stmt bran cond sub pod time code
1             package Archive::SimpleExtractor::Zip;
2              
3 1     1   3124 use warnings;
  1         2  
  1         36  
4 1     1   6 use strict;
  1         2  
  1         36  
5 1     1   1244 use Archive::Zip qw/ :ERROR_CODES :CONSTANTS /;
  1         91717  
  1         285  
6 1     1   10 use File::Find;
  1         2  
  1         67  
7 1     1   7 use File::Copy;
  1         2  
  1         65  
8 1     1   6 use File::Path qw/rmtree/;
  1         2  
  1         51  
9 1     1   6 use Cwd 'abs_path';
  1         1  
  1         538  
10              
11             =head1 NAME
12              
13             =head1 VERSION
14              
15             Version 0.04
16              
17             =cut
18              
19             our $VERSION = '0.03';
20              
21             =head1 SYNOPSIS
22              
23             =cut
24              
25             =head1 METHODS
26              
27             =head2 new
28              
29             =cut
30              
31             sub extract {
32 0     0 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 0         unless ( $zip->read($arguments{archive}) == AZ_OK ) { return (0, 'Can not read archive file'.$arguments{archive}) }
  0            
40 0 0         if ($arguments{tree}) {
41 0 0         unless ( $zip->extractTree( '' , $arguments{dir} ) == AZ_OK ) {
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   0       mkdir $arguments{dir}.$tmp_dir || return (0, 'Can not create temp_directory '.$! );
50 0           $tmp_dir = $arguments{dir}.$tmp_dir;
51 0 0         unless ( $zip->extractTree( '' , $tmp_dir ) == AZ_OK ) {
52 0           unlink $arguments{archive};
53 0           return (0, 'Can not extract archive' );
54             }
55             find( { wanted => sub {
56 0 0   0     if (-f $File::Find::name) {
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;