Pod/Weaver/Section/Blurbs.pm

filter: Statementstmt 100% 59 / 59 Branchbran 62.5% 10 / 16 Conditioncond 44.4% 4 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 85.1% 86 / 101 CC 14 SCAR 16.0
CC
14
Cov
87%
weave_section
9.4
_generate
4.1
_package_of
3.1
CRAP 4.9
« Pod/Coverage/More/Declared/Kavorka.pm ↑ Summary Pod/Coverage/More/Declared.pm »
1 # ABSTRACT: Weave the POD of each sub that has a blurb, from its blurb and its code
2 # PODNAME: Pod::Weaver::Section::Blurbs
3  
4 package Pod::Weaver::Section::Blurbs 0.001;
5  
6 2 ▶use 5.036;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings FATAL => q{all};
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 with 'Pod::Weaver::Role::Section';
11  
12 2 ▶use Capture::Tiny qw{capture};
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Pod::Elemental;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Pod::Elemental::Element::Nested;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Pod::Elemental::Transformer::Pod5;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18 2 has header => ( is => 'ro', isa => 'Str', default => 'METHODS' );
19  
20  
21 # Adds the generated sections of the module that C<input> describes to C<document>, as L<Pod::Weaver::Role::Section> asks.
22 # @param document Pod::Elemental::Document the POD that is woven
23 # @param input HashRef with C<filename>, the path of the module from the current directory, and C<ppi_document>, the module as L<PPI> reads it
24 # @returns nothing
25 # @throws when the child perl cannot load the module
26 # @example $section->weave_section( $document, { filename => 'lib/Some/Module.pm', ppi_document => $ppi } );
27 3 ▶sub weave_section {
Subroutine weave_section: called CC=9 SCAR=22.5
Pod documented
28 3 my ( $self, $document, $input ) = @_;
29 3 ▶ my $file = $input->{filename} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $file = $input->{"filename"} or return 3 0 3
30 3 ▶ my $package = _package_of( $input->{ppi_document} ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $package = _package_of($input->{"ppi_document"}) or return 3 0 3
31  
32 3 my $pod = _generate( $package, $file );
33 2 ▶ return if $pod eq q{};
Branch: 1 branch
BranchTrueFalseTotal
if $pod eq "" 0 2 2
34  
35 2 my $generated = Pod::Elemental->read_string("=pod\n\n${pod}=cut\n");
36 2 Pod::Elemental::Transformer::Pod5->new->transform_node($generated);
37 2 my @elements = @{ $generated->children };
38  
39 # The POD that a section such as [Leftovers] has not moved yet is still in the input document.
40 2 foreach my $pod ( grep { defined } $document, $input->{pod_document} ) {
41 4 foreach my $element ( @{ $pod->children } ) {
42 3 ▶ next if !$element->isa('Pod::Elemental::Element::Nested') || $element->command ne 'head1' || $element->content ne $self->header;
Branch: 1 branch
BranchTrueFalseTotal
if not $element->isa("Pod::Elemental::Element::Nested") or $element->command ne "head1" or $element->content ne $self->header 2 1 3
Condition50%3/6
not $element->isa("Pod::Elemental::Element::Nested") or $element->command ne "head1" or $element->content ne $self->header
l!l&&r!l&&!r
021
not $element->isa("Pod::Elemental::Element::Nested") or $element->command ne "head1"
l!l&&r!l&&!r
003
MC/DC33%1/3
not $element->isa("Pod::Elemental::Element::Nested") or $element->command ne "head1" or $element->content ne $self->header
not $element->isa("Pod::Elemental::Element::Nested") $element->command ne "head1" $element->content ne $self->header
Truth table50%2/4
not(A) or B or C
A= not $element->isa("Pod::Elemental::Element::Nested")B= $element->command ne "head1"C= $element->content ne $self->header
ABCresult
1XX1
01X1
0011
0000
43 1 push @{ $element->children }, @elements;
44 1 return;
45 }
46 }
47 1 push @{ $document->children }, Pod::Elemental::Element::Nested->new( { command => 'head1', content => $self->header, children => \@elements } );
48 1 return;
49 }
50  
51 # The first package that the PPI document declares.
52 3 ▶sub _package_of {
Subroutine _package_of: called CC=3 SCAR=11.4
53 3 my ($ppi) = @_;
54 3 ▶ return if !$ppi;
Branch: 1 branch
BranchTrueFalseTotal
unless $ppi 0 3 3
55 3 ▶ my $statement = $ppi->find_first('PPI::Statement::Package') or return;
Branch: 1 branch
BranchTrueFalseTotal
my $statement = $ppi->find_first("PPI::Statement::Package") or return 3 0 3
56 3 return $statement->namespace;
57 }
58  
59 # The generated POD of PACKAGE, which FILE holds, from a child perl that loads it.
60 2 our $CHILD = <<'PERL';
61 my ( $package, $file, $root ) = @ARGV;
62 unshift @INC, $root;
63 ( my $module = "$package.pm" ) =~ s{::}{/}g;
64 require $module;
65 require Pod::Coverage::More::Generator;
66 print Pod::Coverage::More::Generator->new( package => $package, file => $file )->pod;
67 PERL
68  
69 3 ▶sub _generate {
Subroutine _generate: called CC=4 SCAR=14.1
70 3 my ( $package, $file ) = @_;
71 3 ( my $module = "$package.pm" ) =~ s{::}{/}gxsaa;
72 3 my $root = $file =~ s{/?\Q$module\E\z}{}xsaar;
73 3 ▶ $root = q{.} if $root eq q{} || $root eq $file;
Branch: 1 branch
BranchTrueFalseTotal
if $root eq "" or $root eq $file 0 3 3
Condition33%1/3
$root eq "" or $root eq $file
l!l&&r!l&&!r
003
MC/DC0%0/2
$root eq "" or $root eq $file
$root eq "" $root eq $file
Truth table33%1/3
A or B
A= $root eq ""B= $root eq $file
ABresult
1X1
011
000
74  
75 3 local $ENV{PERL5LIB} = join q{:}, grep { !ref } @INC;
76  
77 # A child perl, so that the module that is being built never loads into the build.
78 3 ▶ my ( $out, $err, $status ) = capture { system( $^X, '-e', $CHILD, $package, $file, $root ) }; ## no critic (logicLAB::ProhibitShellDispatch)
Subroutine __ANON__: called CC=1 SCAR=0.0
79 3 ▶ die "Cannot generate the POD of $package from $file: $err" if $status != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $status != 0 1 2 3
80 2 return $out;
81 }
82  
83 2 __PACKAGE__->meta->make_immutable;
84  
85 2 1;
86  
87 __END__
« Pod/Coverage/More/Declared/Kavorka.pm ↑ Summary Pod/Coverage/More/Declared.pm »