| 1 |
package CPANSA::DB; |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
|
| 5 |
=encoding utf8 |
| 6 |
|
| 7 |
=head1 The build file for CPANSA::DB |
| 8 |
|
| 9 |
This build file is a modulino; it works as both a build script and |
| 10 |
a module. |
| 11 |
|
| 12 |
To build the distribution, run this file normally: |
| 13 |
|
| 14 |
% perl Makefile.PL |
| 15 |
|
| 16 |
But, it's more interesting than that. You can load it with C<require> |
| 17 |
and call C<arguments> to get the data structure it passes to |
| 18 |
C<WriteMakefile>: |
| 19 |
|
| 20 |
my $package = require '/path/to/Makefile.PL'; |
| 21 |
my $arguments = $package->arguments; |
| 22 |
|
| 23 |
Note that C<require>-ing a file makes an entry in C<%INC> for exactly |
| 24 |
that name. If you try to C<require> another file with the same name, |
| 25 |
even from a different path, C<require> thinks it has already loaded |
| 26 |
the file. As such, I recommend you always require the full path to the |
| 27 |
file. |
| 28 |
|
| 29 |
The return value of the C<require> is a package name (in this case, |
| 30 |
the name of the main module. Use that to call the C<arguments> method. |
| 31 |
|
| 32 |
Even if this distribution needs a higher version of Perl, this bit |
| 33 |
only needs v5.8. You can play with the data structure with a primitive |
| 34 |
Perl. |
| 35 |
|
| 36 |
=cut |
| 37 |
|
| 38 |
use File::Spec::Functions qw(catfile); |
| 39 |
|
| 40 |
my $module = __PACKAGE__; |
| 41 |
( my $dist = $module ) =~ s/::/-/g; |
| 42 |
|
| 43 |
my $github = 'https://github.com/briandfoy/cpan-security-advisory'; |
| 44 |
my $main_file = catfile( 'lib', split /::/, "$module.pm" ); |
| 45 |
|
| 46 |
my %WriteMakefile = ( |
| 47 |
'MIN_PERL_VERSION' => '5.020', |
| 48 |
|
| 49 |
'NAME' => $module, |
| 50 |
'ABSTRACT_FROM' => $main_file, |
| 51 |
'VERSION_FROM' => $main_file, |
| 52 |
'LICENSE' => 'artistic_2', |
| 53 |
'AUTHOR' => 'brian d foy <[email protected]>', |
| 54 |
|
| 55 |
'PM' => { |
| 56 |
'lib/CPAN/Audit/DB.pm' => '$(INST_LIB)/CPAN/Audit/DB.pm', |
| 57 |
'lib/CPANSA/DB.pm' => '$(INST_LIB)/CPANSA/DB.pm', |
| 58 |
}, |
| 59 |
|
| 60 |
'CONFIGURE_REQUIRES' => { |
| 61 |
'ExtUtils::MakeMaker' => '6.64', |
| 62 |
'File::Spec::Functions' => '0', |
| 63 |
}, |
| 64 |
|
| 65 |
'BUILD_REQUIRES' => { |
| 66 |
}, |
| 67 |
|
| 68 |
# also update cpanfile because cpanm will ignore this since |
| 69 |
# cpanfile exists |
| 70 |
'TEST_REQUIRES' => { |
| 71 |
'Test::More' => '1', |
| 72 |
'YAML::XS' => '0', |
| 73 |
}, |
| 74 |
|
| 75 |
'PREREQ_PM' => { |
| 76 |
'Carp' => '0', |
| 77 |
}, |
| 78 |
|
| 79 |
'META_MERGE' => { |
| 80 |
'meta-spec' => { version => 2 }, |
| 81 |
resources => { |
| 82 |
repository => { |
| 83 |
type => 'git', |
| 84 |
url => $github, |
| 85 |
web => $github, |
| 86 |
}, |
| 87 |
bugtracker => { |
| 88 |
web => "$github/issues", |
| 89 |
}, |
| 90 |
homepage => $github, |
| 91 |
}, |
| 92 |
}, |
| 93 |
|
| 94 |
'clean' => { FILES => "$dist-* t/.last_run perl-cve-atom.xml" }, |
| 95 |
); |
| 96 |
|
| 97 |
sub arguments { \%WriteMakefile } |
| 98 |
|
| 99 |
do_it() unless caller; |
| 100 |
sub do_it { |
| 101 |
my $MM ='ExtUtils::MakeMaker'; |
| 102 |
my $MM_version = |
| 103 |
eval{ "$MM " . $WriteMakefile{'CONFIGURE_REQUIRES'}{'ExtUtils::MakeMaker'} } |
| 104 |
|| |
| 105 |
"$MM 6.64"; |
| 106 |
eval "use $MM_version; 1" or die "Could not load $MM_version: $@"; |
| 107 |
eval "use Test::Manifest 1.21"; |
| 108 |
|
| 109 |
my $arguments = arguments(); |
| 110 |
my $minimum_perl = $arguments->{MIN_PERL_VERSION} || '5.008'; |
| 111 |
eval "require $minimum_perl;" or die $@; |
| 112 |
|
| 113 |
WriteMakefile( %$arguments ); |
| 114 |
} |
| 115 |
|
| 116 |
BEGIN { |
| 117 |
# remove the useless default `help` target so I can make my own |
| 118 |
use ExtUtils::MM_Unix; |
| 119 |
no warnings 'redefine'; |
| 120 |
|
| 121 |
sub ExtUtils::MM_Unix::top_targets { |
| 122 |
# --- Target Sections --- |
| 123 |
|
| 124 |
my($self) = shift; |
| 125 |
my(@m); |
| 126 |
|
| 127 |
push @m, $self->all_target, "\n" unless $self->{SKIPHASH}{'all'}; |
| 128 |
|
| 129 |
push @m, sprintf <<'EOF'; |
| 130 |
pure_all :: config pm_to_blib subdirs linkext |
| 131 |
$(NOECHO) $(NOOP) |
| 132 |
|
| 133 |
subdirs :: $(MYEXTLIB) |
| 134 |
$(NOECHO) $(NOOP) |
| 135 |
|
| 136 |
config :: $(FIRST_MAKEFILE) blibdirs |
| 137 |
$(NOECHO) $(NOOP) |
| 138 |
EOF |
| 139 |
|
| 140 |
push @m, ' |
| 141 |
$(O_FILES) : $(H_FILES) |
| 142 |
' if @{$self->{O_FILES} || []} && @{$self->{H} || []}; |
| 143 |
|
| 144 |
# push @m, q{ |
| 145 |
# help : |
| 146 |
# perldoc ExtUtils::MakeMaker |
| 147 |
#}; |
| 148 |
|
| 149 |
join('',@m); |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
} |
| 155 |
|
| 156 |
BEGIN { |
| 157 |
use ExtUtils::MM_Any; |
| 158 |
no warnings qw(redefine); |
| 159 |
|
| 160 |
# get rid of the warning about README.pod, because I'm using it. |
| 161 |
# It's also in INSTALL.SKIP |
| 162 |
sub ExtUtils::MM_Any::libscan { |
| 163 |
my($self,$path) = @_; |
| 164 |
|
| 165 |
my($dirs,$file) = ($self->splitpath($path))[1,2]; |
| 166 |
return '' if grep /^(?:RCS|CVS|SCCS|\.svn|_darcs)$/, |
| 167 |
$self->splitdir($dirs), $file; |
| 168 |
|
| 169 |
return $path; |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
sub MY::postamble { |
| 174 |
return <<'POSTAMBLE'; |
| 175 |
GENERATED=t/.last_run perl-cve-atom.xml generated_reports |
| 176 |
CVE_FEED_FILE=perl-cve-atom.xml |
| 177 |
|
| 178 |
.PHONY: invert |
| 179 |
invert: ## turn the external_reports into CPANSA-style reports |
| 180 |
$(PERL) util/invert-third-party.pl |
| 181 |
|
| 182 |
.PHONY: lint |
| 183 |
lint: invert ## lint the reports |
| 184 |
$(PERL) util/lint_reports |
| 185 |
|
| 186 |
.PHONY: generate |
| 187 |
generate: invert ## recreate the data files |
| 188 |
$(PERL) util/generate -o $@ |
| 189 |
|
| 190 |
.PHONY: feed |
| 191 |
feed: $(CVE_FEED_FILE) |
| 192 |
|
| 193 |
$(CVE_FEED_FILE): |
| 194 |
$(PERL) util/make_feed > $@ |
| 195 |
|
| 196 |
.PHONY: review |
| 197 |
review: |
| 198 |
(cd apps/review_queue; morbo script/review_queue) |
| 199 |
|
| 200 |
.PHONY: test_yaml |
| 201 |
test_yaml: ## test all YAML files |
| 202 |
env TEST_CHANGED_ONLY=0 prove -Ilib -b -r xt |
| 203 |
|
| 204 |
###################################################################### |
| 205 |
# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html |
| 206 |
.PHONY: help ## Show all the Makefile targets with descriptions |
| 207 |
help: ## show a list of targets |
| 208 |
@grep -E '^[a-zA-Z][/a-zA-Z0-9_.-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' |
| 209 |
|
| 210 |
POSTAMBLE |
| 211 |
} |
| 212 |
|
| 213 |
no warnings; |
| 214 |
__PACKAGE__; |