blib/lib/Pod/Weaver/Section/Blurbs.pm

filter: Statementstmt 100% 59 / 59 Branchbran 68.7% 11 / 16 Conditioncond 55.5% 5 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 88.1% 89 / 101 CC 14 SCAR 16.0
CC
14
Cov
89%
weave_section
9.4
_generate
4.0
_package_of
3.1
CRAP 4.9
« lib/Pod/Coverage/More/Declared/Kavorka.pm ↑ Summary lib/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.003;
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 4 ▶sub weave_section {
Subroutine weave_section: called CC=9 SCAR=22.5
Pod documented
28 4 my ( $self, $document, $input ) = @_;
29 4 ▶ my $file = $input->{filename} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $file = $input->{"filename"} or return 4 0 4
30 4 ▶ my $package = _package_of( $input->{ppi_document} ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $package = _package_of($input->{"ppi_document"}) or return 4 0 4
31  
32 4 my $pod = _generate( $package, $file );
33 3 ▶ return if $pod eq q{};
Branch: 1 branch
BranchTrueFalseTotal
if $pod eq "" 0 3 3
34  
35 3 my $generated = Pod::Elemental->read_string("=pod\n\n${pod}=cut\n");
36 3 Pod::Elemental::Transformer::Pod5->new->transform_node($generated);
37 3 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 3 foreach my $pod ( grep { defined } $document, $input->{pod_document} ) {
41 6 foreach my $element ( @{ $pod->children } ) {
42 4 ▶ 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 3 1 4
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
031
not $element->isa("Pod::Elemental::Element::Nested") or $element->command ne "head1"
l!l&&r!l&&!r
004
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 2 push @{ $document->children }, Pod::Elemental::Element::Nested->new( { command => 'head1', content => $self->header, children => \@elements } );
48 2 return;
49 }
50  
51 # The first package that the PPI document declares.
52 4 ▶sub _package_of {
Subroutine _package_of: called CC=3 SCAR=11.4
53 4 my ($ppi) = @_;
54 4 ▶ return if !$ppi;
Branch: 1 branch
BranchTrueFalseTotal
unless $ppi 0 4 4
55 4 ▶ my $statement = $ppi->find_first('PPI::Statement::Package') or return;
Branch: 1 branch
BranchTrueFalseTotal
my $statement = $ppi->find_first("PPI::Statement::Package") or return 4 0 4
56 4 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 # A script declares a package that no module file holds, so it loads by its path.
65 if ( grep { !ref && -f "$_/$module" } @INC ) {
66 require $module;
67 }
68 else {
69 require File::Spec;
70 $INC{$module} = File::Spec->rel2abs($file);
71 require( $INC{$module} );
72 }
73 require Pod::Coverage::More::Generator;
74 print Pod::Coverage::More::Generator->new( package => $package, file => $file )->pod;
75 PERL
76  
77 4 ▶sub _generate {
Subroutine _generate: called CC=4 SCAR=13.9
78 4 my ( $package, $file ) = @_;
79 4 ( my $module = "$package.pm" ) =~ s{::}{/}gxsaa;
80 4 my $root = $file =~ s{/?\Q$module\E\z}{}xsaar;
81 4 ▶ $root = q{.} if $root eq q{} || $root eq $file;
Branch: 1 branch
BranchTrueFalseTotal
if $root eq "" or $root eq $file 1 3 4
Condition66%2/3
$root eq "" or $root eq $file
l!l&&r!l&&!r
013
MC/DC50%1/2
$root eq "" or $root eq $file
$root eq "" $root eq $file
Truth table66%2/3
A or B
A= $root eq ""B= $root eq $file
ABresult
1X1
011
000
82  
83 4 local $ENV{PERL5LIB} = join q{:}, grep { !ref } @INC;
84  
85 # A child perl, so that the module that is being built never loads into the build.
86 4 ▶ my ( $out, $err, $status ) = capture { system( $^X, '-e', $CHILD, $package, $file, $root ) }; ## no critic (logicLAB::ProhibitShellDispatch)
Subroutine __ANON__: called CC=1 SCAR=0.0
87 4 ▶ die "Cannot generate the POD of $package from $file: $err" if $status != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $status != 0 1 3 4
88 3 return $out;
89 }
90  
91 2 __PACKAGE__->meta->make_immutable;
92  
93 2 1;
94  
95 __END__
« lib/Pod/Coverage/More/Declared/Kavorka.pm ↑ Summary lib/Pod/Coverage/More/Declared.pm »