| 1 | package Dist::Zilla::Plugin::CPANFile 6.040; | ||||||||||||
| 2 | # ABSTRACT: produce a cpanfile prereqs file | ||||||||||||
| 3 | |||||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 2 | with 'Dist::Zilla::Role::FileGatherer'; | |||||||||||
| 6 | |||||||||||||
| 7 | 2 | ▶ | use Dist::Zilla::Pragmas; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 2 | ▶ | use namespace::autoclean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 2 | ▶ | use Dist::Zilla::File::FromCode; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | #pod =head1 SYNOPSIS | ||||||||||||
| 14 | #pod | ||||||||||||
| 15 | #pod # dist.ini | ||||||||||||
| 16 | #pod [CPANFile] | ||||||||||||
| 17 | #pod | ||||||||||||
| 18 | #pod =head1 DESCRIPTION | ||||||||||||
| 19 | #pod | ||||||||||||
| 20 | #pod This plugin will add a F<cpanfile> file to the distribution. | ||||||||||||
| 21 | #pod | ||||||||||||
| 22 | #pod =attr filename | ||||||||||||
| 23 | #pod | ||||||||||||
| 24 | #pod If given, parameter allows you to specify an alternate name for the generated | ||||||||||||
| 25 | #pod file. It defaults, of course, to F<cpanfile>. | ||||||||||||
| 26 | #pod | ||||||||||||
| 27 | #pod # dist.ini | ||||||||||||
| 28 | #pod [CPANFile] | ||||||||||||
| 29 | #pod filename = dzil-generated-cpanfile | ||||||||||||
| 30 | #pod | ||||||||||||
| 31 | #pod =attr comment | ||||||||||||
| 32 | #pod | ||||||||||||
| 33 | #pod If given, override the default C<cpanfile> header comment with your own. The default comment | ||||||||||||
| 34 | #pod explains that this file was generated by Dist::Zilla and tells users to edit the dist.ini | ||||||||||||
| 35 | #pod file to change prereqs | ||||||||||||
| 36 | #pod | ||||||||||||
| 37 | #pod # dist.ini | ||||||||||||
| 38 | #pod [CPANFile] | ||||||||||||
| 39 | #pod comment = This file is generated by Dist::Zilla | ||||||||||||
| 40 | #pod comment = Prereqs are detected automatically. You do not need to edit this file | ||||||||||||
| 41 | #pod | ||||||||||||
| 42 | #pod =head1 SEE ALSO | ||||||||||||
| 43 | #pod | ||||||||||||
| 44 | #pod =for :list | ||||||||||||
| 45 | #pod * L<Module::CPANfile> | ||||||||||||
| 46 | #pod * L<Carton> | ||||||||||||
| 47 | #pod * L<cpanm> | ||||||||||||
| 48 | #pod | ||||||||||||
| 49 | #pod =cut | ||||||||||||
| 50 | |||||||||||||
| 51 | 2 | has filename => ( | |||||||||||
| 52 | is => 'ro', | ||||||||||||
| 53 | isa => 'Str', | ||||||||||||
| 54 | default => 'cpanfile', | ||||||||||||
| 55 | ); | ||||||||||||
| 56 | |||||||||||||
| 57 | 4 | ▶ | sub mvp_multivalue_args { qw( comment ) } | ||||||||||
|
Subroutine
mvp_multivalue_args: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 58 | |||||||||||||
| 59 | has comment => ( | ||||||||||||
| 60 | is => 'ro', | ||||||||||||
| 61 | isa => 'ArrayRef[Str]', | ||||||||||||
| 62 | 2 | ▶ | default => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||
| 63 | [ | ||||||||||||
| 64 | 2 | ▶ | qq{This file is generated by Dist::Zilla::Plugin::CPANFile v} | ||||||||||
|
Condition50%1/2
$Dist::Zilla::Plugin::CPANFile::VERSION // "<internal>"
MC/DC0%0/1
$Dist::Zilla::Plugin::CPANFile::VERSION // "<internal>"
$Dist::Zilla::Plugin::CPANFile::VERSION
Truth table50%1/2
A
A= $Dist::Zilla::Plugin::CPANFile::VERSION
| |||||||||||||
| 65 | . ( $Dist::Zilla::Plugin::CPANFile::VERSION // '<internal>' ), | ||||||||||||
| 66 | qq{Do not edit this file directly. To change prereqs, edit the `dist.ini` file.}, | ||||||||||||
| 67 | ] | ||||||||||||
| 68 | } | ||||||||||||
| 69 | 2 | ); | |||||||||||
| 70 | |||||||||||||
| 71 | 4 | ▶ | sub _hunkify_hunky_hunk_hunks { | ||||||||||
|
Subroutine
_hunkify_hunky_hunk_hunks: called CC=2 SCAR=6.9
| |||||||||||||
| 72 | 4 | my ($self, $indent, $type, $req) = @_; | |||||||||||
| 73 | |||||||||||||
| 74 | 4 | my $str = ''; | |||||||||||
| 75 | 4 | for my $module (sort $req->required_modules) { | |||||||||||
| 76 | 8 | my $vstr = $req->requirements_for_module($module); | |||||||||||
| 77 | 8 | $str .= qq{$type "$module" => "$vstr";\n}; | |||||||||||
| 78 | } | ||||||||||||
| 79 | 4 | $str =~ s/^/' ' x $indent/egm; | |||||||||||
| 80 | 4 | return $str; | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | 4 | ▶ | sub gather_files { | ||||||||||
|
Subroutine
gather_files: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 84 | 4 | my ($self, $arg) = @_; | |||||||||||
| 85 | |||||||||||||
| 86 | 4 | my $zilla = $self->zilla; | |||||||||||
| 87 | |||||||||||||
| 88 | my $file = Dist::Zilla::File::FromCode->new({ | ||||||||||||
| 89 | name => $self->filename, | ||||||||||||
| 90 | 4 | ▶ | code => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.6
| |||||||||||||
| 91 | 4 | my $prereqs = $zilla->prereqs; | |||||||||||
| 92 | |||||||||||||
| 93 | 4 | my @types = qw(requires recommends suggests conflicts); | |||||||||||
| 94 | 4 | my @phases = qw(runtime build test configure develop); | |||||||||||
| 95 | |||||||||||||
| 96 | 4 | my $str = join "\n", ( map { "# $_" } @{ $self->comment } ), '', ''; | |||||||||||
| 97 | 4 | for my $phase (@phases) { | |||||||||||
| 98 | 20 | for my $type (@types) { | |||||||||||
| 99 | 80 | my $req = $prereqs->requirements_for($phase, $type); | |||||||||||
| 100 | 80 | ▶ | next unless $req->required_modules; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 101 | 4 | ▶ | $str .= qq[\non '$phase' => sub {\n] unless $phase eq 'runtime'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 102 | 4 | ▶ | $str .= $self->_hunkify_hunky_hunk_hunks( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 103 | ($phase eq 'runtime' ? 0 : 1), | ||||||||||||
| 104 | $type, | ||||||||||||
| 105 | $req, | ||||||||||||
| 106 | ); | ||||||||||||
| 107 | 4 | ▶ | $str .= qq[};\n] unless $phase eq 'runtime'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 108 | } | ||||||||||||
| 109 | } | ||||||||||||
| 110 | |||||||||||||
| 111 | 4 | return $str; | |||||||||||
| 112 | }, | ||||||||||||
| 113 | 4 | }); | |||||||||||
| 114 | |||||||||||||
| 115 | 4 | $self->add_file($file); | |||||||||||
| 116 | 4 | return; | |||||||||||
| 117 | } | ||||||||||||
| 118 | |||||||||||||
| 119 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 120 | 2 | 1; | |||||||||||
| 121 | |||||||||||||
| 122 | __END__ | ||||||||||||