lib/Pod/Coverage/More/Types.pm

filter: Statementstmt 100% 81 / 81 Branchbran 96.4% 54 / 56 Conditioncond 89.4% 17 / 19 MC/DCmcdc 83.3% 10 / 12 Subroutinesub 100% 12 / 12 Podpod 100% 3 / 3 totaltotal 96.7% 177 / 183 CC 37 SCAR 26.1
CC
37
Cov
97%
type_of_value
22.0
type_of_usage
11.0
type_named
6.0
CRAP 13.6
« lib/Pod/Coverage/More/Analyzer.pm ↑ Summary lib/Pod/Coverage/More/Declared/MOP.pm »
1 # ABSTRACT: The Type::Tiny constraints that the evidence of an analysis amounts to
2 # PODNAME: Pod::Coverage::More::Types
3  
4 package Pod::Coverage::More::Types 0.005;
5  
6 25 ▶use 5.036;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 25 ▶use warnings FATAL => q{all};
Subroutine BEGIN: called CC=1 SCAR=0.0
8 25 ▶use re q{/xsaa};
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 25 ▶use Exporter qw{import};
Subroutine BEGIN: called CC=1 SCAR=0.0
11 25 ▶use Scalar::Util qw{blessed};
Subroutine BEGIN: called CC=1 SCAR=0.0
12 25 ▶use Type::Registry;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 25 ▶use Type::Tiny::Intersection;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 25 ▶use Type::Tiny::Union;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 25 ▶use Types::Standard qw{Any ArrayRef Bool CodeRef GlobRef HasMethods HashRef InstanceOf Int Maybe Num Object Ref ScalarRef Str Undef};
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 25 our @EXPORT_OK = qw{type_of_value type_of_usage type_named};
18  
19  
20 504 ▶sub type_of_value {
Subroutine type_of_value: called CC=22 SCAR=30.9
Pod documented
21 504 my ($evidence) = @_;
22 504 my $type = $evidence->{type};
23  
24 504 ▶ if ( $type eq 'number' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "number") 131 373 504
25 131 my $value = $evidence->{value};
26 131 ▶ return Maybe [Int] if $evidence->{integer} && $evidence->{maybe_undef};
Branch: 1 branch
BranchTrueFalseTotal
if $evidence->{"integer"} and $evidence->{"maybe_undef"} 2 129 131
Condition100%3/3
$evidence->{"integer"} and $evidence->{"maybe_undef"}
!ll&&!rl&&r
12182
MC/DC100%2/2
$evidence->{"integer"} and $evidence->{"maybe_undef"}
$evidence->{"integer"} $evidence->{"maybe_undef"}
Truth table100%3/3
A and B
A= $evidence->{"integer"}B= $evidence->{"maybe_undef"}
ABresult
0X0
100
111
27 129 ▶ return Int if $evidence->{integer};
Branch: 1 branch
BranchTrueFalseTotal
if $evidence->{"integer"} 8 121 129
28 121 ▶ return ( defined $value && $value =~ m/\A-?\d+\z/ ) ? Int : Num;
Branch: 1 branch
BranchTrueFalseTotal
defined $value && $value =~ /\A-?\d+\z/aasx ? : 74 47 121
Condition100%3/3
defined $value and $value =~ /\A-?\d+\z/aasx
!ll&&!rl&&r
46174
MC/DC100%2/2
defined $value and $value =~ /\A-?\d+\z/aasx
defined $value $value =~ /\A-?\d+\z/aasx
Truth table100%3/3
A and B
A= defined $valueB= $value =~ /\A-?\d+\z/aasx
ABresult
0X0
100
111
29 }
30 373 ▶ return Str if $type eq 'string';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "string" 35 338 373
31 338 ▶ return Bool if $type eq 'boolean' || $type eq 'context';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "boolean" or $type eq "context" 1 337 338
Condition66%2/3
$type eq "boolean" or $type eq "context"
l!l&&r!l&&!r
10337
MC/DC50%1/2
$type eq "boolean" or $type eq "context"
$type eq "boolean" $type eq "context"
Truth table66%2/3
A or B
A= $type eq "boolean"B= $type eq "context"
ABresult
1X1
011
000
32  
33 # An empty return gives undef to a caller that wants one value.
34 337 ▶ return Undef if $type eq 'undef' || $type eq 'empty';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "undef" or $type eq "empty" 135 202 337
Condition100%3/3
$type eq "undef" or $type eq "empty"
l!l&&r!l&&!r
11124202
MC/DC100%2/2
$type eq "undef" or $type eq "empty"
$type eq "undef" $type eq "empty"
Truth table100%3/3
A or B
A= $type eq "undef"B= $type eq "empty"
ABresult
1X1
011
000
35  
36 202 ▶ return HashRef if $type eq 'hashref';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "hashref" 10 192 202
37 192 ▶ return ArrayRef if $type eq 'arrayref';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "arrayref" 31 161 192
38 161 ▶ return CodeRef if $type eq 'coderef';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "coderef" 0 161 161
39 161 ▶ return Ref if $type eq 'ref';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "ref" 0 161 161
40 161 ▶ if ( $type eq 'object' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "object") 27 134 161
41 27 ▶ my @classes = @{ $evidence->{classes} || [] };
Condition100%2/2
$evidence->{'classes'} || []
l!l
225
MC/DC100%1/1
$evidence->{'classes'} || []
$evidence->{'classes'}
Truth table100%2/2
A
A= $evidence->{'classes'}
Aresult
11
00
42 27 ▶ return InstanceOf [ $classes[0] ] if @classes == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @classes == 1 1 26 27
43 26 ▶ if ( @classes > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@classes > 1) 1 25 26
44 1 my @instances;
45 1 foreach my $class (@classes) {
46 2 push @instances, InstanceOf [$class];
47 }
48 1 return Type::Tiny::Union->new( type_constraints => \@instances );
49 }
50 25 ▶ return defined $evidence->{class} ? InstanceOf [ $evidence->{class} ] : Object;
Branch: 1 branch
BranchTrueFalseTotal
defined $evidence->{'class'} ? : 22 3 25
51 }
52 134 return;
53 }
54  
55  
56 496 ▶sub type_of_usage {
Subroutine type_of_usage: called CC=11 SCAR=24.0
Pod documented
57 496 my ($usage) = @_;
58 496 my @alternatives;
59 496 ▶ push @alternatives, HashRef if $usage->{hashref};
Branch: 1 branch
BranchTrueFalseTotal
if $usage->{"hashref"} 62 434 496
60 496 ▶ push @alternatives, ArrayRef if $usage->{arrayref};
Branch: 1 branch
BranchTrueFalseTotal
if $usage->{"arrayref"} 17 479 496
61 496 ▶ push @alternatives, CodeRef if $usage->{coderef};
Branch: 1 branch
BranchTrueFalseTotal
if $usage->{"coderef"} 2 494 496
62  
63 # Perl makes a string of a number, so a variable used as both is a string.
64 496 ▶ if ( $usage->{string} ) { push @alternatives, Str }
Branch: 2 branches
BranchTrueFalseTotal
if ($usage->{'string'}) { } 46 450 496
elsif ($usage->{'numeric'}) { } 58 392 450
65 58 elsif ( $usage->{numeric} ) { push @alternatives, Num }
66  
67 496 my $type;
68 496 ▶ $type = $alternatives[0] if @alternatives == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @alternatives == 1 183 313 496
69 496 ▶ $type = Type::Tiny::Union->new( type_constraints => \@alternatives ) if @alternatives > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @alternatives > 1 1 495 496
70  
71 496 ▶ my @methods = @{ $usage->{methods} || [] };
Condition100%2/2
$usage->{'methods'} || []
l!l
15481
MC/DC100%1/1
$usage->{'methods'} || []
$usage->{'methods'}
Truth table100%2/2
A
A= $usage->{'methods'}
Aresult
11
00
72 496 ▶ return $type if !@methods;
Branch: 1 branch
BranchTrueFalseTotal
unless @methods 481 15 496
73 15 my $duck = HasMethods [@methods];
74 15 ▶ return $duck if !$type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 14 1 15
75 1 return Type::Tiny::Intersection->new( type_constraints => [ $type, $duck ] );
76 }
77  
78 # The type words of the POD that Pod::Coverage::More has always read, in lower case.
79 25 our %POD_WORDS = (
80 scalar => Any,
81 mixed => Any,
82 string => Str,
83 integer => Int,
84 float => Num,
85 boolean => Bool,
86 object => Object,
87 scalarref => ScalarRef,
88 arrayref => ArrayRef,
89 hashref => HashRef,
90 coderef => CodeRef,
91 typeglobref => GlobRef,
92 array => ArrayRef,
93 hash => HashRef,
94 );
95  
96  
97 471 ▶sub type_named {
Subroutine type_named: called CC=6 SCAR=17.9
Pod documented
98 471 my ($name) = @_;
99 471 ▶ return if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 1 470 471
100 470 my $word = $POD_WORDS{ lc $name };
101 470 ▶ return $word if $word;
Branch: 1 branch
BranchTrueFalseTotal
if $word 122 348 470
102  
103 # No type expression has a %, and the error of a failed lookup takes NAME as a printf format, which warns.
104 348 ▶ return if index( $name, q{%} ) >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($name, "%") != -1 1 347 348
105  
106 347 state $registry = Type::Registry->new->add_types('Types::Standard');
107 347 my $type = eval { $registry->lookup($name) };
108  
109 # The parser of Type::Registry reads a number as a value, and gives it back as it is.
110 347 ▶ return if !blessed($type) || !$type->isa('Type::Tiny');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($type) and $type->isa("Type::Tiny") 61 286 347
Condition66%2/3
builtin::blessed($type) and $type->isa("Type::Tiny")
!ll&&!rl&&r
610286
MC/DC50%1/2
builtin::blessed($type) and $type->isa("Type::Tiny")
builtin::blessed($type) $type->isa("Type::Tiny")
Truth table66%2/3
A and B
A= builtin::blessed($type)B= $type->isa("Type::Tiny")
ABresult
0X0
100
111
111 286 return $type;
112 }
113  
114 25 1;
115  
116 __END__
« lib/Pod/Coverage/More/Analyzer.pm ↑ Summary lib/Pod/Coverage/More/Declared/MOP.pm »