Zilla/Dist.pm

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