blib/lib/Verby/Action/Untar.pm

filter: Statementstmt 90.9% 50 / 55 Branchbran 66.6% 8 / 12 Conditioncond 55.5% 5 / 9 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 83.3% 10 / 12 Podpod 25.0% 1 / 4 totaltotal 78.1% 75 / 96 CC 11 SCAR 16.4
CC
11
Cov
83%
verify
9.8
__ANON__
6.0
tar_archive
2.0
CRAP 5.2
↑ Summary
1 #!/usr/bin/perl
2  
3 package Verby::Action::Untar;
4 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 with qw/Verby::Action::Run/;
7  
8 1 our $VERSION = "0.04";
9  
10 1 ▶use Archive::Tar;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::stat;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶sub do {
Subroutine do: called CC=1 SCAR=0.8
Pod documented
15 1 my ( $self, $c ) = @_;
16  
17 1 my $tarball = $c->tarball;
18 1 my $dest = $c->dest;
19
20 1 $c->logger->info("untarring '$tarball' into '$dest'");
21  
22 $self->create_poe_session(
23 c => $c,
24 0 ▶ program => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
25 0 chdir $dest;
26  
27 0 ▶ $self->tar_archive($c)->extract
Branch: 1 branch
BranchTrueFalseTotal
$self->tar_archive($c)->extract or $c->logger->log_and_die("Archive::Tar->extract did not return a true value") 0 0 0
28 or $c->logger->log_and_die("Archive::Tar->extract did not return a true value");
29 },
30 1 program_debug_string => "Archive::Tar child",
31 );
32 }
33  
34 1 ▶sub finished {
Subroutine finished: called CC=1 SCAR=0.0
Pod undocumented
35 1 my ( $self, $c ) = @_;
36 1 $c->logger->info("finished untarring");
37 1 $self->confirm($c);
38 }
39  
40 3 ▶sub verify {
Subroutine verify: called CC=9 SCAR=22.8
Pod undocumented
41 3 my ( $self, $c ) = @_;
42  
43 3 my $dest = $c->dest;
44  
45 3 my $main_dir; # the main directory in the archive, if any
46  
47 my $i;
48  
49 3 my $tarball = $self->tar_archive( $c );
50  
51 3 foreach my $spec ( $tarball->list_files([qw/name size mtime/]) ) {
52 5 my ( $name, $size, $mtime ) = @{ $spec }{qw/name size mtime/};
53  
54 # determine the top level unpack directory
55 5 my $top_dir = (File::Spec->splitdir($name))[0];
56 5 ▶ if ( defined $main_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $main_dir) { } 2 3 5
57 2 ▶ if ( $top_dir ne $main_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($top_dir ne $main_dir) 0 2 2
58 0 $c->logger->warn("Archive has no main directory");
59 0 $main_dir = '';
60 }
61 } else {
62 3 $main_dir = $top_dir;
63 }
64  
65 5 my $destfile = File::Spec->catfile($dest, $name);
66 5 my $existing = stat($destfile);
67 5 ▶ unless ( $existing and ( -d $destfile or $existing->size == $size && $existing->mtime == $mtime ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($existing and -d $destfile || $existing->size == $size && $existing->mtime == $mtime) 1 4 5
Condition55%5/9
$existing and -d $destfile || $existing->size == $size && $existing->mtime == $mtime
!ll&&!rl&&r
104
-d $destfile or $existing->size == $size and $existing->mtime == $mtime
l!l&&r!l&&!r
220
$existing->size == $size and $existing->mtime == $mtime
!ll&&!rl&&r
002
MC/DC25%1/4
$existing and -d $destfile || $existing->size == $size && $existing->mtime == $mtime
$existing -d $destfile $existing->size == $size $existing->mtime == $mtime
Truth table60%3/5
A and B or C and D
A= $existingB= -d $destfileC= $existing->size == $sizeD= $existing->mtime == $mtime
ABCDresult
0XXX0
100X0
10100
11XX1
10111
68 1 ▶ $c->logger->warn("file '$name' requires re-extraction") if $i; # it's ok only for the first file to be missing
Branch: 1 branch
BranchTrueFalseTotal
if $i 0 1 1
69 1 return undef;
70 }
71  
72 4 $i++;
73 }
74  
75 2 $c->main_dir(File::Spec->catdir($dest, $main_dir));
76  
77 2 return 1;
78 }
79  
80 3 ▶sub tar_archive {
Subroutine tar_archive: called CC=2 SCAR=6.9
Pod undocumented
81 3 my ( $self, $c ) = @_;
82 3 ▶ $c->archive_object || $c->archive_object(Archive::Tar::LogError->new($c->tarball));
Branch: 1 branch
BranchTrueFalseTotal
$c->archive_object or $c->archive_object("Archive::Tar::LogError"->new($c->tarball)) 2 1 3
83 }
84  
85 package Archive::Tar::LogError;
86 1 ▶use base qw(Archive::Tar);
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 1 ▶use Log::Dispatch::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
89  
90 0 ▶sub _error {
Subroutine _error: not called CC=1 SCAR=6.9
91 0 Log::Dispatch::Config->instance->log_and_die( level => "error", message => $_[1] );
92 }
93  
94 1 __PACKAGE__
95  
96 __END__
↑ Summary