lib/Pod/Coverage/More/Declared/TypeParams.pm

filter: Statementstmt 100% 46 / 46 Branchbran 95.4% 21 / 22 Conditioncond 63.6% 7 / 11 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 90.6% 87 / 96 CC 19 SCAR 19.8
CC
19
Cov
94%
declarations
10.0
_signature_of
9.4
applies_to
2.0
CRAP 7.2
« lib/Pod/Coverage/More/Analyzer/Perl5_44.pm ↑ Summary lib/Pod/Coverage/More/Analyzer/Perl5_38.pm »
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
BranchTrueFalseTotal
$INC{'Type/Params.pm'} ? : 8 34 42
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
BranchTrueFalseTotal
my $signature = _signature_of($stash->get_symbol("&$name")) or next 2 23 25
35 2 my @params;
36 2 my $index = 0;
37 2 ▶ push @params, Pod::Coverage::More::Declared->invocant if $signature->method;
Branch: 1 branch
BranchTrueFalseTotal
if $signature->method 1 1 2
38 2 ▶ $index++ if $signature->method;
Branch: 1 branch
BranchTrueFalseTotal
if $signature->method 1 1 2
39 2 foreach my $param ( @{ $signature->parameters } ) {
40 4 ▶ my %where = $signature->is_named ? ( named => $param->name ) : ( index => $index++ );
Branch: 1 branch
BranchTrueFalseTotal
$signature->is_named ? : 2 2 4
41 4 ▶ push @params, { name => undef, type => $param->type, optional => $param->optional ? 1 : 0, invocant => 0, %where };
Branch: 1 branch
BranchTrueFalseTotal
$param->optional ? : 2 2 4
42 }
43 2 ▶ $declared{$name} = {
Branch: 2 branches
BranchTrueFalseTotal
$signature->method ? : 1 1 2
$signature->has_returns_scalar ? : 1 1 2
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
BranchTrueFalseTotal
if $cv->XSUB or $cv->CvFLAGS & 4 2 23 25
Condition66%2/3
$cv->XSUB or $cv->CvFLAGS & 4
l!l&&r!l&&!r
2023
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if B::class($names[$index]) eq "SPECIAL" or ($names[$index]->PVX // "") ne "\$sig" 84 2 86
Condition80%4/5
B::class($names[$index]) eq "SPECIAL" or ($names[$index]->PVX // "") ne "\$sig"
l!l&&r!l&&!r
0842
$names[$index]->PVX // ""
l!l
4244
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
ABresult
1X1
011
000
64 2 my $value = ${ $values[$index]->object_2svref };
65 2 ▶ return $value if blessed($value) && $value->isa('Type::Params::Signature');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($value) and $value->isa("Type::Params::Signature") 2 0 2
Condition33%1/3
builtin::blessed($value) and $value->isa("Type::Params::Signature")
!ll&&!rl&&r
002
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")
ABresult
0X0
100
111
66 }
67 21 return;
68 }
69  
70 13 1;
71  
72 __END__
« lib/Pod/Coverage/More/Analyzer/Perl5_44.pm ↑ Summary lib/Pod/Coverage/More/Analyzer/Perl5_38.pm »