Weaver/Section/Region.pm

filter: Statementstmt 100% 50 / 50 Branchbran 81.2% 13 / 16 Conditioncond 77.7% 7 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 1 totaltotal 90.3% 84 / 93 CC 12 SCAR 19.7
CC
12
Cov
93%
weave_section
12.3
BEGIN
1.0
BEGIN
1.0
CRAP 7.1
« Weaver/Section/Bugs.pm ↑ Summary Weaver/Plugin/SingleEncoding.pm »
1 package Pod::Weaver::Section::Region 4.022;
2 # ABSTRACT: find a region and put its contents in place where desired
3  
4 6 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 with 'Pod::Weaver::Role::Section';
6  
7 # BEGIN BOILERPLATE
8 6 ▶use v5.22.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶no feature 'switch';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use experimental qw(postderef postderef_qq); # This experiment gets mainlined.
Subroutine BEGIN: called CC=1 SCAR=0.0
13 # END BOILERPLATE
14  
15 #pod =head1 OVERVIEW
16 #pod
17 #pod This section will find and include a located hunk of Pod. In general, it will
18 #pod find a region with the specified name, such as:
19 #pod
20 #pod =begin :myfoo
21 #pod
22 #pod =head1 More Pod Here
23 #pod
24 #pod =end :myfoo
25 #pod
26 #pod In other words, if your configuration include:
27 #pod
28 #pod [Region]
29 #pod region_name = myfoo
30 #pod
31 #pod ...then this weaver will look for "=begin :myfoo" ( and "=for :myfoo" and... ) and include
32 #pod it at the appropriate location in your output.
33 #pod
34 #pod Since you'll probably want to use Region several times, and that will require
35 #pod giving each use a unique name, you can omit C<region_name> if you provide a
36 #pod plugin name, and it will default to the plugin name. In other words, the
37 #pod configuration above could be specified just as:
38 #pod
39 #pod [Region / myfoo]
40 #pod
41 #pod If the C<required> attribute is given, and true, then an exception will be
42 #pod raised if this region can't be found.
43 #pod
44 #pod =cut
45  
46 6 ▶use Pod::Elemental::Element::Pod5::Region;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 6 ▶use Pod::Elemental::Selectors -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 6 ▶use Pod::Elemental::Types qw(FormatName);
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 #pod =attr required
51 #pod
52 #pod A boolean value specifying whether this region is required to be present or not. Defaults
53 #pod to false.
54 #pod
55 #pod If it's enabled and the region can't be found an exception will be raised.
56 #pod
57 #pod =cut
58  
59 6 has required => (
60 is => 'ro',
61 isa => 'Bool',
62 default => 0,
63 );
64  
65 #pod =attr region_name
66 #pod
67 #pod The name of this region. Defaults to the plugin name.
68 #pod
69 #pod =cut
70  
71 has region_name => (
72 is => 'ro',
73 isa => FormatName,
74 lazy => 1,
75 required => 1,
76 14 ▶ default => sub { $_[0]->plugin_name },
Subroutine __ANON__: called CC=1 SCAR=0.0
77 6 );
78  
79 #pod =attr allow_nonpod
80 #pod
81 #pod A boolean value specifying whether nonpod regions are allowed or not. Defaults to false.
82 #pod
83 #pod C<nonpod> regions are regions I<without> a C<:> prefix as explained in
84 #pod L<< perlpodspec|perlpodspec/About Data Paragraphs and "=begin/=end" Regions >>
85 #pod
86 #pod # region_name = myregion
87 #pod # is_pod = false
88 #pod =begin myregion
89 #pod
90 #pod # region_name = myregion
91 #pod # is_pod = true
92 #pod =begin :myregion
93 #pod
94 #pod =cut
95  
96 6 has allow_nonpod => (
97 is => 'ro',
98 isa => 'Bool',
99 default => 0,
100 );
101  
102 #pod =attr flatten
103 #pod
104 #pod A boolean value specifying whether the region's contents should be flattened or not. Defaults to true.
105 #pod
106 #pod #unflattened
107 #pod =begin :myregion
108 #pod
109 #pod =head1
110 #pod
111 #pod =end :myregion
112 #pod
113 #pod #flattened
114 #pod =head1
115 #pod
116 #pod =cut
117  
118 6 has flatten => (
119 is => 'ro',
120 isa => 'Bool',
121 default => 1,
122 );
123  
124 26 ▶sub weave_section {
Subroutine weave_section: called CC=12 SCAR=25.1
Pod undocumented
125 26 my ($self, $document, $input) = @_;
126  
127 26 my @to_insert;
128  
129 26 my $idc = $input->{pod_document}->children;
130 26 ▶ IDX: for (my $i = 0; $i < @$idc; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$idc) 74 26 100
131 98 ▶ next unless my $para = $idc->[ $i ];
Branch: 1 branch
BranchTrueFalseTotal
unless my $para = $idc->[$i] 0 98 98
132 98 ▶ next unless $para->isa('Pod::Elemental::Element::Pod5::Region')
Branch: 1 branch
BranchTrueFalseTotal
unless $para->isa("Pod::Elemental::Element::Pod5::Region") and $para->format_name eq $self->region_name 74 24 98
Condition100%3/3
$para->isa("Pod::Elemental::Element::Pod5::Region") and $para->format_name eq $self->region_name
!ll&&!rl&&r
67724
MC/DC100%2/2
$para->isa("Pod::Elemental::Element::Pod5::Region") and $para->format_name eq $self->region_name
$para->isa("Pod::Elemental::Element::Pod5::Region") $para->format_name eq $self->region_name
Truth table100%3/3
A and B
A= $para->isa("Pod::Elemental::Element::Pod5::Region")B= $para->format_name eq $self->region_name
ABresult
0X0
100
111
133 and $para->format_name eq $self->region_name;
134 24 ▶ next if !$self->allow_nonpod and !$para->is_pod;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->allow_nonpod or $para->is_pod 0 24 24
Condition66%2/3
$self->allow_nonpod or $para->is_pod
l!l&&r!l&&!r
4200
MC/DC0%0/2
$self->allow_nonpod or $para->is_pod
$self->allow_nonpod $para->is_pod
Truth table66%2/3
A or B
A= $self->allow_nonpodB= $para->is_pod
ABresult
1X1
011
000
135  
136 24 ▶ if ( $self->flatten ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->flatten) { } 21 3 24
137 21 push @to_insert, $para->children->@*;
138 } else {
139 3 push @to_insert, $para;
140 }
141  
142 24 splice @$idc, $i, 1;
143  
144 24 redo IDX;
145 }
146  
147 confess "Couldn't find required Region for " . $self->region_name . " in file "
148 26 ▶ . (defined $input->{filename} ? $input->{filename} : '') if $self->required and not @to_insert;
Branch: 2 branches
BranchTrueFalseTotal
if $self->required and not @to_insert 1 25 26
defined $input->{'filename'} ? : 0 1 1
Condition66%2/3
$self->required and not @to_insert
!ll&&!rl&&r
2501
MC/DC50%1/2
$self->required and not @to_insert
$self->required not @to_insert
Truth table66%2/3
A and not(B)
A= $self->requiredB= not @to_insert
ABresult
0X0
100
111
149  
150 25 ▶ my $verb = $self->flatten ? 'flattening' : 'inserting';
Branch: 1 branch
BranchTrueFalseTotal
$self->flatten ? : 22 3 25
151 25 $self->log_debug($verb . q{ } . $self->region_name . ' into pod');
152 25 push $document->children->@*, @to_insert;
153 }
154  
155 6 __PACKAGE__->meta->make_immutable;
156 6 1;
157  
158 __END__
« Weaver/Section/Bugs.pm ↑ Summary Weaver/Plugin/SingleEncoding.pm »