| 1 | package Pod::Weaver::Section::InstallationInstructions; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: generate POD with installation instructions | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use v5.24; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 10 | with 'Pod::Weaver::Role::Section'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use List::Util qw( first ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use Module::Metadata 1.000015; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use MooseX::MungeHas; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 10 | ▶ | use Pod::Elemental::Element::Nested; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 10 | ▶ | use Pod::Elemental::Element::Pod5::Command; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 10 | ▶ | use Pod::Elemental::Element::Pod5::Ordinary; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 10 | ▶ | use Pod::Elemental::Element::Pod5::Region; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 10 | ▶ | use Pod::Elemental::Element::Pod5::Verbatim; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 10 | ▶ | use Types::Common qw( Bool Enum NonEmptySimpleStr SimpleStr ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 10 | ▶ | use experimental qw( lexical_subs signatures ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 10 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 10 | our $VERSION = 'v0.6.0'; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 10 | has header => ( | |||||||||||||||||||||||||||
| 28 | is => 'rw', | ||||||||||||||||||||||||||||
| 29 | isa => NonEmptySimpleStr, | ||||||||||||||||||||||||||||
| 30 | default => 'INSTALLATION', | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 10 | has region => ( | |||||||||||||||||||||||||||
| 35 | is => 'rw', | ||||||||||||||||||||||||||||
| 36 | isa => SimpleStr, | ||||||||||||||||||||||||||||
| 37 | default => '', | ||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 10 | has builder => ( | |||||||||||||||||||||||||||
| 42 | is => 'rw', | ||||||||||||||||||||||||||||
| 43 | isa => Enum [qw( Makefile.PL Build.PL )], | ||||||||||||||||||||||||||||
| 44 | predicate => 1, | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 10 | has all_modules => ( | |||||||||||||||||||||||||||
| 49 | is => 'rw', | ||||||||||||||||||||||||||||
| 50 | isa => Bool, | ||||||||||||||||||||||||||||
| 51 | default => 0, | ||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 10 | ▶ | sub weave_section( $self, $document, $input ) { | ||||||||||||||||||||||||||
|
Subroutine
weave_section: called CC=18 SCAR=29.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 10 | my $zilla = $input->{zilla}; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 10 | ▶ | 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
| |||||||||||||||||||||||||||||
| 59 | 10 | ▶ | return if $zilla->main_module->name ne $input->{filename}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 10 | ▶ | if ( my $stash = $zilla ? $zilla->stash_named('%PodWeaver') : undef ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 63 | 1 | $stash->merge_stashed_config($self); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # TODO change to work without zilla | ||||||||||||||||||||||||||||
| 67 | 10 | my $meta = Module::Metadata->new_from_file( $zilla->main_module->name ); | |||||||||||||||||||||||||||
| 68 | 10 | my $pkg = $meta->name; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 10 | my @pod = ( | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | Pod::Elemental::Element::Pod5::Ordinary->new( | ||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||
| 74 | content => | ||||||||||||||||||||||||||||
| 75 | "The latest version of this module (along with any dependencies) can be installed from L<CPAN|https://www.cpan.org> with the C<cpan> tool that is included with Perl:" | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | ), | ||||||||||||||||||||||||||||
| 78 | Pod::Elemental::Element::Pod5::Verbatim->new( | ||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||
| 80 | content => " cpan ${pkg}", | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | ), | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | Pod::Elemental::Element::Pod5::Ordinary->new( | ||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | content => "You can also extract the distribution archive and install this module (along with any dependencies):" | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | ), | ||||||||||||||||||||||||||||
| 89 | Pod::Elemental::Element::Pod5::Verbatim->new( | ||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||
| 91 | content => " cpan .", | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | ), | ||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 10 | ▶ | my $builder = $self->has_builder ? $self->builder : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 10 | ▶ | my @files = $zilla ? $zilla->files->@* : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 10 | ▶ | if ( !$builder && $zilla ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $builder and $zilla
MC/DC50%1/2
not $builder and $zilla
not $builder
$zilla
Truth table66%2/3
not(A) and B
A= not $builderB= $zilla
| |||||||||||||||||||||||||||||
| 101 | 9 | for my $name ( qw( Build.PL Makefile.PL ) ) { | |||||||||||||||||||||||||||
| 102 | 16 | ▶ | if ( my $type = first { $_->name eq $name } @files ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 9 | $builder = $name; | |||||||||||||||||||||||||||
| 104 | 9 | last; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 10 | ▶ | if ($builder) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 10 | ▶ | my $cmd = $builder =~ /^Build/ ? "perl Build" : "make"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 10 | push @pod, ( | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | Pod::Elemental::Element::Pod5::Ordinary->new( | ||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||
| 116 | content => "You can also install this module manually using the following commands:" | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | ), | ||||||||||||||||||||||||||||
| 119 | Pod::Elemental::Element::Pod5::Verbatim->new( | ||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||
| 121 | content => <<"POD_MANUAL_INSTALL", | ||||||||||||||||||||||||||||
| 122 | perl ${builder} | ||||||||||||||||||||||||||||
| 123 | ${cmd} | ||||||||||||||||||||||||||||
| 124 | ${cmd} test | ||||||||||||||||||||||||||||
| 125 | ${cmd} install | ||||||||||||||||||||||||||||
| 126 | POD_MANUAL_INSTALL | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | ), | ||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 10 | ▶ | if ($zilla) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 10 | ▶ | my $example = $builder ? "F<${builder}> file" : "builder file such as L<Makefile.PL>"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 10 | push @pod, ( | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | Pod::Elemental::Element::Pod5::Ordinary->new( | ||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||
| 140 | content => | ||||||||||||||||||||||||||||
| 141 | "If you are working with the source repository, then it may not have a ${example}. But you can use the L<Dist::Zilla|https://dzil.org/> tool in anger to build and install this module:" | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | ), | ||||||||||||||||||||||||||||
| 144 | Pod::Elemental::Element::Pod5::Verbatim->new( | ||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||
| 146 | content => <<"POD_DZIL_INSTALL", | ||||||||||||||||||||||||||||
| 147 | dzil build | ||||||||||||||||||||||||||||
| 148 | dzil test | ||||||||||||||||||||||||||||
| 149 | dzil install --install-command="cpan ." | ||||||||||||||||||||||||||||
| 150 | POD_DZIL_INSTALL | ||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | ), | ||||||||||||||||||||||||||||
| 153 | ); | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 10 | my $also = "L<How to install CPAN modules|https://www.cpan.org/modules/INSTALL.html>"; | |||||||||||||||||||||||||||
| 158 | 10 | ▶ | if ( my $doc = first { $_->name =~ /\AINSTALL(?:\.(txt|md|mkdn))?\z/i } @files ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 5 | $also = sprintf( 'the F<%s> file included with this distribution', $doc->name ); | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 10 | push @pod, Pod::Elemental::Element::Pod5::Ordinary->new( { content => "For more information, see ${also}." } ); | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 10 | my $res = Pod::Elemental::Element::Nested->new( | |||||||||||||||||||||||||||
| 165 | { | ||||||||||||||||||||||||||||
| 166 | type => 'command', | ||||||||||||||||||||||||||||
| 167 | command => 'head1', | ||||||||||||||||||||||||||||
| 168 | content => $self->header, | ||||||||||||||||||||||||||||
| 169 | children => \@pod, | ||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | ); | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 10 | ▶ | if ( my $name = $self->region ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 1 | push $document->children->@*, | |||||||||||||||||||||||||||
| 176 | Pod::Elemental::Element::Pod5::Region->new( | ||||||||||||||||||||||||||||
| 177 | { | ||||||||||||||||||||||||||||
| 178 | format_name => $name =~ s/^://r, | ||||||||||||||||||||||||||||
| 179 | is_pod => 1, | ||||||||||||||||||||||||||||
| 180 | content => '', | ||||||||||||||||||||||||||||
| 181 | children => [$res], | ||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | ); | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | else { | ||||||||||||||||||||||||||||
| 187 | 9 | push $document->children->@*, $res; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 10 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | __END__ | ||||||||||||||||||||||||||||