.github/dzil-binary/require-gate.pl

filter: Statementstmt 100% 36 / 36 Branchbran 87.5% 14 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 96.4% 55 / 57 CC 9 SCAR 14.4
CC
9
Cov
96%
missing
6.0
main
4.0
BEGIN
1.0
CRAP 4.2
« blib/lib/Dist/Zilla/Plugin/Author/GETTY/Binary.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/Author/GETTY/GiteaMeta.pm »
1 #!/usr/bin/env perl
2 # Every module the dist declares in `require` must be inside the binary.
3 # require-gate.pl <binary> <Module|Glob::*>...
4 package DzilBinary::RequireGate;
5 45 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 45 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 45 ▶use Archive::Zip qw( AZ_OK );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 74 ▶sub missing {
Subroutine missing: called CC=6 SCAR=17.9
10 74 my ($archive, @specs) = @_;
11 74 my $zip = Archive::Zip->new;
12 74 ▶ die "cannot read $archive as an archive\n" unless $zip->read($archive) == AZ_OK;
Branch: 1 branch
BranchTrueFalseTotal
unless $zip->read($archive) == 0 1 73 74
13 73 my @names = $zip->memberNames;
14 73 my %have = map { $_ => 1 } @names;
15 73 my @missing;
16 73 for my $spec (@specs) {
17 133 ▶ if ($spec =~ /\A(.+)::\*\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec =~ /\A(.+)::\*\z/) { } 40 93 133
18 40 (my $prefix = "lib/$1/") =~ s{::}{/}g;
19 40 ▶ push @missing, "$prefix*" unless grep { /\A\Q$prefix\E.+\.pm\z/ } @names;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {/\A\Q$prefix\E.+\.pm\z/;} @names 5 35 40
20 }
21 else {
22 93 (my $path = "lib/$spec.pm") =~ s{::}{/}g;
23 93 ▶ push @missing, $path unless $have{$path};
Branch: 1 branch
BranchTrueFalseTotal
unless $have{$path} 32 61 93
24 }
25 }
26 73 return @missing;
27 }
28  
29 16 ▶sub main {
Subroutine main: called CC=4 SCAR=13.9
30 16 my ($archive, @specs) = @_;
31 16 ▶ die "usage: require-gate.pl <binary> <module|Glob::*>...\n" unless defined $archive;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $archive 0 16 16
32 16 my @m = eval { missing($archive, @specs) };
33 16 ▶ if ($@) { print STDERR $@; return 2 }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 15 16
34 15 ▶ return 0 unless @m;
Branch: 1 branch
BranchTrueFalseTotal
unless @m 7 8 15
35 8 print STDERR "required but missing from $archive:\n", map({ " $_\n" } @m);
36 8 return 1;
37 }
38  
39 16 ▶exit main(@ARGV) unless caller;
Branch: 1 branch
BranchTrueFalseTotal
unless caller 16 0 16
40 1;
« blib/lib/Dist/Zilla/Plugin/Author/GETTY/Binary.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/Author/GETTY/GiteaMeta.pm »