Weaver/Section/Generic.pm

filter: Statementstmt 100% 33 / 33 Branchbran 87.5% 7 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 1 totaltotal 92.8% 52 / 56 CC 6 SCAR 8.3
CC
6
Cov
95%
weave_section
4.0
__ANON__
3.0
BEGIN
1.0
CRAP 2.3
« Weaver/Section/Name.pm ↑ Summary Weaver/Section/Leftovers.pm »
1 package Pod::Weaver::Section::Generic 4.022;
2 # ABSTRACT: a generic section, found by lifting sections
3  
4 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 with 'Pod::Weaver::Role::Section';
6  
7 5 ▶use v5.22.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use experimental 'postderef'; # this experiment succeeded -- rjbs, 2021-04-02
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #pod =head1 OVERVIEW
11 #pod
12 #pod This section will find and include a located hunk of Pod. In general, it will
13 #pod find a C<=head1> command with a content of the plugin's name.
14 #pod
15 #pod In other words, if your configuration include:
16 #pod
17 #pod [Generic]
18 #pod header = OVERVIEW
19 #pod
20 #pod ...then this weaver will look for "=head1 OVERVIEW" and include it at the
21 #pod appropriate location in your output.
22 #pod
23 #pod Since you'll probably want to use Generic several times, and that will require
24 #pod giving each use a unique name, you can omit C<header> if you provide a
25 #pod plugin name, and it will default to the plugin name. In other words, the
26 #pod configuration above could be specified just as:
27 #pod
28 #pod [Generic / OVERVIEW]
29 #pod
30 #pod If the C<required> attribute is given, and true, then an exception will be
31 #pod raised if this section can't be found.
32 #pod
33 #pod =cut
34  
35 5 ▶use Pod::Elemental::Element::Pod5::Region;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 5 ▶use Pod::Elemental::Selectors -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 #pod =attr required
39 #pod
40 #pod A boolean value specifying whether this section is required to be present or not. Defaults
41 #pod to false.
42 #pod
43 #pod If it's enabled and the section can't be found an exception will be raised.
44 #pod
45 #pod =cut
46  
47 5 has required => (
48 is => 'ro',
49 isa => 'Bool',
50 default => 0,
51 );
52  
53 #pod =attr header
54 #pod
55 #pod The name of this section. Defaults to the plugin name.
56 #pod
57 #pod =cut
58  
59 has header => (
60 is => 'ro',
61 isa => 'Str',
62 lazy => 1,
63 23 ▶ default => sub { $_[0]->plugin_name },
Subroutine __ANON__: called CC=1 SCAR=0.0
64 5 );
65  
66 has selector => (
67 is => 'ro',
68 isa => 'CodeRef',
69 lazy => 1,
70 23 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
71 23 my ($self) = @_;
72 86 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
73 86 ▶ return unless s_command(head1 => $_[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless s_command("head1", $_[0]) 21 65 86
74 65 ▶ return unless $_[0]->content eq $self->header;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->content eq $self->header 51 14 65
75 23 };
76 },
77 5 );
78  
79 23 ▶sub weave_section {
Subroutine weave_section: called CC=4 SCAR=14.0
Pod undocumented
80 23 my ($self, $document, $input) = @_;
81  
82 23 my $in_node = $input->{pod_document}->children;
83  
84 my @found = grep {
85 23 $self->selector->($in_node->[$_]);
86 } (0 .. $#$in_node);
87  
88 confess "Couldn't find required Generic section for " . $self->header . " in file "
89 23 ▶ . (defined $input->{filename} ? $input->{filename} : '') if $self->required and not @found;
Branch: 2 branches
BranchTrueFalseTotal
if $self->required and not @found 1 22 23
defined $input->{'filename'} ? : 0 1 1
Condition66%2/3
$self->required and not @found
!ll&&!rl&&r
2201
MC/DC50%1/2
$self->required and not @found
$self->required not @found
Truth table66%2/3
A and not(B)
A= $self->requiredB= not @found
ABresult
0X0
100
111
90  
91 22 $self->log_debug('adding ' . $self->header . ' back into pod');
92  
93 22 push $document->children->@*, map { splice @$in_node, $_, 1 } reverse @found;
94 }
95  
96 5 __PACKAGE__->meta->make_immutable;
97 5 1;
98  
99 __END__
« Weaver/Section/Name.pm ↑ Summary Weaver/Section/Leftovers.pm »