/usr/share/perl5/Dist/Zilla/Role/PrereqScanner.pm is in libdist-zilla-perl 6.010-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | package Dist::Zilla::Role::PrereqScanner 6.010;
# ABSTRACT: automatically extract prereqs from your modules
use Moose::Role;
with(
'Dist::Zilla::Role::FileFinderUser' => {
default_finders => [ ':InstallModules', ':ExecFiles' ],
},
'Dist::Zilla::Role::FileFinderUser' => {
method => 'found_test_files',
finder_arg_names => [ 'test_finder' ],
default_finders => [ ':TestFiles' ],
},
'Dist::Zilla::Role::FileFinderUser' => {
method => 'found_configure_files',
finder_arg_names => [ 'configure_finder' ],
default_finders => [],
},
'Dist::Zilla::Role::FileFinderUser' => {
method => 'found_develop_files',
finder_arg_names => [ 'develop_finder' ],
default_finders => [ ':ExtraTestFiles' ],
},
);
use MooseX::Types;
#pod =attr finder
#pod
#pod This is the name of a L<FileFinder|Dist::Zilla::Role::FileFinder>
#pod whose files will be scanned to determine runtime prerequisites. It
#pod may be specified multiple times. The default value is
#pod C<:InstallModules> and C<:ExecFiles>.
#pod
#pod =attr test_finder
#pod
#pod Just like C<finder>, but for test-phase prerequisites. The default
#pod value is C<:TestFiles>.
#pod
#pod =attr configure_finder
#pod
#pod Just like C<finder>, but for configure-phase prerequisites. There is
#pod no default value; AutoPrereqs will not determine configure-phase
#pod prerequisites unless you set configure_finder.
#pod
#pod =attr develop_finder
#pod
#pod Just like <finder>, but for develop-phase prerequisites. The default value
#pod is C<:ExtraTestFiles>.
#pod
#pod =attr skips
#pod
#pod This is an arrayref of regular expressions, derived from all the 'skip' lines
#pod in the configuration. Any module names matching any of these regexes will not
#pod be registered as prerequisites.
#pod
#pod =cut
has skips => (
is => 'ro',
isa => 'ArrayRef[Str]',
);
around mvp_multivalue_args => sub {
my ($orig, $self) = @_;
($self->$orig, 'skips')
};
around mvp_aliases => sub {
my ($orig, $self) = @_;
my $aliases = $self->$orig;
$aliases->{skip} = 'skips';
return $aliases
};
requires 'scan_file_reqs';
sub scan_prereqs {
my $self = shift;
require CPAN::Meta::Requirements;
require List::Util;
List::Util->VERSION(1.45); # uniq
# not a hash, because order is important
my @sets = (
# phase => file finder method
[ configure => 'found_configure_files' ], # must come before runtime
[ runtime => 'found_files' ],
[ test => 'found_test_files' ],
[ develop => 'found_develop_files' ],
);
my %reqs_by_phase;
my %runtime_final;
my @modules;
for my $fileset (@sets) {
my ($phase, $method) = @$fileset;
my $req = CPAN::Meta::Requirements->new;
my $files = $self->$method;
foreach my $file (@$files) {
# skip binary files
next if $file->is_bytes;
# parse only perl files
next unless $file->name =~ /\.(?:pm|pl|t|psgi)$/i
|| $file->content =~ /^#!(?:.*)perl(?:$|\s)/;
# RT#76305 skip extra tests produced by ExtraTests plugin
next if $file->name =~ m{^t/(?:author|release)-[^/]*\.t$};
# store module name, to trim it from require list later on
my @this_thing = $file->name;
# t/lib/Foo.pm is treated as providing t::lib::Foo, lib::Foo, and Foo
if ($this_thing[0] =~ /^t/) {
push @this_thing, ($this_thing[0]) x 2;
$this_thing[1] =~ s{^t/}{};
$this_thing[2] =~ s{^t/lib/}{};
} else {
$this_thing[0] =~ s{^lib/}{};
}
s{\.pm$}{} for @this_thing;
s{/}{::}g for @this_thing;
# this is a bunk heuristic and can still capture strings from pod - the
# proper thing to do is grab all packages from Module::Metadata
push @this_thing, $file->content =~ /^[^#]*?(?:^|\s)package\s+([^\s;#]+)/mg;
push @modules, @this_thing;
# parse a file, and merge with existing prereqs
$self->log_debug([ 'scanning %s for %s prereqs', $file->name, $phase ]);
my $file_req = $self->scan_file_reqs($file);
$req->add_requirements($file_req);
}
# remove prereqs from skiplist
for my $skip (@{ $self->skips || [] }) {
my $re = qr/$skip/;
foreach my $k ($req->required_modules) {
$req->clear_requirement($k) if $k =~ $re;
}
}
# remove prereqs shipped with current dist
if (@modules) {
$self->log_debug([
'excluding local packages: %s',
sub { join(', ', List::Util::uniq(@modules)) } ]
)
}
$req->clear_requirement($_) for @modules;
$req->clear_requirement($_) for qw(Config DB Errno NEXT Pod::Functions); # never indexed
# we're done, return what we've found
my %got = %{ $req->as_string_hash };
if ($phase eq 'runtime') {
%runtime_final = %got;
} else {
# do not test-require things required for runtime
delete $got{$_} for
grep { exists $got{$_} and $runtime_final{$_} ge $got{$_} }
keys %runtime_final;
}
$reqs_by_phase{$phase} = \%got;
}
return \%reqs_by_phase
}
1;
=pod
=encoding UTF-8
=head1 NAME
Dist::Zilla::Role::PrereqScanner - automatically extract prereqs from your modules
=head1 VERSION
version 6.010
=head1 ATTRIBUTES
=head2 finder
This is the name of a L<FileFinder|Dist::Zilla::Role::FileFinder>
whose files will be scanned to determine runtime prerequisites. It
may be specified multiple times. The default value is
C<:InstallModules> and C<:ExecFiles>.
=head2 test_finder
Just like C<finder>, but for test-phase prerequisites. The default
value is C<:TestFiles>.
=head2 configure_finder
Just like C<finder>, but for configure-phase prerequisites. There is
no default value; AutoPrereqs will not determine configure-phase
prerequisites unless you set configure_finder.
=head2 develop_finder
Just like <finder>, but for develop-phase prerequisites. The default value
is C<:ExtraTestFiles>.
=head2 skips
This is an arrayref of regular expressions, derived from all the 'skip' lines
in the configuration. Any module names matching any of these regexes will not
be registered as prerequisites.
=head1 SEE ALSO
L<Dist::Zilla::Plugin::AutoPrereqs>.
=head1 CREDITS
The role was provided by Olivier Mengué (DOLMEN) and Philippe Bruhat (BOOK) at Perl QA Hackathon 2016
(but it is just a refactor of the AutoPrereqs plugin).
=head1 AUTHOR
Ricardo SIGNES 😏 <rjbs@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Ricardo SIGNES.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
__END__
#pod =head1 SEE ALSO
#pod
#pod L<Dist::Zilla::Plugin::AutoPrereqs>.
#pod
#pod =head1 CREDITS
#pod
#pod The role was provided by Olivier Mengué (DOLMEN) and Philippe Bruhat (BOOK) at Perl QA Hackathon 2016
#pod (but it is just a refactor of the AutoPrereqs plugin).
#pod
#pod =cut
|