| 1 | # ABSTRACT: Write the POD of each sub from its blurb and the analysis of its code | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # PODNAME: Pod::Coverage::More::Generator | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | package Pod::Coverage::More::Generator 0.003; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use 5.036; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use warnings FATAL => q{all}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use re q{/xsaa}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Module::Runtime qw{module_notional_filename}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use mro; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use Pod::Coverage::More; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Pod::Coverage::More::Blurb; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use Pod::Coverage::More::Documentation; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # A generator for the package C<package>, which must be loaded. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # @param package Str the name of the package | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # @param file Str optional: the file to read the blurbs from, by default the file that the package was loaded from | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # @returns Pod::Coverage::More::Generator the generator | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # @example my $generator = Pod::Coverage::More::Generator->new( package => 'Some::Module', file => 'lib/Some/Module.pm' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | my ( $class, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | my $package = $args{package}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | ▶ | my $file = $args{file} // $INC{ module_notional_filename($package) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args{"file"} // $INC{&module_notional_filename($package)}
MC/DC0%0/2
$args{"file"} // $INC{&module_notional_filename($package)}
$args{"file"}
$INC{&module_notional_filename($package)}
Truth table66%2/3
A // B
A= $args{"file"}B= $INC{&module_notional_filename($package)}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | return bless( { package => $package, file => $file, coverage => Pod::Coverage::More->new( package => $package ) }, $class ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # One section per sub that gets one, in the order of the names of the subs: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # a HASHREF with C<name>, the name of the sub, and C<pod>, the text of its section, which starts with a C<=head2>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # @returns the sections, as a list | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # @example my @sections = $generator->sections; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 9 | ▶ | sub sections { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sections: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 9 | my $coverage = $self->{coverage}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 9 | ▶ | my $blurbs = defined $self->{file} ? Pod::Coverage::More::Blurb->read_file( $self->{file} ) : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 9 | my $analysis = $coverage->analysis; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 9 | my @sections; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 9 | foreach my $name ( sort $coverage->public_subs ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 52 | ▶ | my $blurb = $blurbs->{$name} or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 40 | ▶ | next if $coverage->section_for($name) || $self->_parent_has_blurb($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$coverage->section_for($name) or $self->_parent_has_blurb($name)
MC/DC50%1/2
$coverage->section_for($name) or $self->_parent_has_blurb($name)
$coverage->section_for($name)
$self->_parent_has_blurb($name)
Truth table66%2/3
A or B
A= $coverage->section_for($name)B= $self->_parent_has_blurb($name)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 39 | push @sections, { name => $name, pod => _section( $name, $blurb, $analysis->{$name} ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 9 | return @sections; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # Whether a parent class has a blurb for the sub NAME, which becomes its section when the parent is woven. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # Only a parent from the tree of the package counts: it is woven with the package. A parent from elsewhere, as an | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # installed one, either was woven already, so that its POD documents the sub, or never was, so that its comment is none. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 40 | ▶ | sub _parent_has_blurb { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parent_has_blurb: called CC=9 SCAR=22.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 40 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 40 | ▶ | my $tree = _tree_of( $self->{package} ) // return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
_tree_of($self->{"package"}) // (return 0)
MC/DC0%0/1
_tree_of($self->{"package"}) // (return 0)
_tree_of($self->{"package"})
Truth table50%1/2
A
A= _tree_of($self->{"package"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 40 | foreach my $parent ( @{ mro::get_linear_isa( $self->{package} ) } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 43 | ▶ | next if $parent eq $self->{package}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | ▶ | my $file = $INC{ module_notional_filename($parent) } or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | ▶ | next if ( _tree_of($parent) // q{} ) ne $tree; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
_tree_of($parent) // ""
MC/DC0%0/1
_tree_of($parent) // ""
_tree_of($parent)
Truth table50%1/2
A
A= _tree_of($parent)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | ▶ | $self->{parent_blurbs}{$parent} //= Pod::Coverage::More::Blurb->read_file($file); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"parent_blurbs"}{$parent} //= "Pod::Coverage::More::Blurb"->read_file($file)
MC/DC0%0/2
$self->{"parent_blurbs"}{$parent} //= "Pod::Coverage::More::Blurb"->read_file($file)
$self->{"parent_blurbs"}{$parent}
"Pod::Coverage::More::Blurb"->read_file($file)
Truth table66%2/3
A //= B
A= $self->{"parent_blurbs"}{$parent}B= "Pod::Coverage::More::Blurb"->read_file($file)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | ▶ | return 1 if $self->{parent_blurbs}{$parent}{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 39 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # The directory on @INC that PACKAGE was loaded from, or nothing when it was not loaded from a file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 43 | ▶ | sub _tree_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tree_of: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 43 | my ($package) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 43 | my $notional = module_notional_filename($package); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 43 | ▶ | my $file = $INC{$notional} // return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$INC{$notional} // (return)
MC/DC0%0/1
$INC{$notional} // (return)
$INC{$notional}
Truth table50%1/2
A
A= $INC{$notional}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 43 | return $file =~ s{/?\Q$notional\E\z}{}r; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # Whether the text of a @throws is a sentence already, as "croaks when", because it starts with a word of termination. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # The noun "exception" does not count: "with a Some::Exception" still needs "Dies". | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 12 | ▶ | sub _says_how_it_dies { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_says_how_it_dies: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 12 | my ($throws) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 12 | ▶ | return $throws =~ m/\A$Pod::Coverage::More::Documentation::TERMINATION/ && $throws !~ m/\Aexceptions?\b/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$throws =~ /\A$Pod::Coverage::More::Documentation::TERMINATION/aasx && !($throws =~ /\Aexceptions?\b/aaisx)
MC/DC0%0/2
$throws =~ /\A$Pod::Coverage::More::Documentation::TERMINATION/aasx && !($throws =~ /\Aexceptions?\b/aaisx)
$throws =~ /\A$Pod::Coverage::More::Documentation::TERMINATION/aasx
!($throws =~ /\Aexceptions?\b/aaisx)
Truth table33%1/3
A && not(B)
A= $throws =~ /\A$Pod::Coverage::More::Documentation::TERMINATION/aasxB= !($throws =~ /\Aexceptions?\b/aaisx)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # The text of all the sections, one after another. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # @returns Str the POD, or the empty string when no sub gets a section | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # @example my $pod = $generator->pod; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 5 | ▶ | sub pod { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pod: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 5 | return join q{}, map { $_->{pod} } $self->sections; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # The POD of one sub, from its BLURB and the analysis REC of its code. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 39 | ▶ | sub _section { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_section: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 39 | my ( $name, $blurb, $rec ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 39 | my @args = _arguments( $blurb, $rec ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 39 | ▶ | my $pod = "=head2 $name" . ( @args ? '(' . join( ', ', map { $_->{name} } @args ) . ')' : q{} ) . "\n\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 39 | foreach my $paragraph ( @{ $blurb->{description} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 39 | $pod .= "$paragraph\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 39 | ▶ | if (@args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 33 | $pod .= "=over 4\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 33 | foreach my $arg (@args) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 45 | ▶ | my @parts = ( "$arg->{sigil}$arg->{name}", $arg->{type} ? $arg->{type}->display_name : (), $arg->{description} ne q{} ? $arg->{description} : () ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 45 | $pod .= '=item ' . join( ' - ', @parts ) . "\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 33 | $pod .= "=back\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 39 | my $returns = _returns( $blurb, $rec ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 39 | ▶ | $pod .= "$returns\n\n" if defined $returns; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 39 | foreach my $throws ( @{ $blurb->{throws} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 12 | ▶ | $pod .= _sentence( _says_how_it_dies($throws) ? $throws : "Dies $throws" ) . "\n\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 39 | foreach my $example ( @{ $blurb->{examples} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 39 | $pod .= join( "\n", map { " $_" } @$example ) . "\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 39 | return $pod; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # The arguments of the heading: the parameters, or the keys of a hash of named arguments, with what the blurb and the code say of each. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 39 | ▶ | sub _arguments { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_arguments: called CC=18 SCAR=30.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 39 | my ( $blurb, $rec ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 39 | my %documented; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 39 | foreach my $param ( @{ $blurb->{params} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 45 | $documented{ Pod::Coverage::More::Documentation->bare_name( $param->{name} ) } = $param; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 39 | my @names; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 39 | ▶ | foreach my $param ( @{ $rec->{params} || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$rec->{'params'} || []
MC/DC0%0/1
$rec->{'params'} || []
$rec->{'params'}
Truth table50%1/2
A
A= $rec->{'params'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 39 | ▶ | next if !defined $param->{name} || $param->{source} eq 'invocant' || $param->{name} =~ m/\A\$(?:self|class|proto)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not defined $param->{"name"} or $param->{"source"} eq "invocant" or $param->{"name"} =~ /\A\$(?:self|class|proto)\z/aasx
not defined $param->{"name"} or $param->{"source"} eq "invocant"
MC/DC33%1/3
not defined $param->{"name"} or $param->{"source"} eq "invocant" or $param->{"name"} =~ /\A\$(?:self|class|proto)\z/aasx
not defined $param->{"name"}
$param->{"source"} eq "invocant"
$param->{"name"} =~ /\A\$(?:self|class|proto)\z/aasx
Truth table50%2/4
not(A) or B or C
A= not defined $param->{"name"}B= $param->{"source"} eq "invocant"C= $param->{"name"} =~ /\A\$(?:self|class|proto)\z/aasx
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 32 | ▶ | if ( $param->{name} =~ m/\A%/ && $param->{keys} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$param->{"name"} =~ /\A%/aasx and $param->{"keys"}
MC/DC50%1/2
$param->{"name"} =~ /\A%/aasx and $param->{"keys"}
$param->{"name"} =~ /\A%/aasx
$param->{"keys"}
Truth table66%2/3
A and B
A= $param->{"name"} =~ /\A%/aasxB= $param->{"keys"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | push @names, map { [ $_, undef ] } @{ $param->{keys} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 26 | push @names, [ Pod::Coverage::More::Documentation->bare_name( $param->{name} ), $param ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 39 | ▶ | if ( !@names ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 13 | foreach my $param ( @{ $blurb->{params} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 7 | push @names, [ Pod::Coverage::More::Documentation->bare_name( $param->{name} ), undef ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 39 | my @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 39 | foreach my $entry (@names) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 45 | my ( $name, $param ) = @$entry; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 45 | ▶ | my $documented = $documented{$name} // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$documented{$name} // {}
MC/DC0%0/1
$documented{$name} // {}
$documented{$name}
Truth table50%1/2
A
A= $documented{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | push @args, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | sigil => ( $documented->{name} // q{} ) =~ m/\A([@%])/ ? $1 : q{}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | type => $documented->{type} // ( $param ? $param->{declared} : undef ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 45 | ▶ | description => $documented->{description} // q{}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition42%3/7
$documented->{"name"} // ""
$documented->{"type"} // ($param ? $param->{"declared"} : undef)
$documented->{"description"} // ""
MC/DC0%0/1
$documented->{"name"} // ""
$documented->{"name"}
MC/DC0%0/2
$documented->{"type"} // ($param ? $param->{"declared"} : undef)
$documented->{"type"}
($param ? $param->{"declared"} : undef)
MC/DC0%0/1
$documented->{"description"} // ""
$documented->{"description"}
Truth table50%1/2
A
A= $documented->{"name"}
Truth table33%1/3
A // B
A= $documented->{"type"}B= ($param ? $param->{"declared"} : undef)
Truth table50%1/2
A
A= $documented->{"description"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 39 | return @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # The paragraph of the return value, or undef when neither the blurb nor what the code shows for certain says anything. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 39 | ▶ | sub _returns { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_returns: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 39 | my ( $blurb, $rec ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 39 | ▶ | my $stated = $blurb->{returns} // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$blurb->{"returns"} // {}
MC/DC100%1/1
$blurb->{"returns"} // {}
$blurb->{"returns"}
Truth table100%2/2
A
A= $blurb->{"returns"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 39 | ▶ | my $description = $stated->{description} // q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$stated->{"description"} // ""
MC/DC100%1/1
$stated->{"description"} // ""
$stated->{"description"}
Truth table100%2/2
A
A= $stated->{"description"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 39 | ▶ | my @types = $stated->{type} ? ( $stated->{type} ) : _code_return_types($rec); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 39 | ▶ | return if !@types && $description eq q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not @types and $description eq ""
MC/DC100%2/2
not @types and $description eq ""
not @types
$description eq ""
Truth table100%3/3
not(A) and B
A= not @typesB= $description eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 32 | my $text = 'Returns'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 32 | ▶ | $text .= q{ } . join( q{ or }, _type_texts(@types) ) if @types; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 32 | ▶ | $text .= ( @types ? q{, } : q{ } ) . $description if $description ne q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 32 | return _sentence($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # The return types that the code declares, or else those that its literals and objects show for certain. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 32 | ▶ | sub _code_return_types { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_code_return_types: called CC=9 SCAR=22.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 32 | my ($rec) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 32 | ▶ | return if !$rec; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 32 | ▶ | my @declared = @{ $rec->{declared}{returns} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$rec->{'declared'}{'returns'} || []
MC/DC0%0/1
$rec->{'declared'}{'returns'} || []
$rec->{'declared'}{'returns'}
Truth table50%1/2
A
A= $rec->{'declared'}{'returns'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 32 | ▶ | return @declared if @declared; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 32 | my ( @types, %seen ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 32 | foreach my $returned ( @{ $rec->{returns} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 38 | ▶ | next if $returned->{weak} || !$returned->{constraint} || $returned->{type} eq 'empty'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$returned->{"weak"} or not $returned->{"constraint"} or $returned->{"type"} eq "empty"
$returned->{"weak"} or not $returned->{"constraint"}
MC/DC100%3/3
$returned->{"weak"} or not $returned->{"constraint"} or $returned->{"type"} eq "empty"
$returned->{"weak"}
not $returned->{"constraint"}
$returned->{"type"} eq "empty"
Truth table100%4/4
A or not(B) or C
A= $returned->{"weak"}B= not $returned->{"constraint"}C= $returned->{"type"} eq "empty"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 24 | ▶ | push @types, $returned->{constraint} if !$seen{ $returned->{constraint}->display_name }++; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 32 | return @types; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # Constraints as the POD writes them in a Returns paragraph: an instance of one class in prose, a union as its alternatives, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # and any other by its name. Type::Tiny flattens a union of unions, so its members are no unions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 25 | ▶ | sub _type_texts { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_type_texts: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 25 | my (@types) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 25 | my @texts; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 25 | foreach my $type (@types) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | my @members = $type->isa('Type::Tiny::Union') ? @{ $type->type_constraints } : ($type); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 31 | foreach my $member (@members) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 31 | ▶ | push @texts, $member->isa('Type::Tiny::Class') ? 'a ' . $member->class . ' object' : $member->display_name; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 25 | return @texts; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 44 | ▶ | sub _sentence { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sentence: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 44 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 44 | $text =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 44 | $text = ucfirst $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 44 | ▶ | return $text =~ m/[.!?]\z/ ? $text : "$text."; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||