CPAN/Maker/Bootstrapper/Role/ExtraFiles.pm

filter: Statementstmt 23.6% 26 / 110 Branchbran 0.0% 0 / 60 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 57.1% 8 / 14 Podpod 0.0% 0 / 1 totaltotal 15.7% 34 / 216 CC 48 SCAR 74.0
CC
48
Cov
14%
cmd_extra_files
2162.0
__ANON__
6.0
__ANON__
6.0
CRAP 1631.0
↑ Summary CPAN/Maker/Bootstrapper/Role/Installer.pm »
1 package CPAN::Maker::Bootstrapper::Role::ExtraFiles;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use CLI::Simple::Constants qw(:booleans);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use List::Util qw(any none);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 our $VERSION = '2.4.0';
15  
16 ########################################################################
17 0 ▶sub cmd_extra_files {
Subroutine cmd_extra_files: not called CC=46 SCAR=76.8
Pod undocumented
18 ########################################################################
19 0 my ($self) = @_;
20  
21 0 my ( $path, @extra_files ) = $self->get_args;
22  
23 0 require YAML::Tiny;
24  
25 0 my $buildspec = YAML::Tiny::LoadFile('buildspec.yml');
26 0 ▶ my $extra = $buildspec->{'extra-files'} // [];
Condition0%0/2
$buildspec->{"extra-files"} // []
l!l
00
MC/DC0%0/1
$buildspec->{"extra-files"} // []
$buildspec->{"extra-files"}
Truth table0%0/2
A
A= $buildspec->{"extra-files"}
Aresult
11
00
27  
28 ######################################################################
29 # With no arguments, emit the source files represented by
30 # buildspec.yml. This form is used by make to regenerate extra-files.
31 ######################################################################
32 0 ▶ if ( !defined $path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $path) 0 0 0
33 0 foreach my $entry ( @{$extra} ) {
34 0 ▶ if ( !ref $entry ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $entry) 0 0 0
35 0 print "$entry\n";
36 0 next;
37 }
38  
39 next
40 0 ▶ if reftype($entry) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($entry) ne "HASH" 0 0 0
41  
42 0 foreach my $section ( keys %{$entry} ) {
43 0 my $files = $entry->{$section};
44  
45 0 ▶ if ( !ref $files ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $files) 0 0 0
46 0 ▶ print "$files\n"
Branch: 1 branch
BranchTrueFalseTotal
if defined $files and $files ne "" 0 0 0
Condition0%0/3
defined $files and $files ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $files and $files ne ""
defined $files $files ne ""
Truth table0%0/3
A and B
A= defined $filesB= $files ne ""
ABresult
0X0
100
111
47 if defined $files && $files ne q{};
48 0 next;
49 }
50  
51 next
52 0 ▶ if reftype($files) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($files) ne "ARRAY" 0 0 0
53  
54 0 foreach my $file ( @{$files} ) {
55 0 ▶ print "$file\n"
Branch: 1 branch
BranchTrueFalseTotal
if defined $file and not ref $file and $file ne "" 0 0 0
Condition0%0/6
defined $file and not ref $file and $file ne ""
!ll&&!rl&&r
000
defined $file and not ref $file
!ll&&!rl&&r
000
MC/DC0%0/3
defined $file and not ref $file and $file ne ""
defined $file not ref $file $file ne ""
Truth table0%0/4
A and not(B) and C
A= defined $fileB= not ref $fileC= $file ne ""
ABCresult
0XX0
10X0
1100
1111
56 if defined $file && !ref $file && $file ne q{};
57 }
58 }
59 }
60  
61 0 return $SUCCESS;
62 }
63  
64 die "ERROR: path must root, '.' or share\n"
65 0 ▶ if none { $path eq $_ } qw(root . share);
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &none(sub { $path eq $_; } , "root", ".", "share") 0 0 0
66  
67 0 ▶ die "ERROR: usage cmb extra-files [path file...]\n"
Branch: 1 branch
BranchTrueFalseTotal
unless @extra_files 0 0 0
68 if !@extra_files;
69  
70 0 ▶ $path = q{.}
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "root" 0 0 0
71 if $path eq 'root';
72  
73 ######################################################################
74 # Additions must exist. Removals are idempotent and need not exist on
75 # disk.
76 ######################################################################
77 0 foreach my $file (@extra_files) {
78 next
79 0 ▶ if $file =~ /^-/xsm;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /^-/msx 0 0 0
80  
81 0 ▶ die "ERROR: file not found - make sure '$file' exists before adding to buildspec.yml\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
82 if !-f $file;
83 }
84  
85 0 ▶ if ( $path eq q{.} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq '.') { } 0 0 0
86 0 my @updated;
87  
88 0 foreach my $entry ( @{$extra} ) {
89 0 ▶ if ( ref $entry ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $entry) 0 0 0
90 0 push @updated, $entry;
91 0 next;
92 }
93  
94 0 ▶ my $remove = any {
Subroutine __ANON__: not called CC=2 SCAR=17.9
95 0 my $file = $_;
96 0 $file =~ s/^-//xsm;
97 0 ▶ $_ =~ /^-/xsm && $file eq $entry;
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /^-/msx and $file eq $entry 0 0 0
98 0 } @extra_files;
99  
100 0 ▶ push @updated, $entry
Branch: 1 branch
BranchTrueFalseTotal
unless $remove 0 0 0
101 if !$remove;
102 }
103  
104 0 foreach my $file (@extra_files) {
105 next
106 0 ▶ if $file =~ /^-/xsm;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /^-/msx 0 0 0
107  
108 next
109 0 ▶ if any { !ref $_ && $_ eq $file } @updated;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 2 branches
BranchTrueFalseTotal
if &any(sub { not ref $_ and $_ eq $file; } , @updated) 0 0 0
not ref $_ and $_ eq $file 0 0 0
110  
111 0 push @updated, $file;
112 }
113  
114 0 $extra = \@updated;
115 }
116 else {
117 0 my @updated;
118 my @share_files;
119 0 my $share_seen = $FALSE;
120  
121 ####################################################################
122 # Fold any duplicate share sections into one while preserving all
123 # other extra-files sections unchanged.
124 ####################################################################
125 0 foreach my $entry ( @{$extra} ) {
126 0 ▶ if ( ref $entry
Branch: 1 branch
BranchTrueFalseTotal
if (ref $entry and builtin::reftype($entry) eq "HASH" and exists $entry->{"share"}) 0 0 0
Condition0%0/6
ref $entry and builtin::reftype($entry) eq "HASH" and exists $entry->{"share"}
!ll&&!rl&&r
000
ref $entry and builtin::reftype($entry) eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/3
ref $entry and builtin::reftype($entry) eq "HASH" and exists $entry->{"share"}
ref $entry builtin::reftype($entry) eq "HASH" exists $entry->{"share"}
Truth table0%0/4
A and B and C
A= ref $entryB= builtin::reftype($entry) eq "HASH"C= exists $entry->{"share"}
ABCresult
0XX0
10X0
1100
1111
127 && reftype($entry) eq 'HASH'
128 && exists $entry->{share} ) {
129 0 my $files = $entry->{share};
130  
131 0 ▶ if ( ref $files && reftype($files) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $files and builtin::reftype($files) eq "ARRAY") 0 0 0
Condition0%0/3
ref $files and builtin::reftype($files) eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $files and builtin::reftype($files) eq "ARRAY"
ref $files builtin::reftype($files) eq "ARRAY"
Truth table0%0/3
A and B
A= ref $filesB= builtin::reftype($files) eq "ARRAY"
ABresult
0X0
100
111
132 0 foreach my $file ( @{$files} ) {
133 push @share_files, $file
134 0 ▶ if !any { $_ eq $file } @share_files;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless &any(sub { $_ eq $file; } , @share_files) 0 0 0
135 }
136 }
137  
138 next
139 0 ▶ if $share_seen;
Branch: 1 branch
BranchTrueFalseTotal
if $share_seen 0 0 0
140  
141 0 $share_seen = $TRUE;
142 0 next;
143 }
144  
145 0 push @updated, $entry;
146 }
147  
148 0 foreach my $arg (@extra_files) {
149 0 ▶ if ( $arg =~ /^-(.+)$/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^-(.+)$/msx) 0 0 0
150 0 my $remove = $1;
151 0 my @kept;
152  
153 0 foreach my $file (@share_files) {
154 0 ▶ push @kept, $file
Branch: 1 branch
BranchTrueFalseTotal
if $file ne $remove 0 0 0
155 if $file ne $remove;
156 }
157  
158 0 @share_files = @kept;
159 0 next;
160 }
161  
162 push @share_files, $arg
163 0 ▶ if !any { $_ eq $arg } @share_files;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless &any(sub { $_ eq $arg; } , @share_files) 0 0 0
164 }
165  
166 0 ▶ push @updated, { share => \@share_files }
Branch: 1 branch
BranchTrueFalseTotal
if @share_files 0 0 0
167 if @share_files;
168  
169 0 $extra = \@updated;
170 }
171  
172 0 $buildspec->{'extra-files'} = $extra;
173  
174 0 ▶ rename 'buildspec.yml', 'buildspec.yml.bak'
Branch: 1 branch
BranchTrueFalseTotal
rename "buildspec.yml", "buildspec.yml.bak" or die "ERROR: could not back up buildspec.yml\n$CPAN::Maker::Bootstrapper::Role::ExtraFiles::OS_ERROR" 0 0 0
175 or die "ERROR: could not back up buildspec.yml\n$OS_ERROR";
176  
177 eval {
178 0 YAML::Tiny::DumpFile( 'buildspec.yml', $buildspec );
179 0 return 1;
180 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { YAML::Tiny::DumpFile("buildspec.yml", $buildspec); return 1 } } or do { my $error = $CPAN::Maker::Bootstrapper::Role::ExtraFiles::EVAL_ERROR; rename "buildspec.yml.bak", "buildspec.yml" or die "ERROR: could not restore buildspec.yml\n$CPAN::Maker::Bootstrapper::Role::ExtraFiles::OS_ERROR"; die $error } 0 0 0
181 0 my $error = $EVAL_ERROR;
182  
183 0 ▶ rename 'buildspec.yml.bak', 'buildspec.yml'
Branch: 1 branch
BranchTrueFalseTotal
rename "buildspec.yml.bak", "buildspec.yml" or die "ERROR: could not restore buildspec.yml\n$CPAN::Maker::Bootstrapper::Role::ExtraFiles::OS_ERROR" 0 0 0
184 or die "ERROR: could not restore buildspec.yml\n$OS_ERROR";
185  
186 0 die $error;
187 };
188  
189 0 return $SUCCESS;
190 }
191  
192 2 1;
↑ Summary CPAN/Maker/Bootstrapper/Role/Installer.pm »