SimpleExtractor.pm

filter: Statementstmt 80.0% 32 / 40 Branchbran 33.3% 4 / 12 Conditioncond 25.0% 3 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 87.5% 7 / 8 Podpod 100% 3 / 3 totaltotal 59.0% 49 / 83 CC 11 SCAR 24.7
CC
11
Cov
61%
extract
30.0
have_extractor
8.1
BEGIN
1.0
CRAP 11.8
« SimpleExtractor/Zip.pm ↑ Summary SimpleExtractor/Rar.pm »
1 package Archive::SimpleExtractor;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Module::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Module::Load::Conditional qw/can_load/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 $Module::Load::Conditional::VERBOSE = 1;
8  
9 =head1 NAME
10  
11 Archive::SimpleExtractor - simple module for extract archives
12  
13 =head1 VERSION
14  
15 Version 0.10
16  
17 =cut
18  
19 2 our $VERSION = '0.11';
20  
21  
22 =head1 SYNOPSIS
23  
24 use Archive::SimpleExtractor;
25  
26 my $extractor = new Archive::SimpleExtractor;
27
28 @res = $extractor->extract(archive => 'archive.tar.bz2', dir => './somedir', tree => 1);
29  
30 =cut
31  
32 2 our $extentions = {
33 'zip' => 'Archive::SimpleExtractor::Zip',
34 'rar' => 'Archive::SimpleExtractor::Rar',
35 'tar' => 'Archive::SimpleExtractor::Tar',
36 'tgz' => 'Archive::SimpleExtractor::Tar',
37 'tar.gz' => 'Archive::SimpleExtractor::Tar',
38 'tar.bz2' => 'Archive::SimpleExtractor::Tar',
39 };
40  
41 =head1 METHODS
42  
43 =head2 new
44  
45 Returns a new object
46  
47 =cut
48  
49 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
50 1 my $self = shift;
51 1 $self = bless {}, $self;
52 1 return $self;
53 }
54  
55 =head2 extract
56  
57 @res = $extractor->extract(archive => $archive_file, dir => $destination_dir, [tree => 1]);
58  
59 extract files from archive
60  
61 Atributes HASH:
62  
63  
64  
65 archive => ...
66  
67 path to you archive file
68  
69  
70  
71 dir => ...
72  
73 path will be unpacked archive
74  
75  
76  
77 tree => 1
78  
79 By default extractor unpacked arhive without subdirectories, but all files have been extracted in source dir. If you want save stucture set this argument.
80  
81  
82 use_extractor => [file extention]
83  
84 if archive file have not extentions, your must set this parameter for right select extractor
85  
86  
87 Returns ARRAY:
88  
89 $res[0] - success status. If 1 then OK else error
90  
91 $res[1] - message or error string
92  
93 =cut
94  
95 0 ▶sub extract {
Subroutine extract: not called CC=5 SCAR=34.0
Pod documented
96 0 my $self = shift;
97 0 my %arguments = @_;
98 0 ▶ return (0, 'Bad atributes') unless $arguments{archive} || $arguments{dir};
Branch: 1 branch
BranchTrueFalseTotal
unless $arguments{"archive"} or $arguments{"dir"} 0 0 0
Condition0%0/3
$arguments{"archive"} or $arguments{"dir"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$arguments{"archive"} or $arguments{"dir"}
$arguments{"archive"} $arguments{"dir"}
Truth table0%0/3
A or B
A= $arguments{"archive"}B= $arguments{"dir"}
ABresult
1X1
011
000
99 0 ▶ return (0, 'No source directory') unless -d $arguments{dir};
Branch: 1 branch
BranchTrueFalseTotal
unless -d $arguments{"dir"} 0 0 0
100 0 my ($res, $extractor) = $self->have_extractor(%arguments);
101 0 ▶ return (0, $extractor) unless $res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 0 0
102 0 my @result = $extractor->extract(%arguments);
103 0 return @result;
104 }
105  
106 =head2 have_extractor
107  
108 Check extractor
109  
110 =cut
111  
112 3 ▶sub have_extractor {
Subroutine have_extractor: called CC=7 SCAR=21.0
Pod documented
113 3 my $self = shift;
114 3 my %arguments = @_;
115 3 my $reg_exp = join('|', keys %{$extentions});
116 3 $reg_exp = qr/$reg_exp/;
117 2 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
118 3 ▶ my ($ext) = $arguments{use_extractor} || $arguments{archive} =~ /\.($reg_exp)$/;
Condition33%1/3
$arguments{'use_extractor'} || $arguments{'archive'} =~ /\.($reg_exp)$/
l!l&&r!l&&!r
030
MC/DC0%0/2
$arguments{'use_extractor'} || $arguments{'archive'} =~ /\.($reg_exp)$/
$arguments{'use_extractor'} $arguments{'archive'} =~ /\.($reg_exp)$/
Truth table33%1/3
A || B
A= $arguments{'use_extractor'}B= $arguments{'archive'} =~ /\.($reg_exp)$/
ABresult
1X1
011
000
119 3 ▶ return (0, 'No Extractor') unless $ext;
Branch: 1 branch
BranchTrueFalseTotal
unless $ext 0 3 3
120 3 ▶ return (0, 'No Extractor') unless $extentions->{$ext} || {reverse %$extentions}->{$ext};
Branch: 1 branch
BranchTrueFalseTotal
unless $Archive::SimpleExtractor::extentions->{$ext} or {reverse(%$Archive::SimpleExtractor::extentions)}->{$ext} 0 3 3
Condition33%1/3
$Archive::SimpleExtractor::extentions->{$ext} or {reverse(%$Archive::SimpleExtractor::extentions)}->{$ext}
l!l&&r!l&&!r
300
MC/DC0%0/2
$Archive::SimpleExtractor::extentions->{$ext} or {reverse(%$Archive::SimpleExtractor::extentions)}->{$ext}
$Archive::SimpleExtractor::extentions->{$ext} {reverse(%$Archive::SimpleExtractor::extentions)}->{$ext}
Truth table33%1/3
A or B
A= $Archive::SimpleExtractor::extentions->{$ext}B= {reverse(%$Archive::SimpleExtractor::extentions)}->{$ext}
ABresult
1X1
011
000
121 3 ▶ my $extractor = $extentions->{$ext} || $ext;
Condition33%1/3
$Archive::SimpleExtractor::extentions->{$ext} || $ext
l!l&&r!l&&!r
300
MC/DC0%0/2
$Archive::SimpleExtractor::extentions->{$ext} || $ext
$Archive::SimpleExtractor::extentions->{$ext} $ext
Truth table33%1/3
A || B
A= $Archive::SimpleExtractor::extentions->{$ext}B= $ext
ABresult
1X1
011
000
122 3 ▶ return can_load(modules => {$extractor => 0.0}) ? (1, $extractor) : (0, 'Bad Extractor');
Branch: 1 branch
BranchTrueFalseTotal
can_load('modules', {$extractor, 0.0}) ? : 2 1 3
123 }
124  
125 =head1 AUTHOR
126  
127 Sergey Tomoulevitch, C<< <phoinix.public at gmail.com> >>
128  
129 =head1 BUGS
130  
131 Please report any bugs or feature requests to C<bug-archive-simpleextractor at rt.cpan.org>, or through
132 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Archive-SimpleExtractor>. I will be notified, and then you'll
133 automatically be notified of progress on your bug as I make changes.
134  
135  
136  
137  
138 =head1 SUPPORT
139  
140 You can find documentation for this module with the perldoc command.
141  
142 perldoc Archive::SimpleExtractor
143  
144  
145 You can also look for information at:
146  
147 =over 4
148  
149 =item * RT: CPAN's request tracker
150  
151 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Archive-SimpleExtractor>
152  
153 =item * AnnoCPAN: Annotated CPAN documentation
154  
155 L<http://annocpan.org/dist/Archive-SimpleExtractor>
156  
157 =item * CPAN Ratings
158  
159 L<http://cpanratings.perl.org/d/Archive-SimpleExtractor>
160  
161 =item * Search CPAN
162  
163 L<http://search.cpan.org/dist/Archive-SimpleExtractor/>
164  
165 =back
166  
167  
168 =head1 COPYRIGHT & LICENSE
169  
170 Copyright 2009 Sergey Tomoulevitch.
171  
172 This program is free software; you can redistribute it and/or modify it
173 under the terms of either: the GNU General Public License as published
174 by the Free Software Foundation; or the Artistic License.
175  
176 See http://dev.perl.org/licenses/ for more information.
177  
178  
179 =cut
180  
181 2 1; # End of Archive::SimpleExtractor
« SimpleExtractor/Zip.pm ↑ Summary SimpleExtractor/Rar.pm »