« blib/lib/Dist/Zilla/Plugin/ShareDir.pm
↑ Summary
blib/lib/Dist/Zilla/Role/MintingProfile/ShareDir.pm »
| 1 | package Dist::Zilla::Plugin::AutoPrereqs 6.040; | ||||||||||
| 2 | # ABSTRACT: automatically extract prereqs from your modules | ||||||||||
| 3 | |||||||||||
| 4 | 6 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 6 | with( | |||||||||
| 6 | 'Dist::Zilla::Role::PrereqScanner', | ||||||||||
| 7 | 'Dist::Zilla::Role::PrereqSource', | ||||||||||
| 8 | 'Dist::Zilla::Role::PPI', | ||||||||||
| 9 | ); | ||||||||||
| 10 | |||||||||||
| 11 | 6 | ▶ | use Dist::Zilla::Pragmas; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 6 | ▶ | use Moose::Util::TypeConstraints 'enum'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 6 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | #pod =head1 SYNOPSIS | ||||||||||
| 17 | #pod | ||||||||||
| 18 | #pod In your F<dist.ini>: | ||||||||||
| 19 | #pod | ||||||||||
| 20 | #pod [AutoPrereqs] | ||||||||||
| 21 | #pod skip = ^Foo|Bar$ | ||||||||||
| 22 | #pod skip = ^Other::Dist | ||||||||||
| 23 | #pod | ||||||||||
| 24 | #pod =head1 DESCRIPTION | ||||||||||
| 25 | #pod | ||||||||||
| 26 | #pod This plugin will extract loosely your distribution prerequisites from | ||||||||||
| 27 | #pod your files using L<Perl::PrereqScanner>. | ||||||||||
| 28 | #pod | ||||||||||
| 29 | #pod If some prereqs are not found, you can still add them manually with the | ||||||||||
| 30 | #pod L<Prereqs|Dist::Zilla::Plugin::Prereqs> plugin. | ||||||||||
| 31 | #pod | ||||||||||
| 32 | #pod This plugin will skip the modules shipped within your dist. | ||||||||||
| 33 | #pod | ||||||||||
| 34 | #pod B<Note>, if you have any non-Perl files in your C<t/> directory or other | ||||||||||
| 35 | #pod directories being scanned, be sure to mark those files' encoding as C<bytes> | ||||||||||
| 36 | #pod with the L<Encoding|Dist::Zilla::Plugin::Encoding> plugin so they won't be | ||||||||||
| 37 | #pod scanned: | ||||||||||
| 38 | #pod | ||||||||||
| 39 | #pod [Encoding] | ||||||||||
| 40 | #pod encoding = bytes | ||||||||||
| 41 | #pod match = ^t/data/ | ||||||||||
| 42 | #pod | ||||||||||
| 43 | #pod =attr finder | ||||||||||
| 44 | #pod | ||||||||||
| 45 | #pod This is the name of a L<FileFinder|Dist::Zilla::Role::FileFinder> | ||||||||||
| 46 | #pod whose files will be scanned to determine runtime prerequisites. It | ||||||||||
| 47 | #pod may be specified multiple times. The default value is | ||||||||||
| 48 | #pod C<:InstallModules> and C<:ExecFiles>. | ||||||||||
| 49 | #pod | ||||||||||
| 50 | #pod =attr test_finder | ||||||||||
| 51 | #pod | ||||||||||
| 52 | #pod Just like C<finder>, but for test-phase prerequisites. The default | ||||||||||
| 53 | #pod value is C<:TestFiles>. | ||||||||||
| 54 | #pod | ||||||||||
| 55 | #pod =attr configure_finder | ||||||||||
| 56 | #pod | ||||||||||
| 57 | #pod Just like C<finder>, but for configure-phase prerequisites. There is | ||||||||||
| 58 | #pod no default value; AutoPrereqs will not determine configure-phase | ||||||||||
| 59 | #pod prerequisites unless you set configure_finder. | ||||||||||
| 60 | #pod | ||||||||||
| 61 | #pod =attr develop_finder | ||||||||||
| 62 | #pod | ||||||||||
| 63 | #pod Just like C<finder>, but for develop-phase prerequisites. The default value | ||||||||||
| 64 | #pod is C<:ExtraTestFiles>. | ||||||||||
| 65 | #pod | ||||||||||
| 66 | #pod =attr skips | ||||||||||
| 67 | #pod | ||||||||||
| 68 | #pod This is an arrayref of regular expressions, derived from all the 'skip' lines | ||||||||||
| 69 | #pod in the configuration. Any module names matching any of these regexes will not | ||||||||||
| 70 | #pod be registered as prerequisites. | ||||||||||
| 71 | #pod | ||||||||||
| 72 | #pod =attr relationship | ||||||||||
| 73 | #pod | ||||||||||
| 74 | #pod The relationship used for the registered prerequisites. The default value is | ||||||||||
| 75 | #pod 'requires'; other options are 'recommends' and 'suggests'. | ||||||||||
| 76 | #pod | ||||||||||
| 77 | #pod =attr extra_scanners | ||||||||||
| 78 | #pod | ||||||||||
| 79 | #pod This is an arrayref of scanner names (as expected by L<Perl::PrereqScanner>). | ||||||||||
| 80 | #pod It will be passed as the C<extra_scanners> parameter to L<Perl::PrereqScanner>. | ||||||||||
| 81 | #pod | ||||||||||
| 82 | #pod =attr scanners | ||||||||||
| 83 | #pod | ||||||||||
| 84 | #pod This is an arrayref of scanner names (as expected by L<Perl::PrereqScanner>). | ||||||||||
| 85 | #pod If present, it will be passed as the C<scanners> parameter to | ||||||||||
| 86 | #pod L<Perl::PrereqScanner>, which means that it will replace the default list | ||||||||||
| 87 | #pod of scanners. | ||||||||||
| 88 | #pod | ||||||||||
| 89 | #pod =head1 SEE ALSO | ||||||||||
| 90 | #pod | ||||||||||
| 91 | #pod L<Prereqs|Dist::Zilla::Plugin::Prereqs>, L<Perl::PrereqScanner>. | ||||||||||
| 92 | #pod | ||||||||||
| 93 | #pod =head1 CREDITS | ||||||||||
| 94 | #pod | ||||||||||
| 95 | #pod This plugin was originally contributed by Jerome Quelin. | ||||||||||
| 96 | #pod | ||||||||||
| 97 | #pod =cut | ||||||||||
| 98 | |||||||||||
| 99 | 30 | ▶ | sub mvp_multivalue_args { qw(extra_scanners scanners) } | ||||||||
|
Subroutine
mvp_multivalue_args: called CC=1 SCAR=0.0
| |||||||||||
| 100 | 30 | ▶ | sub mvp_aliases { return { extra_scanner => 'extra_scanners', | ||||||||
|
Subroutine
mvp_aliases: called CC=1 SCAR=0.0
| |||||||||||
| 101 | scanner => 'scanners', | ||||||||||
| 102 | relationship => 'type' } } | ||||||||||
| 103 | |||||||||||
| 104 | has extra_scanners => ( | ||||||||||
| 105 | is => 'ro', | ||||||||||
| 106 | isa => 'ArrayRef[Str]', | ||||||||||
| 107 | 29 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 108 | 6 | ); | |||||||||
| 109 | |||||||||||
| 110 | 6 | has scanners => ( | |||||||||
| 111 | is => 'ro', | ||||||||||
| 112 | isa => 'ArrayRef[Str]', | ||||||||||
| 113 | predicate => 'has_scanners', | ||||||||||
| 114 | ); | ||||||||||
| 115 | |||||||||||
| 116 | |||||||||||
| 117 | has _scanner => ( | ||||||||||
| 118 | is => 'ro', | ||||||||||
| 119 | lazy => 1, | ||||||||||
| 120 | 30 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 121 | 30 | my $self = shift; | |||||||||
| 122 | |||||||||||
| 123 | 30 | require Perl::PrereqScanner; | |||||||||
| 124 | 30 | Perl::PrereqScanner->VERSION('1.016'); # don't skip "lib" | |||||||||
| 125 | |||||||||||
| 126 | 30 | ▶ | return Perl::PrereqScanner->new( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 127 | ($self->has_scanners ? (scanners => $self->scanners) : ()), | ||||||||||
| 128 | extra_scanners => $self->extra_scanners, | ||||||||||
| 129 | ) | ||||||||||
| 130 | }, | ||||||||||
| 131 | 6 | init_arg => undef, | |||||||||
| 132 | ); | ||||||||||
| 133 | |||||||||||
| 134 | 6 | has type => ( | |||||||||
| 135 | is => 'ro', | ||||||||||
| 136 | isa => enum([qw(requires recommends suggests)]), | ||||||||||
| 137 | default => 'requires', | ||||||||||
| 138 | ); | ||||||||||
| 139 | |||||||||||
| 140 | 94 | ▶ | sub scan_file_reqs { | ||||||||
|
Subroutine
scan_file_reqs: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 141 | 94 | my ($self, $file) = @_; | |||||||||
| 142 | 94 | return $self->_scanner->scan_ppi_document($self->ppi_document_for_file($file)) | |||||||||
| 143 | } | ||||||||||
| 144 | |||||||||||
| 145 | 30 | ▶ | sub register_prereqs { | ||||||||
|
Subroutine
register_prereqs: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 146 | 30 | my $self = shift; | |||||||||
| 147 | |||||||||||
| 148 | 30 | my $type = $self->type; | |||||||||
| 149 | |||||||||||
| 150 | 30 | my $reqs_by_phase = $self->scan_prereqs; | |||||||||
| 151 | 30 | ▶ | while (my ($phase, $reqs) = each %$reqs_by_phase) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 152 | 120 | $self->zilla->register_prereqs({ phase => $phase, type => $type }, %$reqs); | |||||||||
| 153 | } | ||||||||||
| 154 | } | ||||||||||
| 155 | |||||||||||
| 156 | 6 | __PACKAGE__->meta->make_immutable; | |||||||||
| 157 | 6 | 1; | |||||||||
| 158 | |||||||||||
| 159 | __END__ | ||||||||||