| 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.001; | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use 5.036; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use warnings FATAL => q{all}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use re q{/xsaa}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Module::Runtime qw{module_notional_filename}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use mro; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Pod::Coverage::More; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use Pod::Coverage::More::Blurb; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | 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 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | my ( $class, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | my $package = $args{package}; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | ▶ | 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 | 4 | 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 | 7 | ▶ | sub sections { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sections: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 7 | my $coverage = $self->{coverage}; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 7 | ▶ | my $blurbs = defined $self->{file} ? Pod::Coverage::More::Blurb->read_file( $self->{file} ) : {}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 7 | my $analysis = $coverage->analysis; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 7 | my @sections; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 7 | foreach my $name ( sort $coverage->public_subs ) { | |||||||||||||||||||||||||||||||||||||||||
| 41 | 44 | ▶ | my $blurb = $blurbs->{$name} or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 32 | ▶ | 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 | 31 | push @sections, { name => $name, pod => _section( $name, $blurb, $analysis->{$name} ) }; | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 7 | 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 | 32 | ▶ | sub _parent_has_blurb { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parent_has_blurb: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 32 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 32 | foreach my $parent ( @{ mro::get_linear_isa( $self->{package} ) } ) { | |||||||||||||||||||||||||||||||||||||||||
| 52 | 34 | ▶ | next if $parent eq $self->{package}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | ▶ | my $file = $INC{ module_notional_filename($parent) } or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 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)
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | ▶ | return 1 if $self->{parent_blurbs}{$parent}{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 31 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | # The text of all the sections, one after another. | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # @returns Str the POD, or the empty string when no sub gets a section | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # @example my $pod = $generator->pod; | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | ▶ | sub pod { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pod: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 4 | return join q{}, map { $_->{pod} } $self->sections; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | # The POD of one sub, from its BLURB and the analysis REC of its code. | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 31 | ▶ | sub _section { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_section: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 31 | my ( $name, $blurb, $rec ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 31 | my @args = _arguments( $blurb, $rec ); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 31 | ▶ | my $pod = "=head2 $name" . ( @args ? '(' . join( ', ', map { $_->{name} } @args ) . ')' : q{} ) . "\n\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 31 | foreach my $paragraph ( @{ $blurb->{description} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 74 | 31 | $pod .= "$paragraph\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 31 | ▶ | if (@args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 25 | $pod .= "=over 4\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 25 | foreach my $arg (@args) { | |||||||||||||||||||||||||||||||||||||||||
| 80 | 31 | ▶ | my @parts = ( $arg->{name}, $arg->{type} ? $arg->{type}->display_name : (), $arg->{description} ne q{} ? $arg->{description} : () ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 31 | $pod .= '=item ' . join( ' - ', @parts ) . "\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 25 | $pod .= "=back\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 31 | my $returns = _returns( $blurb, $rec ); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 31 | ▶ | $pod .= "$returns\n\n" if defined $returns; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 31 | foreach my $throws ( @{ $blurb->{throws} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 89 | 6 | ▶ | $pod .= _sentence( $throws =~ $Pod::Coverage::More::Documentation::TERMINATION ? $throws : "Dies $throws" ) . "\n\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 31 | foreach my $example ( @{ $blurb->{examples} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 92 | 31 | $pod .= join( "\n", map { " $_" } @$example ) . "\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 31 | return $pod; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | # 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. | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 31 | ▶ | sub _arguments { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_arguments: called CC=16 SCAR=29.2
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 31 | my ( $blurb, $rec ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 31 | my %documented; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 31 | foreach my $param ( @{ $blurb->{params} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 102 | 31 | $documented{ Pod::Coverage::More::Documentation->bare_name( $param->{name} ) } = $param; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 31 | my @names; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 31 | ▶ | 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'}
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 25 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 19 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 6 | push @names, map { [ $_, undef ] } @{ $param->{keys} }; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 13 | push @names, [ Pod::Coverage::More::Documentation->bare_name( $param->{name} ), $param ]; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 31 | ▶ | if ( !@names ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 12 | foreach my $param ( @{ $blurb->{params} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 115 | 6 | push @names, [ Pod::Coverage::More::Documentation->bare_name( $param->{name} ), undef ]; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 31 | my @args; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 31 | foreach my $entry (@names) { | |||||||||||||||||||||||||||||||||||||||||
| 121 | 31 | my ( $name, $param ) = @$entry; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 31 | ▶ | 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}
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | push @args, { | ||||||||||||||||||||||||||||||||||||||||||
| 124 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 125 | type => $documented->{type} // ( $param ? $param->{declared} : undef ), | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 31 | ▶ | description => $documented->{description} // q{}, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
$documented->{"type"} // ($param ? $param->{"declared"} : undef)
$documented->{"description"} // ""
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 table33%1/3
A // B
A= $documented->{"type"}B= ($param ? $param->{"declared"} : undef)
Truth table50%1/2
A
A= $documented->{"description"}
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 31 | return @args; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | # The paragraph of the return value, or undef when neither the blurb nor what the code shows for certain says anything. | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 31 | ▶ | sub _returns { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_returns: called CC=9 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 31 | my ( $blurb, $rec ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 31 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 31 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 31 | ▶ | my @types = $stated->{type} ? ( $stated->{type} ) : _code_return_types($rec); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 31 | ▶ | return if !@types && $description eq q{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not @types and $description eq ""
MC/DC50%1/2
not @types and $description eq ""
not @types
$description eq ""
Truth table66%2/3
not(A) and B
A= not @typesB= $description eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 24 | my $text = 'Returns'; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 24 | ▶ | $text .= q{ } . join( q{ or }, _type_texts(@types) ) if @types; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 24 | ▶ | $text .= ( @types ? q{, } : q{ } ) . $description if $description ne q{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 24 | return _sentence($text); | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | # The return types that the code declares, or else those that its literals and objects show for certain. | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 25 | ▶ | sub _code_return_types { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_code_return_types: called CC=9 SCAR=22.5
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 25 | my ($rec) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 25 | ▶ | return if !$rec; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 25 | ▶ | 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'}
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 25 | ▶ | return @declared if @declared; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 25 | my ( @types, %seen ); | |||||||||||||||||||||||||||||||||||||||||
| 153 | 25 | foreach my $returned ( @{ $rec->{returns} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 154 | 31 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 24 | ▶ | push @types, $returned->{constraint} if !$seen{ $returned->{constraint}->display_name }++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 25 | return @types; | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | # Constraints as the POD writes them in a Returns paragraph: an instance of one class in prose, a union as its alternatives, | ||||||||||||||||||||||||||||||||||||||||||
| 161 | # and any other by its name. Type::Tiny flattens a union of unions, so its members are no unions. | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 24 | ▶ | sub _type_texts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_type_texts: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 24 | my (@types) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 24 | my @texts; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 24 | foreach my $type (@types) { | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | my @members = $type->isa('Type::Tiny::Union') ? @{ $type->type_constraints } : ($type); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 30 | foreach my $member (@members) { | |||||||||||||||||||||||||||||||||||||||||
| 168 | 30 | ▶ | push @texts, $member->isa('Type::Tiny::Class') ? 'a ' . $member->class . ' object' : $member->display_name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 24 | return @texts; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 30 | ▶ | sub _sentence { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sentence: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 30 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 30 | $text =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 30 | $text = ucfirst $text; | |||||||||||||||||||||||||||||||||||||||||
| 178 | 30 | ▶ | return $text =~ m/[.!?]\z/ ? $text : "$text."; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | __END__ | ||||||||||||||||||||||||||||||||||||||||||