| 1 | package Pod::Weaver::Section::Collect 4.022; | ||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: a section that gathers up specific commands | ||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 5 | with 'Pod::Weaver::Role::Section', | |||||||||||||||||||||||||||||||||
| 6 | 'Pod::Weaver::Role::Transformer'; | ||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | # BEGIN BOILERPLATE | ||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use v5.22.0; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | no feature 'switch'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | 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 Given the configuration: | ||||||||||||||||||||||||||||||||||
| 19 | #pod | ||||||||||||||||||||||||||||||||||
| 20 | #pod [Collect / METHODS] | ||||||||||||||||||||||||||||||||||
| 21 | #pod command = method | ||||||||||||||||||||||||||||||||||
| 22 | #pod | ||||||||||||||||||||||||||||||||||
| 23 | #pod This plugin will start off by gathering and nesting any C<=method> commands | ||||||||||||||||||||||||||||||||||
| 24 | #pod found in the C<pod_document>. Those commands, along with their nestable | ||||||||||||||||||||||||||||||||||
| 25 | #pod content, will be collected under a C<=head1 METHODS> header and placed in the | ||||||||||||||||||||||||||||||||||
| 26 | #pod correct location in the output stream. Their order will be preserved as it was | ||||||||||||||||||||||||||||||||||
| 27 | #pod in the source document. | ||||||||||||||||||||||||||||||||||
| 28 | #pod | ||||||||||||||||||||||||||||||||||
| 29 | #pod =cut | ||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | 5 | ▶ | use Pod::Elemental::Element::Pod5::Region; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 32 | 5 | ▶ | use Pod::Elemental::Selectors -all; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 33 | 5 | ▶ | use List::Util 1.33 'any'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||
| 35 | #pod =attr command | ||||||||||||||||||||||||||||||||||
| 36 | #pod | ||||||||||||||||||||||||||||||||||
| 37 | #pod The command that will be collected (e.g. C<attr> or C<method>). | ||||||||||||||||||||||||||||||||||
| 38 | #pod (required) | ||||||||||||||||||||||||||||||||||
| 39 | #pod | ||||||||||||||||||||||||||||||||||
| 40 | #pod =attr new_command | ||||||||||||||||||||||||||||||||||
| 41 | #pod | ||||||||||||||||||||||||||||||||||
| 42 | #pod The command to be used in the output instead of the collected command. | ||||||||||||||||||||||||||||||||||
| 43 | #pod (default: C<head2>) | ||||||||||||||||||||||||||||||||||
| 44 | #pod | ||||||||||||||||||||||||||||||||||
| 45 | #pod =attr header_command | ||||||||||||||||||||||||||||||||||
| 46 | #pod | ||||||||||||||||||||||||||||||||||
| 47 | #pod The section command for the section to be added. | ||||||||||||||||||||||||||||||||||
| 48 | #pod (default: C<head1>) | ||||||||||||||||||||||||||||||||||
| 49 | #pod | ||||||||||||||||||||||||||||||||||
| 50 | #pod =attr header | ||||||||||||||||||||||||||||||||||
| 51 | #pod | ||||||||||||||||||||||||||||||||||
| 52 | #pod The title of the section to be added. | ||||||||||||||||||||||||||||||||||
| 53 | #pod (default: the plugin name) | ||||||||||||||||||||||||||||||||||
| 54 | #pod | ||||||||||||||||||||||||||||||||||
| 55 | #pod =cut | ||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | 5 | has command => ( | |||||||||||||||||||||||||||||||||
| 58 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 59 | isa => 'Str', | ||||||||||||||||||||||||||||||||||
| 60 | required => 1, | ||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | 5 | has new_command => ( | |||||||||||||||||||||||||||||||||
| 64 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 65 | isa => 'Str', | ||||||||||||||||||||||||||||||||||
| 66 | required => 1, | ||||||||||||||||||||||||||||||||||
| 67 | default => 'head2', | ||||||||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | 5 | has header_command => ( | |||||||||||||||||||||||||||||||||
| 71 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 72 | isa => 'Str', | ||||||||||||||||||||||||||||||||||
| 73 | required => 1, | ||||||||||||||||||||||||||||||||||
| 74 | default => 'head1', | ||||||||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | has header => ( | ||||||||||||||||||||||||||||||||||
| 78 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 79 | isa => 'Str', | ||||||||||||||||||||||||||||||||||
| 80 | lazy => 1, | ||||||||||||||||||||||||||||||||||
| 81 | required => 1, | ||||||||||||||||||||||||||||||||||
| 82 | 7 | ▶ | default => sub { $_[0]->plugin_name }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 83 | 5 | ); | |||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | 5 | ▶ | use Pod::Elemental::Transformer::Gatherer; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 86 | 5 | ▶ | use Pod::Elemental::Transformer::Nester; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | 5 | has __used_container => (is => 'rw'); | |||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | 20 | ▶ | sub transform_document { | ||||||||||||||||||||||||||||||||
|
Subroutine
transform_document: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 91 | 20 | my ($self, $document) = @_; | |||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||
| 93 | 20 | my $command = $self->command; | |||||||||||||||||||||||||||||||||
| 94 | 20 | my $selector = s_command($command); | |||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||
| 96 | 20 | my $children = $document->children; | |||||||||||||||||||||||||||||||||
| 97 | 20 | ▶ | unless (any { $selector->($_) } @$children) { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 98 | 13 | $self->log_debug("no $command commands in pod to collect"); | |||||||||||||||||||||||||||||||||
| 99 | 13 | return; | |||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||
| 102 | 7 | $self->log_debug("transforming $command commands into standard pod"); | |||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | 7 | my $nester = Pod::Elemental::Transformer::Nester->new({ | |||||||||||||||||||||||||||||||||
| 105 | top_selector => $selector, | ||||||||||||||||||||||||||||||||||
| 106 | content_selectors => [ | ||||||||||||||||||||||||||||||||||
| 107 | s_command([ qw(head3 head4 over item back) ]), | ||||||||||||||||||||||||||||||||||
| 108 | s_flat, | ||||||||||||||||||||||||||||||||||
| 109 | ], | ||||||||||||||||||||||||||||||||||
| 110 | }); | ||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||
| 112 | # try and find array position of suitable host | ||||||||||||||||||||||||||||||||||
| 113 | my ( $container_id ) = grep { | ||||||||||||||||||||||||||||||||||
| 114 | 7 | my $c = $children->[$_]; | |||||||||||||||||||||||||||||||||
| 115 | 55 | ▶ | $c->isa("Pod::Elemental::Element::Nested") | ||||||||||||||||||||||||||||||||
|
Condition83%5/6
$c->isa('Pod::Elemental::Element::Nested') && $c->command eq $self->header_command && $c->content eq $self->header
$c->isa("Pod::Elemental::Element::Nested") and $c->command eq $self->header_command
MC/DC66%2/3
$c->isa('Pod::Elemental::Element::Nested') && $c->command eq $self->header_command && $c->content eq $self->header
$c->isa("Pod::Elemental::Element::Nested")
$c->command eq $self->header_command
$c->content eq $self->header
Truth table75%3/4
A and B && C
A= $c->isa("Pod::Elemental::Element::Nested")B= $c->command eq $self->header_commandC= $c->content eq $self->header
| |||||||||||||||||||||||||||||||||||
| 116 | and $c->command eq $self->header_command and $c->content eq $self->header; | ||||||||||||||||||||||||||||||||||
| 117 | } 0 .. $#$children; | ||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||
| 119 | 7 | ▶ | my $container = $container_id | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 120 | ? splice @$children, $container_id, 1 # excise host | ||||||||||||||||||||||||||||||||||
| 121 | : Pod::Elemental::Element::Nested->new({ # synthesize new host | ||||||||||||||||||||||||||||||||||
| 122 | command => $self->header_command, | ||||||||||||||||||||||||||||||||||
| 123 | content => $self->header, | ||||||||||||||||||||||||||||||||||
| 124 | }); | ||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||
| 126 | 7 | $self->__used_container($container); | |||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | 7 | my $gatherer = Pod::Elemental::Transformer::Gatherer->new({ | |||||||||||||||||||||||||||||||||
| 129 | gather_selector => $selector, | ||||||||||||||||||||||||||||||||||
| 130 | container => $container, | ||||||||||||||||||||||||||||||||||
| 131 | }); | ||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||
| 133 | 7 | $nester->transform_node($document); | |||||||||||||||||||||||||||||||||
| 134 | 7 | my @children = $container->children->@*; # rescue children | |||||||||||||||||||||||||||||||||
| 135 | 7 | $gatherer->transform_node($document); # insert host at position of first adopt-child and inject it with adopt-children | |||||||||||||||||||||||||||||||||
| 136 | 7 | foreach my $child ($container->children->@*) { | |||||||||||||||||||||||||||||||||
| 137 | 7 | ▶ | $child->command( $self->new_command ) if $child->command eq $command; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||
| 139 | 7 | unshift $container->children->@*, @children; # give original children back to host | |||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||
| 142 | 20 | ▶ | sub weave_section { | ||||||||||||||||||||||||||||||||
|
Subroutine
weave_section: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 143 | 20 | my ($self, $document, $input) = @_; | |||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||
| 145 | 20 | ▶ | return unless $self->__used_container; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||
| 147 | 7 | my $in_node = $input->{pod_document}->children; | |||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||
| 149 | my @found = grep { | ||||||||||||||||||||||||||||||||||
| 150 | 7 | my ($i, $para) = ($_, $in_node->[$_]); | |||||||||||||||||||||||||||||||||
| 151 | 21 | ▶ | ($para == $self->__used_container) | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$para == $self->__used_container && @{$self->__used_container->children}
MC/DC50%1/2
$para == $self->__used_container && @{$self->__used_container->children}
$para == $self->__used_container
@{$self->__used_container->children}
Truth table66%2/3
A && B
A= $para == $self->__used_containerB= @{$self->__used_container->children}
| |||||||||||||||||||||||||||||||||||
| 152 | && $self->__used_container->children->@*; | ||||||||||||||||||||||||||||||||||
| 153 | } (0 .. $#$in_node); | ||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||
| 155 | 7 | push $document->children->@*, map { splice @$in_node, $_, 1 } reverse @found; | |||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||
| 158 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||
| 159 | 5 | 1; | |||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||
| 161 | __END__ | ||||||||||||||||||||||||||||||||||