| 1 | package Pod::Weaver::Section::Requirements; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: generate POD with the runtime requirements | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use v5.24; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 11 | with 'Pod::Weaver::Role::Section'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use List::Util qw( first ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use MooseX::MungeHas; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use Perl::PrereqScanner 1.024; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use Pod::Elemental::Element::Nested; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 11 | ▶ | use Pod::Elemental::Element::Pod5::Command; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 11 | ▶ | use Pod::Elemental::Element::Pod5::Ordinary; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use Pod::Elemental::Element::Pod5::Region; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 11 | ▶ | use Types::Common qw( Bool NonEmptySimpleStr SimpleStr ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 11 | ▶ | use experimental qw( lexical_subs signatures ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 11 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 11 | our $VERSION = 'v0.6.0'; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 11 | has header => ( | |||||||||||||||||||||||||||
| 27 | is => 'rw', | ||||||||||||||||||||||||||||
| 28 | isa => NonEmptySimpleStr, | ||||||||||||||||||||||||||||
| 29 | default => 'REQUIREMENTS', | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 11 | has region => ( | |||||||||||||||||||||||||||
| 34 | is => 'rw', | ||||||||||||||||||||||||||||
| 35 | isa => SimpleStr, | ||||||||||||||||||||||||||||
| 36 | default => '', | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 11 | has metafile => ( | |||||||||||||||||||||||||||
| 41 | is => 'rw', | ||||||||||||||||||||||||||||
| 42 | isa => SimpleStr, | ||||||||||||||||||||||||||||
| 43 | default => 'cpanfile', | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 11 | has all_modules => ( | |||||||||||||||||||||||||||
| 48 | is => 'rw', | ||||||||||||||||||||||||||||
| 49 | isa => Bool, | ||||||||||||||||||||||||||||
| 50 | default => 0, | ||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 11 | has guess_prereqs => ( | |||||||||||||||||||||||||||
| 55 | is => 'rw', | ||||||||||||||||||||||||||||
| 56 | isa => Bool, | ||||||||||||||||||||||||||||
| 57 | default => 0, | ||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 11 | ▶ | sub weave_section( $self, $document, $input ) { | ||||||||||||||||||||||||||
|
Subroutine
weave_section: called CC=13 SCAR=26.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 11 | my $zilla = $input->{zilla}; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 11 | ▶ | unless ($zilla) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | $self->log_fatal("missing zilla argument"); | |||||||||||||||||||||||||||
| 66 | 0 | return; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 11 | ▶ | if ( $zilla && !$self->all_modules ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$zilla and not $self->all_modules
MC/DC0%0/2
$zilla and not $self->all_modules
$zilla
not $self->all_modules
Truth table33%1/3
A and not(B)
A= $zillaB= not $self->all_modules
| |||||||||||||||||||||||||||||
| 70 | 11 | ▶ | return if $zilla->main_module->name ne $input->{filename}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 11 | ▶ | if ( my $stash = $zilla ? $zilla->stash_named('%PodWeaver') : undef ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 74 | 1 | $stash->merge_stashed_config($self); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 11 | my $runtime = $zilla->prereqs->as_string_hash->{runtime}{requires}; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 11 | ▶ | if ( !$runtime && $self->guess_prereqs ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $runtime and $self->guess_prereqs
MC/DC50%1/2
not $runtime and $self->guess_prereqs
not $runtime
$self->guess_prereqs
Truth table66%2/3
not(A) and B
A= not $runtimeB= $self->guess_prereqs
| |||||||||||||||||||||||||||||
| 80 | 1 | my $scanner = Perl::PrereqScanner->new; | |||||||||||||||||||||||||||
| 81 | 1 | my $prereqs = $scanner->scan_ppi_document($input->{ppi_document} ); | |||||||||||||||||||||||||||
| 82 | 1 | $runtime = $prereqs->as_string_hash; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 11 | ▶ | return unless $runtime; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 47 | ▶ | my sub _module_link($name) { | ||||||||||||||||||||||||||
|
Subroutine
_module_link: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 88 | 47 | my $version = $runtime->{$name}; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 47 | my $text = "L<${name}>"; | |||||||||||||||||||||||||||
| 91 | 47 | ▶ | $text .= " version ${version} or later" if $version; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | return ( | ||||||||||||||||||||||||||||
| 94 | 47 | Pod::Elemental::Element::Pod5::Command->new( | |||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||
| 96 | command => 'item', | ||||||||||||||||||||||||||||
| 97 | content => '*' | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | ), | ||||||||||||||||||||||||||||
| 100 | Pod::Elemental::Element::Pod5::Ordinary->new( { content => $text } ) | ||||||||||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 11 | ▶ | my @links = ( map { _module_link($_) } sort keys $runtime->%* ) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 11 | my $res = Pod::Elemental::Element::Nested->new( | |||||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||||
| 108 | type => 'command', | ||||||||||||||||||||||||||||
| 109 | command => 'head1', | ||||||||||||||||||||||||||||
| 110 | content => $self->header, | ||||||||||||||||||||||||||||
| 111 | children => [ | ||||||||||||||||||||||||||||
| 112 | Pod::Elemental::Element::Pod5::Ordinary->new( | ||||||||||||||||||||||||||||
| 113 | { content => "This module lists the following modules as runtime dependencies:" } | ||||||||||||||||||||||||||||
| 114 | ), | ||||||||||||||||||||||||||||
| 115 | Pod::Elemental::Element::Pod5::Command->new( | ||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||
| 117 | command => 'over', | ||||||||||||||||||||||||||||
| 118 | content => '4', | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | ), | ||||||||||||||||||||||||||||
| 121 | @links, | ||||||||||||||||||||||||||||
| 122 | Pod::Elemental::Element::Pod5::Command->new( | ||||||||||||||||||||||||||||
| 123 | { | ||||||||||||||||||||||||||||
| 124 | command => 'back', | ||||||||||||||||||||||||||||
| 125 | content => '', | ||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | ) | ||||||||||||||||||||||||||||
| 128 | ] | ||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 11 | my %files = map { $_->name => 1 } $zilla->files->@*; | |||||||||||||||||||||||||||
| 133 | 11 | my @metafiles = grep { $_ ne '' } ( $self->metafile, qw( cpm.yml cpanfile META.json META.yml ) ); | |||||||||||||||||||||||||||
| 134 | 11 | ▶ | if ( my $file = first { $files{$_} } @metafiles ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 7 | push $res->children->@*, | |||||||||||||||||||||||||||
| 136 | Pod::Elemental::Element::Pod5::Ordinary->new( | ||||||||||||||||||||||||||||
| 137 | { content => "See the F<${file}> file for the full list of prerequisites." } ); | ||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 11 | ▶ | if ( my $name = $self->region ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 2 | push $document->children->@*, | |||||||||||||||||||||||||||
| 143 | Pod::Elemental::Element::Pod5::Region->new( | ||||||||||||||||||||||||||||
| 144 | { | ||||||||||||||||||||||||||||
| 145 | format_name => $name =~ s/^://r, | ||||||||||||||||||||||||||||
| 146 | is_pod => 1, | ||||||||||||||||||||||||||||
| 147 | content => '', | ||||||||||||||||||||||||||||
| 148 | children => [$res], | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | ); | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | else { | ||||||||||||||||||||||||||||
| 154 | 9 | push $document->children->@*, $res; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 11 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | __END__ | ||||||||||||||||||||||||||||