| 1 | 1 | ▶ | use 5.008; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | package Pod::Weaver::Section::CollectWithAutoDoc; | ||||||||||||
| 6 | 1 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | $Pod::Weaver::Section::CollectWithAutoDoc::VERSION = '1.100980'; | |||||||||||
| 8 | } | ||||||||||||
| 9 | |||||||||||||
| 10 | # ABSTRACT: Section to gather specific commands and add auto-generated documentation | ||||||||||||
| 11 | 1 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 1 | extends 'Pod::Weaver::Section::Collect'; | |||||||||||
| 13 | 1 | with 'Pod::Weaver::Role::Preparer'; | |||||||||||
| 14 | 1 | ▶ | use Moose::Autobox; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 1 | ▶ | use Sub::Documentation ':all'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 1 | ▶ | use Pod::Elemental::Element::Pod5::Command; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 1 | ▶ | use Pod::Elemental::Element::Pod5::Ordinary; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 1 | ▶ | use Pod::Elemental::Element::Pod5::Verbatim; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | |||||||||||||
| 20 | 0 | ▶ | sub prepare_input { | ||||||||||
|
Subroutine
prepare_input: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||
| 21 | 0 | my ($self, $input) = @_; | |||||||||||
| 22 | |||||||||||||
| 23 | # Load the module file so it can auto-generated documentation | ||||||||||||
| 24 | 0 | my $file = $input->{filename}; | |||||||||||
| 25 | 0 | ▶ | return unless defined $file; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | 0 | (my $inc_key = $file) =~ s!^lib/!!; | |||||||||||
| 27 | 0 | ▶ | if ($INC{$inc_key}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | 0 | $self->log("$file appears to have been already loaded, skipping"); | |||||||||||
| 29 | 0 | return; | |||||||||||
| 30 | } | ||||||||||||
| 31 | 0 | ▶ | unless (my $return = do $file) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 32 | 0 | ▶ | $self->log("couldn't parse $file: $@") if $@; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | 0 | ▶ | $self->log("couldn't do $file: $!") unless defined $return; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 34 | 0 | ▶ | $self->log("couldn't run $file") unless $return; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | # Some modules define a UNIVERSAL::AUTOLOAD, this can be unwelcome for our | ||||||||||||
| 38 | # circumstances, so we shoot it. :) | ||||||||||||
| 39 | 0 | undef *UNIVERSAL::AUTOLOAD; | |||||||||||
| 40 | } | ||||||||||||
| 41 | |||||||||||||
| 42 | 0 | ▶ | sub get_package_name { | ||||||||||
|
Subroutine
get_package_name: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 43 | 0 | my ($self, $input) = @_; | |||||||||||
| 44 | 0 | ▶ | return unless my $ppi_document = $input->{ppi_document}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | 0 | my $pkg_node = $ppi_document->find_first('PPI::Statement::Package'); | |||||||||||
| 46 | 0 | ▶ | my $filename = $input->{filename} || 'file'; | ||||||||||
|
Condition0%0/2
$input->{'filename'} || 'file'
MC/DC0%0/1
$input->{'filename'} || 'file'
$input->{'filename'}
Truth table0%0/2
A
A= $input->{'filename'}
| |||||||||||||
| 47 | 0 | ▶ | Carp::croak sprintf "couldn't find package declaration in %s", $filename | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | unless $pkg_node; | ||||||||||||
| 49 | 0 | $pkg_node->namespace; | |||||||||||
| 50 | } | ||||||||||||
| 51 | |||||||||||||
| 52 | 0 | ▶ | sub pod_ordinary { | ||||||||||
|
Subroutine
pod_ordinary: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 53 | 0 | my ($self, $content) = @_; | |||||||||||
| 54 | 0 | Pod::Elemental::Element::Pod5::Ordinary->new(content => $content,); | |||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | 0 | ▶ | sub pod_verbatim { | ||||||||||
|
Subroutine
pod_verbatim: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 58 | 0 | my ($self, $content) = @_; | |||||||||||
| 59 | 0 | Pod::Elemental::Element::Pod5::Verbatim->new(content => $content,); | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | 0 | ▶ | sub pod_command { | ||||||||||
|
Subroutine
pod_command: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 63 | 0 | my ($self, $command, $content) = @_; | |||||||||||
| 64 | 0 | Pod::Elemental::Element::Pod5::Command->new( | |||||||||||
| 65 | content => $content, | ||||||||||||
| 66 | command => $command, | ||||||||||||
| 67 | ), | ||||||||||||
| 68 | ; | ||||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | 0 | ▶ | sub add_examples { | ||||||||||
|
Subroutine
add_examples: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||
| 72 | 0 | my ($self, %args) = @_; | |||||||||||
| 73 | 0 | my @examples = search_documentation( | |||||||||||
| 74 | glob_type => 'CODE', | ||||||||||||
| 75 | type => 'examples', | ||||||||||||
| 76 | %args, | ||||||||||||
| 77 | ); | ||||||||||||
| 78 | 0 | ▶ | if (@examples) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | 0 | my @count = map { @{ $_->{documentation} } } @examples; | |||||||||||
| 80 | 0 | ▶ | $_->children->push( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 81 | $self->pod_ordinary( | ||||||||||||
| 82 | @count == 1 | ||||||||||||
| 83 | ? 'Example:' | ||||||||||||
| 84 | : 'Examples:' | ||||||||||||
| 85 | ) | ||||||||||||
| 86 | ); | ||||||||||||
| 87 | 0 | for my $example_doc (@examples) { | |||||||||||
| 88 | 0 | for my $example (@{ $example_doc->{documentation} }) { | |||||||||||
| 89 | 0 | $_->children->push($self->pod_verbatim(" $example")); | |||||||||||
| 90 | } | ||||||||||||
| 91 | } | ||||||||||||
| 92 | } | ||||||||||||
| 93 | } | ||||||||||||
| 94 | 0 | ▶ | override weave_section => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 95 | 0 | my ($self, $document, $input) = @_; | |||||||||||
| 96 | 0 | my $package = $self->get_package_name($input); | |||||||||||
| 97 | 0 | ▶ | if ($self->__used_container) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 98 | $self->__used_container->children->each_value( | ||||||||||||
| 99 | 0 | ▶ | sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||
| 100 | my @main_purposes = search_documentation( | ||||||||||||
| 101 | package => $package, | ||||||||||||
| 102 | glob_type => 'CODE', | ||||||||||||
| 103 | type => 'purpose', | ||||||||||||
| 104 | name => $_->{content}, | ||||||||||||
| 105 | 0 | ); | |||||||||||
| 106 | 0 | ▶ | if (@main_purposes) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 107 | 0 | for my $main_purpose (@main_purposes) { | |||||||||||
| 108 | $_->children->push( | ||||||||||||
| 109 | $self->pod_ordinary($main_purpose->{documentation}) | ||||||||||||
| 110 | 0 | ); | |||||||||||
| 111 | $self->add_examples( | ||||||||||||
| 112 | package => $package, | ||||||||||||
| 113 | name => $_->{content}, | ||||||||||||
| 114 | 0 | ); | |||||||||||
| 115 | } | ||||||||||||
| 116 | } | ||||||||||||
| 117 | my @helper_purposes = search_documentation( | ||||||||||||
| 118 | package => $package, | ||||||||||||
| 119 | glob_type => 'CODE', | ||||||||||||
| 120 | type => 'purpose', | ||||||||||||
| 121 | belongs_to => $_->{content} | ||||||||||||
| 122 | 0 | ); | |||||||||||
| 123 | 0 | ▶ | if (@helper_purposes) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 124 | 0 | $_->children->push( | |||||||||||
| 125 | $self->pod_ordinary( | ||||||||||||
| 126 | 'There are also the following helper methods for this accessor:', | ||||||||||||
| 127 | ) | ||||||||||||
| 128 | ); | ||||||||||||
| 129 | 0 | $_->children->push($self->pod_command(over => 4)); | |||||||||||
| 130 | 0 | for my $helper_purpose (@helper_purposes) { | |||||||||||
| 131 | 0 | for my $name (@{ $helper_purpose->{name} }) { | |||||||||||
| 132 | 0 | $_->children->push( | |||||||||||
| 133 | $self->pod_command(item => "C<$name>")); | ||||||||||||
| 134 | } | ||||||||||||
| 135 | $_->children->push( | ||||||||||||
| 136 | $self->pod_ordinary( | ||||||||||||
| 137 | $helper_purpose->{documentation} | ||||||||||||
| 138 | ) | ||||||||||||
| 139 | 0 | ); | |||||||||||
| 140 | $self->add_examples( | ||||||||||||
| 141 | package => $package, | ||||||||||||
| 142 | name => $helper_purpose->{name}[0], | ||||||||||||
| 143 | belongs_to => $_->{content}, | ||||||||||||
| 144 | 0 | ); | |||||||||||
| 145 | } | ||||||||||||
| 146 | 0 | $_->children->push($self->pod_command(back => '')); | |||||||||||
| 147 | } | ||||||||||||
| 148 | } | ||||||||||||
| 149 | 0 | ); | |||||||||||
| 150 | } | ||||||||||||
| 151 | 0 | super; | |||||||||||
| 152 | 1 | }; | |||||||||||
| 153 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 154 | 1 | ▶ | no Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 155 | 1 | 1; | |||||||||||
| 156 | |||||||||||||
| 157 | |||||||||||||
| 158 | __END__ | ||||||||||||