File Coverage

blib/lib/Archive/SimpleExtractor/Tar.pm
Criterion Covered Total %
statement 18 40 45.0
branch 0 10 0.0
condition n/a
subroutine 6 7 85.7
pod 0 1 0.0
total 24 58 41.3


line stmt bran cond sub pod time code
1             package Archive::SimpleExtractor::Tar;
2              
3 1     1   2348 use warnings;
  1         2  
  1         27  
4 1     1   5 use strict;
  1         2  
  1         21  
5 1     1   998 use Archive::Tar;
  1         133027  
  1         100  
6 1     1   13 use File::Find;
  1         3  
  1         54  
7 1     1   6 use File::Copy;
  1         3  
  1         53  
8 1     1   6 use File::Path qw/rmtree/;
  1         2  
  1         362  
9              
10             =head1 NAME
11              
12             =head1 VERSION
13              
14             Version 0.03
15              
16             =cut
17              
18             our $VERSION = '0.03';
19              
20             =head1 SYNOPSIS
21              
22             =cut
23              
24             =head1 METHODS
25              
26             =head2 new
27              
28             =cut
29              
30             sub extract {
31 0     0 0   my $self = shift;
32 0           my %arguments = @_;
33 0           my $tar = Archive::Tar->new;
34 0           my ($archive_file) = $arguments{archive} =~ /\/?([^\/]+)$/;
35 0           copy($arguments{archive}, $arguments{dir}.$archive_file);
36 0           chdir $arguments{dir};
37 0 0         unless ( $tar->read($archive_file) ) { return (0, 'Can not read archive file'.$arguments{archive}) }
  0            
38 0           my @files = $tar->extract();
39 0 0         return (0, 'Can not extract archive' ) unless @files;
40 0 0         if ($arguments{tree}) {
41 0           unlink $archive_file;
42 0           return (1, 'Extract finished with directory tree');
43             } else {
44 0           foreach my $file (@files) {
45 0 0         next if -d $file->full_path;
46 0           my ($filename) = $file->full_path =~ /\/([^\/]+)$/;
47 0           copy($file->full_path, $filename);
48             }
49 0 0         foreach my $item (<*>) {if (-d $item) {rmtree($item)}}
  0            
  0            
50 0           unlink $archive_file;
51 0           return (1, 'Extract finished without directory tree');
52             }
53             }
54              
55             1;