Packer/InstallerMaker/dir.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 58 CC 4 SCAR 23.0
CC
4
Cov
0%
run
20.0
_build_target_dir
2.0
BEGIN
2.0
CRAP 10.0
1 package Win32::Packer::InstallerMaker::dir;
2  
3 use Path::Tiny;
4 use Win32::Packer::Helpers qw(mkpath to_bool);
5  
6 use Moo;
7 use namespace::autoclean;
8  
9 extends 'Win32::Packer::InstallerMaker';
10  
11 has target_dir => (is => 'lazy', coerce => \&mkpath);
12  
13 has update => (is => 'ro', coerce => \&to_bool );
14  
15 sub _build_target_dir {
16 my $self = shift;
17 my $basename = join '-', grep defined, $self->app_name, $self->app_version;
18 $self->output_dir->child($basename);
19 }
20  
21 sub run {
22 my $self = shift;
23  
24 my $target_dir = $self->target_dir;
25  
26 my $fs = $self->_fs;
27 my $update = $self->update;
28 for my $to (sort keys %$fs) {
29 my $topto = $target_dir->child($to);
30 my $obj = $fs->{$to};
31 my $type = $obj->{type};
32 $self->log->trace("Adding object '$topto' of type $type");
33 if ($type eq 'dir') {
34 $topto->mkpath;
35 }
36 elsif ($type eq 'file') {
37 if ($update and -f $topto and (stat $obj->{path})[9] <= (stat $topto)[9]) {
38 $self->log->trace("Already up to date, skipping!");
39 next;
40 }
41 path($obj->{path})->copy($topto);
42 }
43 else {
44 $self->log->warn("Unknown file system object type '$type' for '$topto', ignoring it");
45 }
46 }
47 $self->log->info("Application copied to directory $target_dir");
48 }
49  
50 1;