Sub/Meta/Param.pm

filter: Statementstmt 100% 125 / 125 Branchbran 100% 68 / 68 Conditioncond 100% 15 / 15 MC/DCmcdc 100% 9 / 9 Subroutinesub 100% 33 / 33 Podpod 100% 28 / 28 totaltotal 100% 278 / 278 CC 41 SCAR 16.5
CC
41
Cov
100%
is_same_interface
12.0
is_relaxed_same_interface
10.0
new
7.0
CRAP 5.2
« Sub/Meta/Parameters.pm ↑ Summary Sub/Meta.pm »
1 package Sub::Meta::Param;
2 45 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 45 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 45 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 45 our $VERSION = "0.15";
7  
8 45 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 use overload
11 45 ▶ fallback => 1,
Subroutine BEGIN: called CC=1 SCAR=0.0
12 eq => \&is_same_interface,
13 45 ;
14  
15 45 my %DEFAULT = ( named => 0, optional => 0, invocant => 0 );
16  
17 255 ▶sub new {
Subroutine new: called CC=7 SCAR=19.5
Pod documented
18 255 my ($class, @args) = @_;
19 255 my $v = $args[0];
20 255 ▶ my %args = @args == 1 ? ref $v && (ref $v eq 'HASH') ? %{$v}
Branch: 2 branches
BranchTrueFalseTotal
@args == 1 ? : 162 93 255
ref $v && ref $v eq 'HASH' ? : 76 86 162
Condition100%3/3
ref $v and ref $v eq "HASH"
!ll&&!rl&&r
652176
MC/DC100%2/2
ref $v and ref $v eq "HASH"
ref $v ref $v eq "HASH"
Truth table100%3/3
A and B
A= ref $vB= ref $v eq "HASH"
ABresult
0X0
100
111
21 : ( type => $v )
22 : @args;
23  
24 255 ▶ $args{optional} = !delete $args{required} if exists $args{required};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"required"} 26 229 255
25 255 ▶ $args{named} = !delete $args{positional} if exists $args{positional};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"positional"} 26 229 255
26 255 ▶ $args{type} = delete $args{isa} if exists $args{isa};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"isa"} 4 251 255
27  
28 255 %args = (%DEFAULT, %args);
29  
30 255 return bless \%args => $class;
31 }
32  
33 165 ▶sub name() { my $self = shift; return $self->{name} // '' }
Subroutine name: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
$self->{"name"} // ""
l!l
10164
MC/DC100%1/1
$self->{"name"} // ""
$self->{"name"}
Truth table100%2/2
A
A= $self->{"name"}
Aresult
11
00
34 583 ▶sub type() { my $self = shift; return $self->{type} }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
35 61 ▶sub default() { my $self = shift; return $self->{default} } ## no critic (ProhibitBuiltinHomonyms)
Subroutine default: called CC=1 SCAR=0.0
Pod documented
36 61 ▶sub coerce() { my $self = shift; return $self->{coerce} }
Subroutine coerce: called CC=1 SCAR=0.0
Pod documented
37 581 ▶sub optional() { my $self = shift; return !!$self->{optional} }
Subroutine optional: called CC=1 SCAR=0.0
Pod documented
38 144 ▶sub required() { my $self = shift; return !$self->{optional} }
Subroutine required: called CC=1 SCAR=0.0
Pod documented
39 654 ▶sub named() { my $self = shift; return !!$self->{named} }
Subroutine named: called CC=1 SCAR=0.0
Pod documented
40 217 ▶sub positional() { my $self = shift; return !$self->{named} }
Subroutine positional: called CC=1 SCAR=0.0
Pod documented
41 61 ▶sub invocant() { my $self = shift; return !!$self->{invocant} }
Subroutine invocant: called CC=1 SCAR=0.0
Pod documented
42  
43 548 ▶sub has_name() { my $self = shift; return defined $self->{name} }
Subroutine has_name: called CC=1 SCAR=0.0
Pod documented
44 433 ▶sub has_type() { my $self = shift; return defined $self->{type} }
Subroutine has_type: called CC=1 SCAR=0.0
Pod documented
45 61 ▶sub has_default() { my $self = shift; return defined $self->{default} }
Subroutine has_default: called CC=1 SCAR=0.0
Pod documented
46 61 ▶sub has_coerce() { my $self = shift; return defined $self->{coerce} }
Subroutine has_coerce: called CC=1 SCAR=0.0
Pod documented
47  
48 3 ▶sub set_name { my ($self, $v) = @_; $self->{name} = $v; return $self }
Subroutine set_name: called CC=1 SCAR=0.0
Pod documented
49 4 ▶sub set_type { my ($self, $v) = @_; $self->{type} = $v; return $self }
Subroutine set_type: called CC=1 SCAR=0.0
Pod documented
50 4 ▶sub set_default { my ($self, $v) = @_; $self->{default} = $v; return $self }
Subroutine set_default: called CC=1 SCAR=0.0
Pod documented
51 4 ▶sub set_coerce { my ($self, $v) = @_; $self->{coerce} = $v; return $self }
Subroutine set_coerce: called CC=1 SCAR=0.0
Pod documented
52 6 ▶sub set_optional { my ($self, $v) = @_; $self->{optional} = !!(defined $v ? $v : 1); return $self }
Subroutine set_optional: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 4 2 6
53 6 ▶sub set_required { my ($self, $v) = @_; $self->{optional} = !(defined $v ? $v : 1); return $self }
Subroutine set_required: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 4 2 6
54 6 ▶sub set_named { my ($self, $v) = @_; $self->{named} = !!(defined $v ? $v : 1); return $self }
Subroutine set_named: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 4 2 6
55 6 ▶sub set_positional { my ($self, $v) = @_; $self->{named} = !(defined $v ? $v : 1); return $self }
Subroutine set_positional: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 4 2 6
56 71 ▶sub set_invocant { my ($self, $v) = @_; $self->{invocant} = !!(defined $v ? $v : 1); return $self }
Subroutine set_invocant: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 69 2 71
57  
58 # alias
59 sub isa_() :method; # NOT isa
60 45 *isa_ = \&type;
61  
62 sub set_isa;
63 45 *set_isa = \&set_type;
64  
65 117 ▶sub is_same_interface {
Subroutine is_same_interface: called CC=12 SCAR=24.8
Pod documented
66 117 my ($self, $other) = @_;
67  
68 117 ▶ return unless Scalar::Util::blessed($other) && $other->isa('Sub::Meta::Param');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) and $other->isa("Sub::Meta::Param") 10 107 117
Condition100%3/3
builtin::blessed($other) and $other->isa("Sub::Meta::Param")
!ll&&!rl&&r
91107
MC/DC100%2/2
builtin::blessed($other) and $other->isa("Sub::Meta::Param")
builtin::blessed($other) $other->isa("Sub::Meta::Param")
Truth table100%3/3
A and B
A= builtin::blessed($other)B= $other->isa("Sub::Meta::Param")
ABresult
0X0
100
111
69  
70 107 ▶ if ($self->has_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_name) { } 16 91 107
71 16 ▶ return unless $self->name eq $other->name
Branch: 1 branch
BranchTrueFalseTotal
unless $self->name eq $other->name 5 11 16
72 }
73 else {
74 91 ▶ return if $other->has_name
Branch: 1 branch
BranchTrueFalseTotal
if $other->has_name 5 86 91
75 }
76  
77 97 ▶ if ($self->has_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_type) { } 68 29 97
78 68 ▶ return unless $self->type eq ($other->type // '');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->type eq ($other->type // "") 22 46 68
Condition100%2/2
$other->type // ""
l!l
662
MC/DC100%1/1
$other->type // ""
$other->type
Truth table100%2/2
A
A= $other->type
Aresult
11
00
79 }
80 else {
81 29 ▶ return if $other->has_type
Branch: 1 branch
BranchTrueFalseTotal
if $other->has_type 2 27 29
82 }
83  
84 73 ▶ return unless $self->optional eq $other->optional;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->optional eq $other->optional 5 68 73
85  
86 68 ▶ return unless $self->named eq $other->named;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->named eq $other->named 5 63 68
87  
88 63 return !!1;
89 }
90  
91 98 ▶sub is_relaxed_same_interface {
Subroutine is_relaxed_same_interface: called CC=10 SCAR=23.0
Pod documented
92 98 my ($self, $other) = @_;
93  
94 98 ▶ return unless Scalar::Util::blessed($other) && $other->isa('Sub::Meta::Param');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) and $other->isa("Sub::Meta::Param") 2 96 98
Condition100%3/3
builtin::blessed($other) and $other->isa("Sub::Meta::Param")
!ll&&!rl&&r
1196
MC/DC100%2/2
builtin::blessed($other) and $other->isa("Sub::Meta::Param")
builtin::blessed($other) $other->isa("Sub::Meta::Param")
Truth table100%3/3
A and B
A= builtin::blessed($other)B= $other->isa("Sub::Meta::Param")
ABresult
0X0
100
111
95  
96 96 ▶ if ($self->has_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_name) 14 82 96
97 14 ▶ return unless $self->name eq $other->name
Branch: 1 branch
BranchTrueFalseTotal
unless $self->name eq $other->name 5 9 14
98 }
99  
100 91 ▶ if ($self->has_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_type) 57 34 91
101 57 ▶ return unless $self->type eq ($other->type // '');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->type eq ($other->type // "") 20 37 57
Condition100%2/2
$other->type // ""
l!l
552
MC/DC100%1/1
$other->type // ""
$other->type
Truth table100%2/2
A
A= $other->type
Aresult
11
00
102 }
103  
104 71 ▶ return unless $self->optional eq $other->optional;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->optional eq $other->optional 5 66 71
105  
106 66 ▶ return unless $self->named eq $other->named;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->named eq $other->named 5 61 66
107  
108 61 return !!1;
109 }
110  
111 24 ▶sub is_same_interface_inlined {
Subroutine is_same_interface_inlined: called CC=3 SCAR=11.0
Pod documented
112 24 my ($self, $v) = @_;
113  
114 24 my @src;
115 24 push @src => sprintf("Scalar::Util::blessed(%s) && %s->isa('Sub::Meta::Param')", $v, $v);
116  
117 24 ▶ push @src => $self->has_name ? sprintf("'%s' eq %s->name", $self->name, $v)
Branch: 1 branch
BranchTrueFalseTotal
$self->has_name ? : 3 21 24
118 : sprintf('!%s->has_name', $v);
119  
120 24 ▶ push @src => $self->has_type ? sprintf("'%s' eq (%s->type // '')", "@{[$self->type]}", $v)
Branch: 1 branch
BranchTrueFalseTotal
$self->has_type ? : 15 9 24
121 : sprintf('!%s->has_type', $v);
122  
123 24 push @src => sprintf("'%s' eq %s->optional", $self->optional, $v);
124  
125 24 push @src => sprintf("'%s' eq %s->named", $self->named, $v);
126  
127 24 return join "\n && ", @src;
128 }
129  
130 30 ▶sub is_relaxed_same_interface_inlined {
Subroutine is_relaxed_same_interface_inlined: called CC=3 SCAR=11.0
Pod documented
131 30 my ($self, $v) = @_;
132  
133 30 my @src;
134 30 push @src => sprintf("Scalar::Util::blessed(%s) && %s->isa('Sub::Meta::Param')", $v, $v);
135  
136 30 ▶ push @src => sprintf("'%s' eq %s->name", $self->name, $v) if $self->has_name;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_name 3 27 30
137  
138 30 ▶ push @src => sprintf("'%s' eq (%s->type // '')", "@{[$self->type]}", $v) if $self->has_type;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_type 21 9 30
139  
140 30 push @src => sprintf("'%s' eq %s->optional", $self->optional, $v);
141  
142 30 push @src => sprintf("'%s' eq %s->named", $self->named, $v);
143  
144 30 return join "\n && ", @src;
145 }
146  
147 66 ▶sub display {
Subroutine display: called CC=5 SCAR=16.1
Pod documented
148 66 my $self = shift;
149  
150 66 my $s = '';
151 66 ▶ $s .= $self->type if $self->has_type;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_type 58 8 66
152 66 ▶ if ($self->has_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_name) 10 56 66
153 10 ▶ $s .= sprintf("%s%s%s",
Branch: 2 branches
BranchTrueFalseTotal
$self->has_type ? : 6 4 10
$self->named ? : 1 9 10
154 $self->has_type ? ' ' : '',
155 $self->named ? ':' : '',
156 $self->name);
157 }
158 66 return $s;
159 }
160  
161  
162 45 1;
163 __END__
« Sub/Meta/Parameters.pm ↑ Summary Sub/Meta.pm »