| 1 | package Pod::Weaver::Section::Name 4.022; | ||||||||||||||||||||
| 2 | # ABSTRACT: add a NAME section with abstract (for your Perl module) | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 9 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 9 | with 'Pod::Weaver::Role::Section', | |||||||||||||||||||
| 6 | 'Pod::Weaver::Role::StringFromComment'; | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | # BEGIN BOILERPLATE | ||||||||||||||||||||
| 9 | 9 | ▶ | use v5.22.0; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 9 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 9 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 9 | ▶ | no feature 'switch'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 9 | ▶ | use experimental qw(postderef postderef_qq); # This experiment gets mainlined. | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | # END BOILERPLATE | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | #pod =head1 OVERVIEW | ||||||||||||||||||||
| 17 | #pod | ||||||||||||||||||||
| 18 | #pod This section plugin will produce a hunk of Pod giving the name of the document | ||||||||||||||||||||
| 19 | #pod as well as an abstract, like this: | ||||||||||||||||||||
| 20 | #pod | ||||||||||||||||||||
| 21 | #pod =head1 NAME | ||||||||||||||||||||
| 22 | #pod | ||||||||||||||||||||
| 23 | #pod Some::Document - a document for some | ||||||||||||||||||||
| 24 | #pod | ||||||||||||||||||||
| 25 | #pod It will determine the name and abstract by inspecting the C<ppi_document> which | ||||||||||||||||||||
| 26 | #pod must be given. It looks for comments in the form: | ||||||||||||||||||||
| 27 | #pod | ||||||||||||||||||||
| 28 | #pod | ||||||||||||||||||||
| 29 | #pod # ABSTRACT: a document for some | ||||||||||||||||||||
| 30 | #pod # PODNAME: Some::Package::Name | ||||||||||||||||||||
| 31 | #pod | ||||||||||||||||||||
| 32 | #pod If no C<PODNAME> comment is present, but a package declaration can be found, | ||||||||||||||||||||
| 33 | #pod the package name will be used as the document name. | ||||||||||||||||||||
| 34 | #pod | ||||||||||||||||||||
| 35 | #pod =attr header | ||||||||||||||||||||
| 36 | #pod | ||||||||||||||||||||
| 37 | #pod The title of the header to be added. | ||||||||||||||||||||
| 38 | #pod (default: "NAME") | ||||||||||||||||||||
| 39 | #pod | ||||||||||||||||||||
| 40 | #pod =cut | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 9 | has header => ( | |||||||||||||||||||
| 43 | is => 'ro', | ||||||||||||||||||||
| 44 | isa => 'Str', | ||||||||||||||||||||
| 45 | default => 'NAME', | ||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 9 | ▶ | use Pod::Elemental::Element::Pod5::Command; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 49 | 9 | ▶ | use Pod::Elemental::Element::Pod5::Ordinary; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 50 | 9 | ▶ | use Pod::Elemental::Element::Nested; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 27 | ▶ | sub _get_docname_via_statement { | ||||||||||||||||||
|
Subroutine
_get_docname_via_statement: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 53 | 27 | my ($self, $ppi_document) = @_; | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 27 | my $pkg_node = $ppi_document->find_first('PPI::Statement::Package'); | |||||||||||||||||||
| 56 | 27 | ▶ | return unless $pkg_node; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | 27 | return $pkg_node->namespace; | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 29 | ▶ | sub _get_docname_via_comment { | ||||||||||||||||||
|
Subroutine
_get_docname_via_comment: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 61 | 29 | my ($self, $ppi_document) = @_; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 29 | return $self->_extract_comment_content($ppi_document, 'PODNAME'); | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 29 | ▶ | sub _get_docname { | ||||||||||||||||||
|
Subroutine
_get_docname: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 67 | 29 | my ($self, $input) = @_; | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 29 | my $ppi_document = $input->{ppi_document}; | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 29 | ▶ | my $docname = $self->_get_docname_via_comment($ppi_document) | ||||||||||||||||||
|
Condition66%2/3
$self->_get_docname_via_comment($ppi_document) || $self->_get_docname_via_statement($ppi_document)
MC/DC0%0/2
$self->_get_docname_via_comment($ppi_document) || $self->_get_docname_via_statement($ppi_document)
$self->_get_docname_via_comment($ppi_document)
$self->_get_docname_via_statement($ppi_document)
Truth table66%2/3
A || B
A= $self->_get_docname_via_comment($ppi_document)B= $self->_get_docname_via_statement($ppi_document)
| |||||||||||||||||||||
| 72 | || $self->_get_docname_via_statement($ppi_document); | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 29 | return $docname; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 29 | ▶ | sub _get_abstract { | ||||||||||||||||||
|
Subroutine
_get_abstract: called CC=2 SCAR=8.4
| |||||||||||||||||||||
| 78 | 29 | my ($self, $input) = @_; | |||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 29 | my $comment = $self->_extract_comment_content($input->{ppi_document}, 'ABSTRACT'); | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 29 | ▶ | return $comment if $comment; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | # If that failed, fall back to searching the whole document | ||||||||||||||||||||
| 85 | my ($abstract) | ||||||||||||||||||||
| 86 | 0 | = $input->{ppi_document}->serialize =~ /^\s*#+\s*ABSTRACT:\s*(.+)$/m; | |||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | return $abstract; | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 29 | ▶ | sub weave_section { | ||||||||||||||||||
|
Subroutine
weave_section: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||
| 92 | 29 | my ($self, $document, $input) = @_; | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 29 | ▶ | my $filename = $input->{filename} || 'file'; | ||||||||||||||||||
|
Condition50%1/2
$input->{'filename'} || 'file'
MC/DC0%0/1
$input->{'filename'} || 'file'
$input->{'filename'}
Truth table50%1/2
A
A= $input->{'filename'}
| |||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 29 | my $docname = $self->_get_docname($input); | |||||||||||||||||||
| 97 | 29 | my $abstract = $self->_get_abstract($input); | |||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 29 | ▶ | Carp::croak sprintf "couldn't determine document name for %s\nAdd something like this to %s:\n# PODNAME: bobby_tables.pl", $filename, $filename | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | unless $docname; | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 29 | ▶ | $self->log([ "couldn't find abstract in %s", $filename ]) unless $abstract; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 29 | my $name = $docname; | |||||||||||||||||||
| 105 | 29 | ▶ | $name .= " - $abstract" if $abstract; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 29 | $self->log_debug(qq{setting NAME to "$name"}); | |||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 29 | my $name_para = Pod::Elemental::Element::Nested->new({ | |||||||||||||||||||
| 110 | command => 'head1', | ||||||||||||||||||||
| 111 | content => $self->header, | ||||||||||||||||||||
| 112 | children => [ | ||||||||||||||||||||
| 113 | Pod::Elemental::Element::Pod5::Ordinary->new({ content => $name }), | ||||||||||||||||||||
| 114 | ], | ||||||||||||||||||||
| 115 | }); | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 29 | push $document->children->@*, $name_para; | |||||||||||||||||||
| 118 | } | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 9 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 121 | 9 | 1; | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | __END__ | ||||||||||||||||||||