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