blib/lib/Dist/Zilla/Plugin/CopyFilesFromBuild.pm

filter: Statementstmt 79.3% 77 / 97 Branchbran 55.0% 11 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 16 / 20 Podpod 0.0% 0 / 2 totaltotal 74.8% 104 / 139 CC 14 SCAR 15.9
CC
14
Cov
75%
after_build
11.8
_filter_manifest
4.4
_prune_moved_files
3.0
CRAP 4.9
↑ Summary
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Dist::Zilla::Plugin::CopyFilesFromBuild;
6 # ABSTRACT: Copy (or move) specific files after building (for SCM inclusion, etc.)
7 2 $Dist::Zilla::Plugin::CopyFilesFromBuild::VERSION = '0.170880';
8 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use MooseX::Has::Sugar;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 with qw/ Dist::Zilla::Role::AfterBuild /;
11  
12 2 ▶use File::Copy ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use List::Util 1.33 qw( any );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Set::Scalar;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # accept some arguments multiple times.
19 1 ▶sub mvp_multivalue_args { qw{ copy move } }
Subroutine mvp_multivalue_args: called CC=1 SCAR=0.0
Pod undocumented
20  
21 has copy => (
22 ro, lazy,
23 isa => 'ArrayRef[Str]',
24 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 2 );
26  
27 has move => (
28 ro, lazy,
29 isa => 'ArrayRef[Str]',
30 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 2 );
32  
33 1 ▶sub after_build {
Subroutine after_build: called CC=10 SCAR=24.7
Pod undocumented
34 1 my $self = shift;
35 1 my $data = shift;
36  
37 1 my $build_root = $data->{build_root};
38 1 for my $path (@{$self->copy}) {
39 2 ▶ if ($path eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "") 0 2 2
40 0 next;
41 }
42 2 my $src = path($build_root)->child( $path );
43 2 my $dest = path($self->zilla->root)->child( $path );
44 2 ▶ if (-e $src) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $src) { } 2 0 2
45 2 ▶ File::Copy::copy "$src", "$dest"
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::copy("$src", "$dest") or $self->log_fatal("Unable to copy $src to ${dest}: $!") 2 0 2
46 or $self->log_fatal("Unable to copy $src to $dest: $!");
47 2 $self->log("Copied $src to $dest");
48 } else {
49 0 $self->log_fatal("Cannot copy $path from build: file does not exist");
50 }
51 }
52  
53 1 my $moved_something = 0;
54  
55 1 for my $path (@{$self->move}) {
56 1 ▶ if ($path eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "") 0 1 1
57 0 next;
58 }
59 1 my $src = path($build_root)->child( $path );
60 1 my $dest = path($self->zilla->root)->child( $path );
61 1 ▶ if (-e $src) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $src) { } 1 0 1
62 1 ▶ File::Copy::move "$src", "$dest"
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::move("$src", "$dest") or $self->log_fatal("Unable to move $src to ${dest}: $!") 1 0 1
63 or $self->log_fatal("Unable to move $src to $dest: $!");
64 1 $moved_something++;
65 1 $self->log("Moved $src to $dest");
66 } else {
67 0 $self->log_fatal("Cannot move $path from build: file does not exist");
68 }
69 }
70  
71 1 ▶ if ($moved_something) {
Branch: 1 branch
BranchTrueFalseTotal
if ($moved_something) 1 0 1
72 # These are probably horrible hacks. If so, please tell me a
73 # better way.
74 1 $self->_prune_moved_files();
75 1 $self->_filter_manifest($build_root);
76 }
77 }
78  
79 1 ▶sub _prune_moved_files {
Subroutine _prune_moved_files: called CC=3 SCAR=11.0
80 1 my ($self, ) = @_;
81 1 for my $file (@{ $self->zilla->files }) {
82 6 ▶ next unless any { $file->name eq $_ } @{$self->move};
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless &any(sub { $file->name eq $_; } , @{$self->move;}) 5 1 6
83  
84 1 $self->log_debug([ 'pruning moved file %s', $file->name ]);
85  
86 1 $self->zilla->prune_file($file);
87 }
88 }
89  
90 0 ▶sub _read_manifest {
Subroutine _read_manifest: not called CC=1 SCAR=6.9
91 0 my ($self, $manifest_filename) = @_;
92 0 my $input = IO::File->new($manifest_filename);
93 0 my @lines = $input->getlines;
94 0 chomp @lines;
95 0 return @lines;
96 }
97  
98 0 ▶sub _write_manifest {
Subroutine _write_manifest: not called CC=1 SCAR=6.9
99 0 my ($self, $manifest_filename, @contents) = @_;
100 0 my $output = IO::File->new($manifest_filename, 'w');
101 0 $output->print(join("\n", (sort @contents)), "\n");
102 }
103  
104 1 ▶sub _filter_manifest {
Subroutine _filter_manifest: called CC=3 SCAR=14.7
105 1 my ($self, $build_root) = @_;
106 1 ▶ if (@{$self->move}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->move;}) 1 0 1
107 1 my $manifest_file = path($build_root)->child( 'MANIFEST' );
108 1 ▶ return unless -e $manifest_file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $manifest_file 1 0 1
109 0 my $files = Set::Scalar->new($self->_read_manifest($manifest_file));
110 0 my $moved_files = Set::Scalar->new(@{$self->move});
111 0 my $filtered_files = $files->difference($moved_files);
112 0 $self->log_debug("Removing moved files from MANIFEST");
113 0 $self->_write_manifest($manifest_file, $filtered_files->members);
114 }
115 }
116  
117 2 __PACKAGE__->meta->make_immutable;
118 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
119 2 1; # Magic true value required at end of module
120  
121 __END__
↑ Summary