« 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 20 | } | ||||||||||
| 21 | else { | ||||||||||
| 22 | 93 | (my $path = "lib/$spec.pm") =~ s{::}{/}g; | |||||||||
| 23 | 93 | ▶ | push @missing, $path unless $have{$path}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 32 | 16 | my @m = eval { missing($archive, @specs) }; | |||||||||
| 33 | 16 | ▶ | if ($@) { print STDERR $@; return 2 } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 15 | ▶ | return 0 unless @m; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 40 | 1; | ||||||||||