| 1 | # ABSTRACT: What class builders and signature modules declare about the subs of a package | ||||||||||||||||||||
| 2 | # PODNAME: Pod::Coverage::More::Declared | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | package Pod::Coverage::More::Declared 0.001; | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 20 | ▶ | use 5.036; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 20 | ▶ | use warnings FATAL => q{all}; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 20 | ▶ | use Module::Runtime qw{require_module}; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | # Signatures of single subs first: when a class builder also declares the sub, the signature is more specific. | ||||||||||||||||||||
| 13 | 20 | our @PROVIDERS = map { "Pod::Coverage::More::Declared::$_" } qw{TypeParams FunctionParameters Kavorka MOP ObjectPad ClassTiny}; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | # The declaration of the invocant of a method, parameter 0, for the providers. | ||||||||||||||||||||
| 17 | # @param name Maybe[Str] the name of the invocant, or undef when it has none | ||||||||||||||||||||
| 18 | # @returns HashRef the declaration of the parameter | ||||||||||||||||||||
| 19 | # @example my $self = Pod::Coverage::More::Declared->invocant('$self'); | ||||||||||||||||||||
| 20 | 20 | ▶ | sub invocant { | ||||||||||||||||||
|
Subroutine
invocant: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 21 | 20 | my ( $class, $name ) = @_; | |||||||||||||||||||
| 22 | 20 | return { name => $name, index => 0, type => undef, optional => 0, invocant => 1 }; | |||||||||||||||||||
| 23 | } | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | # The declarations of the subs of C<package> that C<names> lists and a provider declares. | ||||||||||||||||||||
| 26 | # When two providers declare the same sub, the first in PROVIDERS wins, and a C<body> from a later one fills in a missing one. | ||||||||||||||||||||
| 27 | # @param package Str the name of the package | ||||||||||||||||||||
| 28 | # @param names ArrayRef[Str] the names of the subs | ||||||||||||||||||||
| 29 | # @returns HashRef from the name of each declared sub to its declaration | ||||||||||||||||||||
| 30 | # @example my $declared = Pod::Coverage::More::Declared->declarations_for( 'Some::Class', [ 'new', 'size' ] ); | ||||||||||||||||||||
| 31 | 37 | ▶ | sub declarations_for { | ||||||||||||||||||
|
Subroutine
declarations_for: called CC=6 SCAR=19.0
Pod
documented
| |||||||||||||||||||||
| 32 | 37 | my ( $class, $package, $names ) = @_; | |||||||||||||||||||
| 33 | 37 | my %declared; | |||||||||||||||||||
| 34 | 37 | foreach my $provider (@PROVIDERS) { | |||||||||||||||||||
| 35 | 222 | require_module($provider); | |||||||||||||||||||
| 36 | 222 | ▶ | next if !$provider->applies_to($package); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | 22 | my $found = $provider->declarations( $package, $names ); | |||||||||||||||||||
| 38 | 22 | foreach my $name ( keys %$found ) { | |||||||||||||||||||
| 39 | 23 | ▶ | if ( !$declared{$name} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 23 | $declared{$name} = $found->{$name}; | |||||||||||||||||||
| 41 | 23 | next; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | 0 | ▶ | $declared{$name}{body} //= $found->{$name}{body}; | ||||||||||||||||||
|
Condition0%0/3
$declared{$name}{"body"} //= $found->{$name}{"body"}
MC/DC0%0/2
$declared{$name}{"body"} //= $found->{$name}{"body"}
$declared{$name}{"body"}
$found->{$name}{"body"}
Truth table0%0/3
A //= B
A= $declared{$name}{"body"}B= $found->{$name}{"body"}
| |||||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | 37 | return \%declared; | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 20 | 1; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | __END__ | ||||||||||||||||||||