| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # This file is part of Pod-Weaver-Section-SeeAlso | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # This software is copyright (c) 2014 by Apocalypse. | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | package Pod::Weaver::Section::SeeAlso; | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # git description: release-1.002-10-g1fda35c | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | $Pod::Weaver::Section::SeeAlso::VERSION = '1.003'; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | $Pod::Weaver::Section::SeeAlso::AUTHORITY = 'cpan:APOCAL'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | # ABSTRACT: add a SEE ALSO pod section | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Moose 1.03; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Moose::Autobox 0.10; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | with 'Pod::Weaver::Role::Section' => { -version => '3.100710' }; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub mvp_multivalue_args { qw( links ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mvp_multivalue_args: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | #pod =attr add_main_link | ||||||||||||||||||||||||||||||||||||||||||
| 27 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 28 | #pod A boolean value controlling whether the link back to the main module should be | ||||||||||||||||||||||||||||||||||||||||||
| 29 | #pod added in the submodules. | ||||||||||||||||||||||||||||||||||||||||||
| 30 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 31 | #pod Defaults to true. | ||||||||||||||||||||||||||||||||||||||||||
| 32 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 33 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | has add_main_link => ( | |||||||||||||||||||||||||||||||||||||||||
| 36 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 37 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||
| 38 | default => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | #pod =attr header | ||||||||||||||||||||||||||||||||||||||||||
| 42 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 43 | #pod Specify the content to be displayed before the list of links is shown. | ||||||||||||||||||||||||||||||||||||||||||
| 44 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 45 | #pod The default is a sufficient explanation (see L</SEE ALSO>). | ||||||||||||||||||||||||||||||||||||||||||
| 46 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 47 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | has header => ( | |||||||||||||||||||||||||||||||||||||||||
| 50 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 51 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 52 | default => <<'EOPOD', | ||||||||||||||||||||||||||||||||||||||||||
| 53 | Please see those modules/websites for more information related to this module. | ||||||||||||||||||||||||||||||||||||||||||
| 54 | EOPOD | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | #pod =attr links | ||||||||||||||||||||||||||||||||||||||||||
| 59 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 60 | #pod Specify a list of links you want to add to the SEE ALSO section. | ||||||||||||||||||||||||||||||||||||||||||
| 61 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 62 | #pod You can either specify it like this: "Moose" or do it in POD format: "L<Moose>". This | ||||||||||||||||||||||||||||||||||||||||||
| 63 | #pod module will automatically add the proper POD formatting if it is missing. | ||||||||||||||||||||||||||||||||||||||||||
| 64 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 65 | #pod The default is an empty list. | ||||||||||||||||||||||||||||||||||||||||||
| 66 | #pod | ||||||||||||||||||||||||||||||||||||||||||
| 67 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | has links => ( | ||||||||||||||||||||||||||||||||||||||||||
| 70 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 71 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | default => sub { [ ] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub weave_section { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
weave_section: not called CC=23 SCAR=63.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | ## no critic ( ProhibitAccessOfPrivateData ) | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my ($self, $document, $input) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | my $zilla = $input->{'zilla'} or die 'Please use Dist::Zilla with this module!'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | # find the main module's name | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $main = $zilla->main_module->name; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | my $is_main = $main eq $input->{'filename'} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $main =~ s|^lib/||; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $main =~ s/\.pm$//; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $main =~ s|/|::|g; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | # Is the SEE ALSO section already in the POD? | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $see_also; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | foreach my $i ( 0 .. $#{ $input->{'pod_document'}->children } ) { | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $para = $input->{'pod_document'}->children->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | next unless $para->isa('Pod::Elemental::Element::Nested') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$para->isa("Pod::Elemental::Element::Nested") and $para->command eq "head1" and $para->content =~ /^SEE\s+ALSO/s
$para->isa("Pod::Elemental::Element::Nested") and $para->command eq "head1"
MC/DC0%0/3
$para->isa("Pod::Elemental::Element::Nested") and $para->command eq "head1" and $para->content =~ /^SEE\s+ALSO/s
$para->isa("Pod::Elemental::Element::Nested")
$para->command eq "head1"
$para->content =~ /^SEE\s+ALSO/s
Truth table0%0/4
A and B and C
A= $para->isa("Pod::Elemental::Element::Nested")B= $para->command eq "head1"C= $para->content =~ /^SEE\s+ALSO/s
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | and $para->command eq 'head1' | ||||||||||||||||||||||||||||||||||||||||||
| 94 | and $para->content =~ /^SEE\s+ALSO/s; # catches both "head1 SEE ALSO\n\nL<baz>" and "head1 SEE ALSO\nL<baz>" format | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $see_also = $para; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | splice( @{ $input->{'pod_document'}->children }, $i, 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my @links; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ( defined $see_also ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | # Transform it into a proper list | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | foreach my $child ( @{ $see_also->children } ) { | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ( $child->isa( 'Pod::Elemental::Element::Pod5::Ordinary' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | foreach my $l ( split /\n/, $child->content ) { | |||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | chomp $l; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | next if ! length $l; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | push( @links, $l ); | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | die 'Unknown POD in SEE ALSO: ' . ref( $child ); | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | # Sometimes the links are in the content! | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if ( $see_also->content =~ /^SEE\s+ALSO\s+(.+)$/s ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | foreach my $l ( split /\n/, $1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | chomp $l; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | next if ! length $l; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | push( @links, $l ); | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if ( $self->add_main_link and ! $is_main ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->add_main_link and not $is_main
MC/DC0%0/2
$self->add_main_link and not $is_main
$self->add_main_link
not $is_main
Truth table0%0/3
A and not(B)
A= $self->add_main_linkB= not $is_main
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | unshift( @links, $main ); | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | # Add links specified in the document | ||||||||||||||||||||||||||||||||||||||||||
| 130 | # Code copied from Pod::Weaver::Section::Name, thanks RJBS! | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my (@extra) = ($input->{'ppi_document'}->serialize =~ /^\s*#+\s*SEE\s*ALSO\s*:\s*(.+)$/mg); | |||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | foreach my $l ( @extra ) { | |||||||||||||||||||||||||||||||||||||||||
| 133 | # get the list! | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my @data = split( /\,/, $l ); | |||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $_ =~ s/^\s+//g for @data; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $_ =~ s/\s+$//g for @data; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | push( @links, $_ ) for @data; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | # Add extra links | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | push( @links, $_ ) for @{ $self->links }; | |||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if ( @links ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | $document->children->push( | ||||||||||||||||||||||||||||||||||||||||||
| 145 | Pod::Elemental::Element::Nested->new( { | ||||||||||||||||||||||||||||||||||||||||||
| 146 | command => 'head1', | ||||||||||||||||||||||||||||||||||||||||||
| 147 | content => 'SEE ALSO', | ||||||||||||||||||||||||||||||||||||||||||
| 148 | children => [ | ||||||||||||||||||||||||||||||||||||||||||
| 149 | Pod::Elemental::Element::Pod5::Ordinary->new( { | ||||||||||||||||||||||||||||||||||||||||||
| 150 | content => $self->header, | ||||||||||||||||||||||||||||||||||||||||||
| 151 | } ), | ||||||||||||||||||||||||||||||||||||||||||
| 152 | # I could have used the list transformer but rjbs said it's more sane to generate it myself :) | ||||||||||||||||||||||||||||||||||||||||||
| 153 | Pod::Elemental::Element::Nested->new( { | ||||||||||||||||||||||||||||||||||||||||||
| 154 | command => 'over', | ||||||||||||||||||||||||||||||||||||||||||
| 155 | content => '4', | ||||||||||||||||||||||||||||||||||||||||||
| 156 | children => [ | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ( map { _make_item( $_ ) } @links ), | |||||||||||||||||||||||||||||||||||||||||
| 158 | Pod::Elemental::Element::Pod5::Command->new( { | ||||||||||||||||||||||||||||||||||||||||||
| 159 | command => 'back', | ||||||||||||||||||||||||||||||||||||||||||
| 160 | content => '', | ||||||||||||||||||||||||||||||||||||||||||
| 161 | } ), | ||||||||||||||||||||||||||||||||||||||||||
| 162 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 163 | } ), | ||||||||||||||||||||||||||||||||||||||||||
| 164 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 165 | } ), | ||||||||||||||||||||||||||||||||||||||||||
| 166 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | sub _make_item { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_item: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | my( $link ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | # Is it proper POD? | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if ( $link !~ /^L\<.+\>$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | # include the link text so we satisfy Perl::Critic::Policy::Documentation::RequirePodLinksIncludeText | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $link = 'L<' . $link . '|' . $link . '>'; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | return Pod::Elemental::Element::Nested->new( { | |||||||||||||||||||||||||||||||||||||||||
| 180 | command => 'item', | ||||||||||||||||||||||||||||||||||||||||||
| 181 | content => '*', | ||||||||||||||||||||||||||||||||||||||||||
| 182 | children => [ | ||||||||||||||||||||||||||||||||||||||||||
| 183 | Pod::Elemental::Element::Pod5::Ordinary->new( { | ||||||||||||||||||||||||||||||||||||||||||
| 184 | content => $link, | ||||||||||||||||||||||||||||||||||||||||||
| 185 | } ), | ||||||||||||||||||||||||||||||||||||||||||
| 186 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 187 | } ); | ||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | __END__ | ||||||||||||||||||||||||||||||||||||||||||