Zilla/Dist.pm

filter: Statementstmt 14.0% 21 / 150 Branchbran 0.0% 0 / 92 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 24.0% 6 / 25 Podpod 5.2% 1 / 19 totaltotal 9.3% 28 / 301 CC 56 SCAR 48.9
CC
56
Cov
8%
validate_changes
380.0
do_meta
156.0
do_changes
72.0
CRAP 132.7
↑ Summary auto/share/dist/Zilla-Dist/alias.pm »
1 1 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Zilla::Dist;
3 1 our $VERSION = '0.0.196';
4  
5 1 ▶use YAML::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Share;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use IO::All;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub new {
11 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
12 0 bless {@_}, $class;
13 }
14  
15 sub run {
16 0 ▶ my ($self, @args) = @_;
Subroutine run: not called CC=6 SCAR=37.4
Pod undocumented
17 0 ▶ @args = ('help') unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 0 0
18 0 ▶ @args = ('version') if "@args" =~ /^(-v|--version)$/;
Branch: 1 branch
BranchTrueFalseTotal
if join($", @args) =~ /^(-v|--version)$/ 0 0 0
19 0 my $cmd = lc(shift @args);
20 0 ▶ if ($cmd =~ /^(?:
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /^(?: test|install|release|update|prereqs|clean| dist|distdir|distshell|disttest| cpan|cpanshell )$/x) 0 0 0
21 test|install|release|update|prereqs|clean|
22 dist|distdir|distshell|disttest|
23 cpan|cpanshell
24 )$/x) {
25 0 unshift @args, $cmd;
26 0 $cmd = 'make';
27 }
28 0 my $method = "do_$cmd";
29 0 ▶ $self->usage, return unless $self->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($method) 0 0 0
30 0 ▶ $self->{meta} = -f 'Meta'
Branch: 1 branch
BranchTrueFalseTotal
-f 'Meta' ? : 0 0 0
31 ? YAML::XS::LoadFile('Meta')
32 : {};
33 0 $self->$method(@args);
34 }
35  
36 sub do_make {
37 0 ▶ my ($self, @args) = @_;
Subroutine do_make: not called CC=2 SCAR=17.9
Pod undocumented
38 0 my @cmd = ('make', '-f', $self->find_sharefile('Makefile'), @args);
39 0 ▶ system(@cmd) == 0
Branch: 1 branch
BranchTrueFalseTotal
system(@cmd) == 0 or die "'@{cmd}' failed: $!\n" 0 0 0
40 or die "'@cmd' failed: $!\n";
41 }
42  
43 sub do_makefile {
44 0 ▶ my ($self, @args) = @_;
Subroutine do_makefile: not called CC=1 SCAR=6.9
Pod undocumented
45 0 print $self->find_sharefile('Makefile'), "\n";
46 }
47  
48 sub do_copy {
49 0 ▶ my ($self, $file, $target) = @_;
Subroutine do_copy: not called CC=2 SCAR=17.9
Pod undocumented
50 0 ▶ $target ||= $file;
Condition0%0/3
$target ||= $file
l!l&&r!l&&!r
000
MC/DC0%0/2
$target ||= $file
$target $file
Truth table0%0/3
A ||= B
A= $targetB= $file
ABresult
1X1
011
000
51  
52 0 my $file_content = io->file($self->find_sharefile($file))->all;
53 0 io->file($target)->print($file_content);
54  
55 0 print "Zilla::Dist copied shared '$file' to '$target'\n";
56 }
57  
58 sub do_version {
59 0 ▶ my ($self, @args) = @_;
Subroutine do_version: not called CC=1 SCAR=6.9
Pod undocumented
60 0 print "$VERSION\n";
61 }
62  
63 sub update_makefile {
64 0 ▶ my ($self, $makefile_path) = @_;
Subroutine update_makefile: not called CC=1 SCAR=6.9
Pod undocumented
65 0 my $makefile_content = io->file($self->find_sharefile('Makefile'))->all;
66 0 io->file($makefile_path)->print($makefile_content);
67 }
68  
69 sub do_sharedir {
70 0 ▶ my ($self, @args) = @_;
Subroutine do_sharedir: not called CC=1 SCAR=6.9
Pod undocumented
71 0 print $self->find_sharedir . "\n";
72 }
73  
74 1 my $default = {
75 branch => 'master',
76 };
77 sub do_meta {
78 0 ▶ my ($self, $key) = @_;
Subroutine do_meta: not called CC=12 SCAR=50.5
Pod undocumented
79 0 my $keys = [ split '/', $key ];
80 0 my $meta = $self->{meta};
81 0 my $value = $meta;
82 0 for my $k (@$keys) {
83 0 ▶ return unless ref($value) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "HASH" 0 0 0
84 0 ▶ $value = $value->{$k} || $default->{$k};
Condition0%0/3
$value->{$k} || $default->{$k}
l!l&&r!l&&!r
000
MC/DC0%0/2
$value->{$k} || $default->{$k}
$value->{$k} $default->{$k}
Truth table0%0/3
A || B
A= $value->{$k}B= $default->{$k}
ABresult
1X1
011
000
85 0 ▶ last unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
86 }
87 0 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
88 0 ▶ if (not ref $value) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $value) { } 0 0 0
elsif (ref $value eq 'ARRAY') { } 0 0 0
elsif (ref $value eq 'HASH') { } 0 0 0
89 0 print "$value\n";
90 }
91 elsif (ref($value) eq 'ARRAY') {
92 0 print "$_\n" for @$value;
93 }
94 elsif (ref($value) eq 'HASH') {
95 0 for my $kk (sort keys %$value) {
96 0 ▶ print "$kk\n" unless $kk =~ /^(?:perl)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $kk =~ /^(?:perl)$/ 0 0 0
97 }
98 }
99 else {
100 0 print "$value\n";
101 }
102 }
103 }
104  
105 sub do_changes {
106 0 ▶ my ($self, $key, $value) = @_;
Subroutine do_changes: not called CC=8 SCAR=42.8
Pod undocumented
107 0 ▶ return if $self->{meta}{'=zild'}{no_changes_yaml};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"meta"}{"=zild"}{"no_changes_yaml"} 0 0 0
108 0 my @changes = YAML::XS::LoadFile('Changes');
109 0 $self->validate_changes(\@changes);
110 0 ▶ return unless @changes;
Branch: 1 branch
BranchTrueFalseTotal
unless @changes 0 0 0
111 0 ▶ if ($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 0 0 0
112 0 chomp $value;
113 0 ▶ die unless length $value;
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 0 0 0
114 0 ▶ my $text = io->file('Changes')->all or die;
Branch: 1 branch
BranchTrueFalseTotal
my $text = io()->file("Changes")->all or die 0 0 0
115 0 my $line = sprintf "%-8s %s", "$key:", $value;
116 0 ▶ $text =~ s/^$key:.*/$line/m or die;
Branch: 1 branch
BranchTrueFalseTotal
$text =~ s/^$key:.*/$line/m or die 0 0 0
117 0 io->file('Changes')->print($text);
118 }
119 else {
120 0 ▶ $value = $changes[0]{$key} or return;
Branch: 1 branch
BranchTrueFalseTotal
$value = $changes[0]{$key} or return 0 0 0
121 0 print "$value\n";
122 }
123 }
124  
125 sub error {
126 0 ▶ die "Error: $_[0]\n";
Subroutine error: not called CC=1 SCAR=6.9
Pod undocumented
127 }
128  
129 sub validate_changes {
130 0 ▶ my ($self, $changes) = @_;
Subroutine validate_changes: not called CC=19 SCAR=59.4
Pod undocumented
131 0 ▶ return if $self->{meta}{'=zild'}{no_changes_yaml};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"meta"}{"=zild"}{"no_changes_yaml"} 0 0 0
132  
133 0 ▶ scalar(@$changes) or error "Changes file is empty";
Branch: 1 branch
BranchTrueFalseTotal
scalar @$changes or error("Changes file is empty") 0 0 0
134  
135 0 ▶ for (my $i = 1; $i <= @$changes; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= @$changes) 0 0 0
136 0 my $entry = $changes->[$i - 1];
137 0 ▶ ref($entry) eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
ref $entry eq "HASH" or error("Changes entry #$i is not a hash") 0 0 0
138 or error "Changes entry #$i is not a hash";
139 0 my @keys = keys %$entry;
140 0 ▶ @keys == 3
Branch: 1 branch
BranchTrueFalseTotal
@keys == 3 or error("Changes entry #$i doesn't have 3 keys") 0 0 0
141 or error "Changes entry #$i doesn't have 3 keys";
142 0 for my $key (qw(version date changes)) {
143 error "Changes entry #$i is missing field '$key'"
144 0 ▶ unless exists $entry->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $entry->{$key} 0 0 0
145 error "Changes entry #$i has undefined field '$key'"
146 0 ▶ unless defined $entry->{$key} or $key eq 'date';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entry->{$key} or $key eq "date" 0 0 0
Condition0%0/3
defined $entry->{$key} or $key eq "date"
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $entry->{$key} or $key eq "date"
defined $entry->{$key} $key eq "date"
Truth table0%0/3
A or B
A= defined $entry->{$key}B= $key eq "date"
ABresult
1X1
011
000
147 0 ▶ if (defined $entry->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $entry->{$key}) 0 0 0
148 0 ▶ if ($key eq 'changes') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq 'changes') { } 0 0 0
149 error "Changes entry #$i field '$key' should be an array"
150 0 ▶ unless ref($entry->{$key}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $entry->{$key} eq "ARRAY" 0 0 0
151 0 my $change_list = $entry->{changes};
152 0 for my $change_entry (@$change_list) {
153 0 ▶ error "Changes entry #$i has non-scalar 'changes' entry"
Branch: 1 branch
BranchTrueFalseTotal
if ref $change_entry 0 0 0
154 if ref $change_entry;
155 }
156 }
157 else {
158 error "Changes entry #$i field '$key' should be a scalar"
159 0 ▶ if ref($entry->{$key});
Branch: 1 branch
BranchTrueFalseTotal
if ref $entry->{$key} 0 0 0
160 }
161 }
162 }
163 }
164 0 ▶ if (@$changes >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$changes >= 2) 0 0 0
165 0 my $changes1 = join '%^&*', @{$changes->[0]{changes}};
166 0 my $changes2 = join '%^&*', @{$changes->[1]{changes}};
167 0 ▶ error "2 most recent Changes messages cannot be the same!"
Branch: 1 branch
BranchTrueFalseTotal
if $changes1 eq $changes2 0 0 0
168 if $changes1 eq $changes2;
169 0 my $v0 = $changes->[0]{version};
170 0 my $v1 = $changes->[1]{version};
171 0 ▶ error "latest Changes version ($v0) is not greater than previous ($v1)"
Branch: 1 branch
BranchTrueFalseTotal
unless "version"->parse($v0) > "version"->parse($v1) 0 0 0
172 unless version->parse($v0) > version->parse($v1);
173 }
174 }
175  
176 sub find_sharefile {
177 0 ▶ my ($self, $file) = @_;
Subroutine find_sharefile: not called CC=2 SCAR=17.9
Pod undocumented
178 0 my $path = $self->find_sharedir . '/' . $file;
179 0 ▶ -e $path or die "Can't find shared Zilla::Dist file '$file'";
Branch: 1 branch
BranchTrueFalseTotal
-e $path or die "Can't find shared Zilla::Dist file '${file}'" 0 0 0
180 0 return $path;
181 }
182  
183 sub find_sharedir {
184 0 ▶ my ($self) = @_;
Subroutine find_sharedir: not called CC=2 SCAR=17.9
Pod undocumented
185 0 my $sharedir = File::Share::dist_dir('Zilla-Dist');
186 0 ▶ -d $sharedir or die "Can't find Zilla::Dist share dir";
Branch: 1 branch
BranchTrueFalseTotal
-d $sharedir or die "Can't find Zilla::Dist share dir" 0 0 0
187 0 return $sharedir;
188 }
189  
190 sub do_webhooks {
191 0 ▶ my ($self) = @_;
Subroutine do_webhooks: not called CC=8 SCAR=42.8
Pod undocumented
192 0 ▶ return unless $ENV{PERL_ZILLA_DIST_GIT_HUB_WEBHOOKS};
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"PERL_ZILLA_DIST_GIT_HUB_WEBHOOKS"} 0 0 0
193 0 ▶ return unless -d '.git';
Branch: 1 branch
BranchTrueFalseTotal
unless -d ".git" 0 0 0
194 0 my $path = '.git/zilla-dist/webhooks';
195 0 my $travis = io->file("$path/travis");
196 0 my $irc = io->file("$path/irc");
197 0 for my $hook (qw(travis irc)) {
198 0 my $file = io->file("$path/$hook");
199 0 ▶ if ($file->exists) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->exists) 0 0 0
200 0 my $hook_version = $file->chomp->getline;
201 0 my $api_version = '0.0.95';
202 next if
203 0 ▶ version->parse($hook_version) >=
Branch: 1 branch
BranchTrueFalseTotal
if "version"->parse($hook_version) >= "version"->parse($api_version) 0 0 0
204 version->parse($api_version);
205 }
206 0 my $method = "webhook_command_$hook";
207 0 ▶ my $command = $self->$method or next;
Branch: 1 branch
BranchTrueFalseTotal
my $command = $self->$method or next 0 0 0
208 0 print "Running: '$command'\n";
209 0 ▶ system($command) == 0
Branch: 1 branch
BranchTrueFalseTotal
system($command) == 0 or die "Error: command failed '${command}': $!" 0 0 0
210 or die "Error: command failed '$command': $!";
211 0 io->file("$path/$hook")->assert->print($VERSION);
212 }
213 }
214  
215 sub webhook_command_travis {
216 0 ▶ my ($self) = @_;
Subroutine webhook_command_travis: not called CC=1 SCAR=6.9
Pod undocumented
217 0 return "git hub travis-enable";
218 }
219  
220 sub webhook_command_irc {
221 0 ▶ my ($self) = @_;
Subroutine webhook_command_irc: not called CC=3 SCAR=24.8
Pod undocumented
222 0 my $irc;
223 0 ▶ return unless $irc = $self->{meta}{devel}{irc};
Branch: 1 branch
BranchTrueFalseTotal
unless $irc = $self->{"meta"}{"devel"}{"irc"} 0 0 0
224 0 ▶ return unless $irc =~ /^(\w\S*)#(\w\S*)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $irc =~ /^(\w\S*)#(\w\S*)$/ 0 0 0
225 0 return "git hub irc-enable $2 $1";
226 }
227  
228 sub do_years {
229 0 ▶ my ($self, $key, $value) = @_;
Subroutine do_years: not called CC=2 SCAR=17.9
Pod undocumented
230 0 my %hash = eval {
231 0 map {($_ => 1)} grep {$_} map {
232 0 $_->{date} =~ /(\d{4})/;
233 0 $1;
234 } (YAML::XS::LoadFile('Changes'));
235 };
236 0 ▶ return if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
237 0 print join(' ', sort keys %hash) . "\n";
238 }
239  
240 sub usage {
241 0 ▶ print <<'...';
Subroutine usage: not called CC=1 SCAR=6.9
Pod undocumented
242  
243 Usage:
244  
245 zild make <rule> # Run `make <rule>` with Zilla::Dist Makefile
246 zild meta <key> # Print Meta value for a key
247 zild copy <file> <dest> # Copy a shared file
248 zild version # Print Zilla::Dist version
249  
250 The following commands are aliases for `zild make <cmd>`
251  
252 zild test zild dist zild cpan
253 zild install zild distdir zild cpanshell
254 zild release zild distshell
255 zild update zild disttest
256 zild clean
257  
258 Internal commands issued by the Makefile:
259  
260 zild sharedir # Print the location of the Zilla::Dist share dir
261 zild makefile # Print the location of the Zilla::Dist 'Makefile'
262 zild changes <key> [<value>]
263  
264 ...
265 }
266  
267 1 1;
↑ Summary auto/share/dist/Zilla-Dist/alias.pm »