blib/lib/File/Archive.pm

filter: Statementstmt 89.0% 49 / 55 Branchbran 81.8% 18 / 22 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 5 totaltotal 85.0% 85 / 100 CC 13 SCAR 15.5
CC
13
Cov
88%
member
8.1
new
4.0
catalog
4.0
CRAP 4.7
↑ Summary
1 package File::Archive;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Archive::Tar qw(0.2);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Compress::Zlib;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 $File::Archive::VERSION = '0.53';
6  
7 5 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod undocumented
8 5 my ($class, $file) = @_;
9 5 my $self = bless {}, $class;
10  
11 5 $self->{filename} = $file;
12  
13 # What type of file is it?
14 5 my $name = $self->{filename};
15 5 ▶ if ($name=~/\.(tar\.gz|tar\.Z|tgz)$/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($name =~ /\.(tar\.gz|tar\.Z|tgz)$/) { } 1 4 5
elsif ($name =~ /\.(gz|Z)$/) { } 2 2 4
elsif ($name =~ /\.tar$/) { } 1 1 2
16 1 $self->{type}="tarred compressed";
17 1 $self->{type_num} = 1;
18 }
19 elsif ($name=~/\.(gz|Z)$/) {
20 2 $self->{type}="compressed";
21 2 $self->{type_num} = 2;
22 }
23 elsif ($name=~/\.tar$/) {
24 1 $self->{type}="tarred";
25 1 $self->{type_num} = 3;
26 }
27 else {
28 1 $self->{type}="plain";
29 1 $self->{type_num} = 4;
30 }
31  
32 5 return $self;
33 }
34  
35 5 ▶sub catalog {
Subroutine catalog: called CC=4 SCAR=13.9
Pod undocumented
36 5 my ($self) = @_;
37 5 my ($tar);
38  
39 # What's in the file?
40 5 ▶ if ($self->{type_num} == 4) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'type_num'} == 4) { } 1 4 5
elsif ($self->{'type_num'} == 1 or $self->{'type_num'} == 3) { } 2 2 4
41 1 return ($self->{filename});
42 }
43 ▶ elsif ($self->{type_num} == 1 || $self->{type_num} == 3) {
Condition100%3/3
$self->{"type_num"} == 1 or $self->{"type_num"} == 3
l!l&&r!l&&!r
112
MC/DC100%2/2
$self->{"type_num"} == 1 or $self->{"type_num"} == 3
$self->{"type_num"} == 1 $self->{"type_num"} == 3
Truth table100%3/3
A or B
A= $self->{"type_num"} == 1B= $self->{"type_num"} == 3
ABresult
1X1
011
000
44 2 $tar = Archive::Tar->new();
45 2 return $tar->list_archive($self->{filename});
46 }
47 else {
48 2 my $name = $self->{filename};
49 2 $name =~ s/\.(Z|gz)$//;
50 2 return $name;
51 }
52 } # End method catalog
53  
54 3 ▶sub member {
Subroutine member: called CC=7 SCAR=21.0
Pod undocumented
55 3 my ($self, $file) = @_;
56 3 my ($contents, $tar, $gz, $line, $output);
57  
58 # What's in the files in the archive?
59 3 ▶ if ($self->{type_num} == 4) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'type_num'} == 4) { } 0 3 3
elsif ($self->{'type_num'} == 1 or $self->{'type_num'} == 3) { } 2 1 3
60 0 open (FILE, $self->{filename});
61 0 undef $/;
62 0 $contents = <FILE>;
63 0 close FILE;
64 }
65 ▶ elsif ($self->{type_num} == 1 || $self->{type_num} == 3) {
Condition100%3/3
$self->{"type_num"} == 1 or $self->{"type_num"} == 3
l!l&&r!l&&!r
111
MC/DC100%2/2
$self->{"type_num"} == 1 or $self->{"type_num"} == 3
$self->{"type_num"} == 1 $self->{"type_num"} == 3
Truth table100%3/3
A or B
A= $self->{"type_num"} == 1B= $self->{"type_num"} == 3
ABresult
1X1
011
000
66 2 $tar = Archive::Tar->new($self->{filename});
67 2 $contents = $tar->get_content($file);
68 } else {
69 # Actually, there's two things here
70 1 ▶ if ($self->{filename} =~ /\.(Z|zip|hqx|bz2?)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'filename'} =~ /\.(Z|zip|hqx|bz2?)$/) { } 0 1 1
71 0 $contents = undef;
72 } else { # it's a gz file
73 1 ▶ $gz=gzopen($self->{filename}, "rb") or die
Branch: 1 branch
BranchTrueFalseTotal
$gz = &gzopen($self->{"filename"}, "rb") or die "Can't open file: $File::Archive::gzerrno\n" 1 0 1
74 "Can't open file: $gzerrno\n";
75 1 ▶ while ($gz->gzreadline($line)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gz->gzreadline($line)) 18 1 19
76 18 $contents .= $line;
77 } # Wend
78 } # End if..else
79 } # End file type test
80
81 3 return $contents;
82 } # End sub member
83  
84 1 ▶sub type {
Subroutine type: called CC=1 SCAR=0.0
Pod undocumented
85 1 my ($self) = @_;
86 1 return $self->{type};
87 }
88  
89 1 ▶sub filename {
Subroutine filename: called CC=1 SCAR=0.0
Pod undocumented
90 1 my ($self) = @_;
91 1 return $self->{filename};
92 }
93  
94 # get rid of annoying -w warnings
95 1 ▶if ($^W) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^W) 0 1 1
96 0 $File::Archive::VERSION = $File::Archive::VERSION;
97 }
98  
99 1 1;
100 __END__
↑ Summary