| 1 | # ABSTRACT: Declarations of the signatures of Type::Params | ||||||||||||||||||||||||||||||||
| 2 | # PODNAME: Pod::Coverage::More::Declared::TypeParams | ||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | package Pod::Coverage::More::Declared::TypeParams 0.003; | ||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use 5.036; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use warnings FATAL => q{all}; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use Pod::Coverage::More::Declared; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 13 | ▶ | use B (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 13 | ▶ | use Package::Stash; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 13 | ▶ | use Scalar::Util qw{blessed}; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | # Whether L<Type::Params> is loaded, so that it can have declared subs of C<package>. | ||||||||||||||||||||||||||||||||
| 17 | # @param package Str the name of the package | ||||||||||||||||||||||||||||||||
| 18 | # @returns Bool | ||||||||||||||||||||||||||||||||
| 19 | # @example next if !Pod::Coverage::More::Declared::TypeParams->applies_to('Some::Class'); | ||||||||||||||||||||||||||||||||
| 20 | 42 | ▶ | sub applies_to { | ||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 21 | 42 | ▶ | return $INC{'Type/Params.pm'} ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | # The declarations of the subs of C<package> that C<names> lists, as L<Pod::Coverage::More::Declared> describes them. | ||||||||||||||||||||||||||||||||
| 25 | # @param package Str the name of the package | ||||||||||||||||||||||||||||||||
| 26 | # @param names ArrayRef[Str] the names of the subs | ||||||||||||||||||||||||||||||||
| 27 | # @returns HashRef from the name of each declared sub to its declaration | ||||||||||||||||||||||||||||||||
| 28 | # @example my $declared = Pod::Coverage::More::Declared::TypeParams->declarations( 'Some::Class', ['new'] ); | ||||||||||||||||||||||||||||||||
| 29 | 8 | ▶ | sub declarations { | ||||||||||||||||||||||||||||||
|
Subroutine
declarations: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 30 | 8 | my ( $class, $package, $names ) = @_; | |||||||||||||||||||||||||||||||
| 31 | 8 | my $stash = Package::Stash->new($package); | |||||||||||||||||||||||||||||||
| 32 | 8 | my %declared; | |||||||||||||||||||||||||||||||
| 33 | 8 | foreach my $name (@$names) { | |||||||||||||||||||||||||||||||
| 34 | 25 | ▶ | my $signature = _signature_of( $stash->get_symbol("&$name") ) or next; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 35 | 2 | my @params; | |||||||||||||||||||||||||||||||
| 36 | 2 | my $index = 0; | |||||||||||||||||||||||||||||||
| 37 | 2 | ▶ | push @params, Pod::Coverage::More::Declared->invocant if $signature->method; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | $index++ if $signature->method; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | 2 | foreach my $param ( @{ $signature->parameters } ) { | |||||||||||||||||||||||||||||||
| 40 | 4 | ▶ | my %where = $signature->is_named ? ( named => $param->name ) : ( index => $index++ ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 41 | 4 | ▶ | push @params, { name => undef, type => $param->type, optional => $param->optional ? 1 : 0, invocant => 0, %where }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||
| 43 | 2 | ▶ | $declared{$name} = { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 44 | via => 'Type::Params', | ||||||||||||||||||||||||||||||||
| 45 | role => $signature->method ? 'method' : 'function', | ||||||||||||||||||||||||||||||||
| 46 | params => \@params, | ||||||||||||||||||||||||||||||||
| 47 | returns => [ $signature->has_returns_scalar ? $signature->returns_scalar : () ], | ||||||||||||||||||||||||||||||||
| 48 | body => $signature->next, | ||||||||||||||||||||||||||||||||
| 49 | }; | ||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||
| 51 | 8 | return \%declared; | |||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | # The signature object that the wrapper CODE closes over, or nothing when CODE is no wrapper of Type::Params. | ||||||||||||||||||||||||||||||||
| 55 | 25 | ▶ | sub _signature_of { | ||||||||||||||||||||||||||||||
|
Subroutine
_signature_of: called CC=9 SCAR=22.4
| |||||||||||||||||||||||||||||||||
| 56 | 25 | my ($code) = @_; | |||||||||||||||||||||||||||||||
| 57 | 25 | my $cv = B::svref_2object($code); | |||||||||||||||||||||||||||||||
| 58 | 25 | ▶ | return if $cv->XSUB || ( $cv->CvFLAGS & B::CVf_CONST ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cv->XSUB or $cv->CvFLAGS & 4
MC/DC50%1/2
$cv->XSUB or $cv->CvFLAGS & 4
$cv->XSUB
$cv->CvFLAGS & 4
Truth table66%2/3
A or B
A= $cv->XSUBB= $cv->CvFLAGS & 4
| |||||||||||||||||||||||||||||||||
| 59 | 23 | my $padlist = $cv->PADLIST; | |||||||||||||||||||||||||||||||
| 60 | 23 | my @names = $padlist->ARRAYelt(0)->ARRAY; | |||||||||||||||||||||||||||||||
| 61 | 23 | my @values = $padlist->ARRAYelt(1)->ARRAY; | |||||||||||||||||||||||||||||||
| 62 | 23 | foreach my $index ( 1 .. $#names ) { | |||||||||||||||||||||||||||||||
| 63 | 86 | ▶ | next if B::class( $names[$index] ) eq 'SPECIAL' || ( $names[$index]->PVX // q{} ) ne q{$sig}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
B::class($names[$index]) eq "SPECIAL" or ($names[$index]->PVX // "") ne "\$sig"
$names[$index]->PVX // ""
MC/DC50%1/2
B::class($names[$index]) eq "SPECIAL" or ($names[$index]->PVX // "") ne "\$sig"
B::class($names[$index]) eq "SPECIAL"
$names[$index]->PVX
Truth table66%2/3
A or B
A= B::class($names[$index]) eq "SPECIAL"B= $names[$index]->PVX
| |||||||||||||||||||||||||||||||||
| 64 | 2 | my $value = ${ $values[$index]->object_2svref }; | |||||||||||||||||||||||||||||||
| 65 | 2 | ▶ | return $value if blessed($value) && $value->isa('Type::Params::Signature'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($value) and $value->isa("Type::Params::Signature")
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Type::Params::Signature")
builtin::blessed($value)
$value->isa("Type::Params::Signature")
Truth table33%1/3
A and B
A= builtin::blessed($value)B= $value->isa("Type::Params::Signature")
| |||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | 21 | return; | |||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 13 | 1; | |||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||||||