| 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"} // []
MC/DC0%0/1
$buildspec->{"extra-files"} // []
$buildspec->{"extra-files"}
Truth table0%0/2
A
A= $buildspec->{"extra-files"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | foreach my $entry ( @{$extra} ) { | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ( !ref $entry ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | print "$entry\n"; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | next | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if reftype($entry) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | foreach my $section ( keys %{$entry} ) { | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $files = $entry->{$section}; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ( !ref $files ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | print "$files\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $files and $files ne ""
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 ""
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | if defined $files && $files ne q{}; | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | next | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if reftype($files) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | foreach my $file ( @{$files} ) { | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | print "$file\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $file and not ref $file and $file ne ""
defined $file and not ref $file
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 ""
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | die "ERROR: usage cmb extra-files [path file...]\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | if !@extra_files; | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | $path = q{.} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | die "ERROR: file not found - make sure '$file' exists before adding to buildspec.yml\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | if !-f $file; | ||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ( $path eq q{.} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my @updated; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | foreach my $entry ( @{$extra} ) { | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ( ref $entry ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | } @extra_files; | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | push @updated, $entry | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | if !$remove; | ||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | foreach my $file (@extra_files) { | |||||||||||||||||||||||||||||||||||||||||
| 105 | next | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if $file =~ /^-/xsm; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | next | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if any { !ref $_ && $_ eq $file } @updated; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
ref $entry and builtin::reftype($entry) eq "HASH" and exists $entry->{"share"}
ref $entry and builtin::reftype($entry) eq "HASH"
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
ref $files and builtin::reftype($files) eq "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | next | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | if $share_seen; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | push @updated, { share => \@share_files } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my $error = $EVAL_ERROR; | |||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | rename 'buildspec.yml.bak', 'buildspec.yml' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||||||