Sub/Meta.pm

filter: Statementstmt 100% 293 / 293 Branchbran 100% 130 / 130 Conditioncond 100% 52 / 52 MC/DCmcdc 100% 32 / 32 Subroutinesub 100% 79 / 79 Podpod 100% 57 / 57 totaltotal 100% 643 / 643 CC 86 SCAR 14.5
CC
86
Cov
100%
error_message
10.0
new
9.0
is_same_interface
9.0
CRAP 4.3
« Sub/Meta/Param.pm ↑ Summary Sub/Meta/Type.pm »
1 package Sub::Meta;
2 29 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 29 our $VERSION = "0.15";
7  
8 29 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 29 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 29 ▶use Sub::Identify ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 29 ▶use Sub::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 29 ▶use attributes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 29 ▶use Sub::Meta::Parameters;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 29 ▶use Sub::Meta::Returns;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 29 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
18 # for Pure Perl
19 29 $ENV{PERL_SUB_IDENTIFY_PP} = $ENV{PERL_SUB_META_PP}; ## no critic (RequireLocalizedPunctuationVars)
20 }
21  
22 use overload
23 29 ▶ fallback => 1,
Subroutine BEGIN: called CC=1 SCAR=0.0
24 eq => \&is_same_interface
25 29 ;
26  
27 175 ▶sub parameters_class { return 'Sub::Meta::Parameters' }
Subroutine parameters_class: called CC=1 SCAR=0.0
Pod documented
28 178 ▶sub returns_class { return 'Sub::Meta::Returns' }
Subroutine returns_class: called CC=1 SCAR=0.0
Pod documented
29  
30 9 ▶sub _croak { require Carp; goto &Carp::croak }
Subroutine _croak: called CC=1 SCAR=0.0
31  
32 200 ▶sub new {
Subroutine new: called CC=9 SCAR=22.0
Pod documented
33 200 my ($class, @args) = @_;
34  
35 my %args = @args == 1 && (ref $args[0]||"") ne "HASH" ? _croak "single arg must be hashref"
36 200 ▶ : @args == 1 ? %{$args[0]}
Branch: 2 branches
BranchTrueFalseTotal
@args == 1 && (ref $args[0] || '') ne 'HASH' ? : 4 196 200
@args == 1 ? : 91 105 196
Condition100%5/5
@args == 1 and (ref $args[0] || "") ne "HASH"
!ll&&!rl&&r
105914
ref $args[0] || ''
l!l
941
MC/DC100%2/2
@args == 1 and (ref $args[0] || "") ne "HASH"
@args == 1 ref $args[0]
Truth table100%3/3
A and B
A= @args == 1B= ref $args[0]
ABresult
0X0
100
111
37 : @args;
38  
39 196 my $self = bless \%args => $class;
40  
41 196 ▶ $self->set_sub(delete $args{sub}) if exists $args{sub}; # build subinfo
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"sub"} 24 172 196
42 196 ▶ $self->set_subname(delete $args{subname}) if exists $args{subname};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"subname"} 55 141 196
43 196 ▶ $self->set_stashname(delete $args{stashname}) if exists $args{stashname};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"stashname"} 1 195 196
44 196 ▶ $self->set_fullname(delete $args{fullname}) if exists $args{fullname};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"fullname"} 2 194 196
45  
46 196 $self->set_is_method($self->_normalize_args_is_method(\%args));
47 196 $self->set_parameters($self->_normalize_args_parameters(\%args));
48 196 $self->set_returns($args{returns});
49  
50 # cleaning
51 196 delete $args{args};
52 196 delete $args{slurpy};
53 196 delete $args{invocant};
54 196 delete $args{nshift};
55  
56 196 return $self;
57 }
58  
59 196 ▶sub _normalize_args_is_method {
Subroutine _normalize_args_is_method: called CC=8 SCAR=20.8
60 196 my ($self, $args) = @_;
61  
62 196 ▶ return !!$args->{invocant} if exists $args->{invocant};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"invocant"} 4 192 196
63 192 ▶ return !!$args->{nshift} if exists $args->{nshift};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"nshift"} 2 190 192
64 190 ▶ return !!$args->{parameters}{nshift} if exists $args->{parameters} && exists $args->{parameters}{nshift};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"parameters"} and exists $args->{"parameters"}{"nshift"} 1 189 190
Condition100%3/3
exists $args->{"parameters"} and exists $args->{"parameters"}{"nshift"}
!ll&&!rl&&r
163261
MC/DC100%2/2
exists $args->{"parameters"} and exists $args->{"parameters"}{"nshift"}
exists $args->{"parameters"} exists $args->{"parameters"}{"nshift"}
Truth table100%3/3
A and B
A= exists $args->{"parameters"}B= exists $args->{"parameters"}{"nshift"}
ABresult
0X0
100
111
65 189 ▶ return !!$args->{parameters}{invocant} if exists $args->{parameters} && exists $args->{parameters}{invocant};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"parameters"} and exists $args->{"parameters"}{"invocant"} 1 188 189
Condition100%3/3
exists $args->{"parameters"} and exists $args->{"parameters"}{"invocant"}
!ll&&!rl&&r
163251
MC/DC100%2/2
exists $args->{"parameters"} and exists $args->{"parameters"}{"invocant"}
exists $args->{"parameters"} exists $args->{"parameters"}{"invocant"}
Truth table100%3/3
A and B
A= exists $args->{"parameters"}B= exists $args->{"parameters"}{"invocant"}
ABresult
0X0
100
111
66 188 ▶ return !!$args->{is_method} if exists $args->{is_method};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"is_method"} 20 168 188
67 168 return !!0;
68 }
69  
70 196 ▶sub _normalize_args_parameters {
Subroutine _normalize_args_parameters: called CC=7 SCAR=19.5
71 196 my ($self, $args) = @_;
72  
73 196 ▶ if (exists $args->{parameters}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{'parameters'}) { } 27 169 196
74 27 return $args->{parameters};
75 }
76 else {
77 my $nshift = exists $args->{nshift} ? $args->{nshift}
78 169 ▶ : $self->is_method ? 1
Branch: 2 branches
BranchTrueFalseTotal
exists $args->{'nshift'} ? : 3 166 169
$self->is_method ? : 14 152 166
79 : 0;
80  
81 169 my $parameters;
82 169 ▶ $parameters->{args} = $args->{args} if exists $args->{args};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"args"} 37 132 169
83 169 ▶ $parameters->{slurpy} = $args->{slurpy} if exists $args->{slurpy};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"slurpy"} 4 165 169
84 169 ▶ $parameters->{invocant} = $args->{invocant} if exists $args->{invocant};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"invocant"} 4 165 169
85 169 $parameters->{nshift} = $nshift;
86 169 return $parameters;
87 }
88 }
89  
90 526 ▶sub sub() :method { my $self = shift; return $self->{sub} } ## no critic (ProhibitBuiltinHomonyms)
Subroutine sub: called CC=1 SCAR=0.0
Pod documented
91 267 ▶sub subname() { my $self = shift; return $self->subinfo->[1] // '' }
Subroutine subname: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
$self->subinfo->[1] // ""
l!l
21849
MC/DC100%1/1
$self->subinfo->[1] // ""
$self->subinfo->[1]
Truth table100%2/2
A
A= $self->subinfo->[1]
Aresult
11
00
92 49 ▶sub stashname() { my $self = shift; return $self->subinfo->[0] // '' }
Subroutine stashname: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
$self->subinfo->[0] // ""
l!l
3316
MC/DC100%1/1
$self->subinfo->[0] // ""
$self->subinfo->[0]
Truth table100%2/2
A
A= $self->subinfo->[0]
Aresult
11
00
93 40 ▶sub fullname() {
Subroutine fullname: called CC=3 SCAR=11.0
Pod documented
94 40 my $self = shift;
95 40 my $s = '';
96 40 ▶ $s .= $self->stashname . '::' if $self->has_stashname;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_stashname 19 21 40
97 40 ▶ $s .= $self->subname if $self->has_subname;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_subname 17 23 40
98 40 return $s;
99 }
100  
101 718 ▶sub subinfo() {
Subroutine subinfo: called CC=2 SCAR=6.9
Pod documented
102 718 my $self = shift;
103 718 ▶ return $self->{subinfo} if $self->{subinfo};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"subinfo"} 625 93 718
104 93 $self->{subinfo} = $self->_build_subinfo;
105 93 return $self->{subinfo};
106 }
107  
108 55 ▶sub file() { my $self = shift; return $self->{file} ||= $self->_build_file }
Subroutine file: called CC=2 SCAR=6.9
Pod documented
Condition100%3/3
$self->{"file"} ||= $self->_build_file
l!l&&r!l&&!r
92620
MC/DC100%2/2
$self->{"file"} ||= $self->_build_file
$self->{"file"} $self->_build_file
Truth table100%3/3
A ||= B
A= $self->{"file"}B= $self->_build_file
ABresult
1X1
011
000
109 55 ▶sub line() { my $self = shift; return $self->{line} ||= $self->_build_line }
Subroutine line: called CC=2 SCAR=6.9
Pod documented
Condition100%3/3
$self->{"line"} ||= $self->_build_line
l!l&&r!l&&!r
92620
MC/DC100%2/2
$self->{"line"} ||= $self->_build_line
$self->{"line"} $self->_build_line
Truth table100%3/3
A ||= B
A= $self->{"line"}B= $self->_build_line
ABresult
1X1
011
000
110 83 ▶sub prototype() :method { my $self = shift; return $self->{prototype} ||= $self->_build_prototype } ## no critic (ProhibitBuiltinHomonyms)
Subroutine prototype: called CC=2 SCAR=6.9
Pod documented
Condition100%3/3
$self->{"prototype"} ||= $self->_build_prototype
l!l&&r!l&&!r
11270
MC/DC100%2/2
$self->{"prototype"} ||= $self->_build_prototype
$self->{"prototype"} $self->_build_prototype
Truth table100%3/3
A ||= B
A= $self->{"prototype"}B= $self->_build_prototype
ABresult
1X1
011
000
111 83 ▶sub attribute() { my $self = shift; return $self->{attribute} ||= $self->_build_attribute }
Subroutine attribute: called CC=2 SCAR=6.9
Pod documented
Condition100%3/3
$self->{"attribute"} ||= $self->_build_attribute
l!l&&r!l&&!r
192836
MC/DC100%2/2
$self->{"attribute"} ||= $self->_build_attribute
$self->{"attribute"} $self->_build_attribute
Truth table100%3/3
A ||= B
A= $self->{"attribute"}B= $self->_build_attribute
ABresult
1X1
011
000
112 58 ▶sub is_constant() { my $self = shift; return $self->{is_constant} ||= !!$self->_build_is_constant }
Subroutine is_constant: called CC=2 SCAR=6.9
Pod documented
Condition100%3/3
$self->{"is_constant"} ||= !!$self->_build_is_constant
l!l&&r!l&&!r
3253
MC/DC100%2/2
$self->{"is_constant"} ||= !!$self->_build_is_constant
$self->{"is_constant"} !!$self->_build_is_constant
Truth table100%3/3
A ||= B
A= $self->{"is_constant"}B= !!$self->_build_is_constant
ABresult
1X1
011
000
113 562 ▶sub is_method() { my $self = shift; return !!$self->{is_method} }
Subroutine is_method: called CC=1 SCAR=0.0
Pod documented
114 928 ▶sub parameters() { my $self = shift; return $self->{parameters} }
Subroutine parameters: called CC=1 SCAR=0.0
Pod documented
115 522 ▶sub returns() { my $self = shift; return $self->{returns} }
Subroutine returns: called CC=1 SCAR=0.0
Pod documented
116  
117 15 ▶sub args() { my $self = shift; return $self->parameters->args }
Subroutine args: called CC=1 SCAR=0.0
Pod documented
118 2 ▶sub all_args() { my $self = shift; return $self->parameters->all_args }
Subroutine all_args: called CC=1 SCAR=0.0
Pod documented
119 12 ▶sub slurpy() { my $self = shift; return $self->parameters->slurpy }
Subroutine slurpy: called CC=1 SCAR=0.0
Pod documented
120 11 ▶sub nshift() { my $self = shift; return $self->parameters->nshift }
Subroutine nshift: called CC=1 SCAR=0.0
Pod documented
121 11 ▶sub invocant() { my $self = shift; return $self->parameters->invocant }
Subroutine invocant: called CC=1 SCAR=0.0
Pod documented
122 1 ▶sub invocants() { my $self = shift; return $self->parameters->invocants }
Subroutine invocants: called CC=1 SCAR=0.0
Pod documented
123  
124 120 ▶sub has_sub() { my $self = shift; return defined $self->{sub} }
Subroutine has_sub: called CC=1 SCAR=0.0
Pod documented
125 262 ▶sub has_subname() { my $self = shift; return defined $self->subinfo->[1] }
Subroutine has_subname: called CC=1 SCAR=0.0
Pod documented
126 67 ▶sub has_stashname() { my $self = shift; return defined $self->subinfo->[0] }
Subroutine has_stashname: called CC=1 SCAR=0.0
Pod documented
127 27 ▶sub has_prototype() { my $self = shift; return !!$self->prototype } # after build_prototype
Subroutine has_prototype: called CC=1 SCAR=0.0
Pod documented
128 27 ▶sub has_attribute() { my $self = shift; return !!$self->attribute } # after build_attribute
Subroutine has_attribute: called CC=1 SCAR=0.0
Pod documented
129 27 ▶sub has_file() { my $self = shift; return defined $self->{file} }
Subroutine has_file: called CC=1 SCAR=0.0
Pod documented
130 27 ▶sub has_line() { my $self = shift; return defined $self->{line} }
Subroutine has_line: called CC=1 SCAR=0.0
Pod documented
131  
132 28 ▶sub set_sub {
Subroutine set_sub: called CC=2 SCAR=6.9
Pod documented
133 28 my ($self, $v) = @_;
134 28 $self->{sub} = $v;
135 28 Scalar::Util::weaken($self->{sub});
136  
137 # rebuild
138 28 for (qw/subinfo file line prototype attribute is_constant/) {
139 168 delete $self->{$_};
140 168 $self->$_;
141 }
142 28 return $self;
143 }
144  
145 57 ▶sub set_subname { my ($self, $v) = @_; $self->{subinfo}[1] = $v; return $self }
Subroutine set_subname: called CC=1 SCAR=0.0
Pod documented
146 2 ▶sub set_stashname { my ($self, $v) = @_; $self->{subinfo}[0] = $v; return $self }
Subroutine set_stashname: called CC=1 SCAR=0.0
Pod documented
147 14 ▶sub set_fullname {
Subroutine set_fullname: called CC=2 SCAR=6.9
Pod documented
148 14 my ($self, $v) = @_;
149 14 ▶ $self->set_subinfo($v =~ m!^(.+)::([^:]+)$! ? [$1, $2] : []);
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /^(.+)::([^:]+)$/ ? : 9 5 14
150 14 return $self;
151 }
152 25 ▶sub set_subinfo {
Subroutine set_subinfo: called CC=1 SCAR=0.0
Pod documented
153 25 my ($self, $args) = @_;
154 25 $self->{subinfo} = [ $args->[0], $args->[1] ];
155 22 return $self;
156 }
157  
158 1 ▶sub set_file { my ($self, $v) = @_; $self->{file} = $v; return $self }
Subroutine set_file: called CC=1 SCAR=0.0
Pod documented
159 1 ▶sub set_line { my ($self, $v) = @_; $self->{line} = $v; return $self }
Subroutine set_line: called CC=1 SCAR=0.0
Pod documented
160 1 ▶sub set_is_constant { my ($self, $v) = @_; $self->{is_constant} = $v; return $self }
Subroutine set_is_constant: called CC=1 SCAR=0.0
Pod documented
161 3 ▶sub set_prototype { my ($self, $v) = @_; $self->{prototype} = $v; return $self }
Subroutine set_prototype: called CC=1 SCAR=0.0
Pod documented
162 3 ▶sub set_attribute { my ($self, $v) = @_; $self->{attribute} = $v; return $self }
Subroutine set_attribute: called CC=1 SCAR=0.0
Pod documented
163 198 ▶sub set_is_method { my ($self, $v) = @_; $self->{is_method} = $v; return $self }
Subroutine set_is_method: called CC=1 SCAR=0.0
Pod documented
164  
165 203 ▶sub set_parameters {
Subroutine set_parameters: called CC=3 SCAR=11.0
Pod documented
166 203 my ($self, @args) = @_;
167 203 my $v = $args[0];
168 203 ▶ if (Scalar::Util::blessed($v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($v)) { } 28 175 203
169 28 ▶ if ($v->isa('Sub::Meta::Parameters')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->isa('Sub::Meta::Parameters')) { } 27 1 28
170 27 $self->{parameters} = $v
171 }
172 else {
173 1 _croak('object must be Sub::Meta::Parameters');
174 }
175 }
176 else {
177 175 $self->{parameters} = $self->parameters_class->new(@args);
178 }
179 200 return $self
180 }
181  
182 3 ▶sub set_args {
Subroutine set_args: called CC=1 SCAR=0.0
Pod documented
183 3 my ($self, $args) = @_;
184 3 $self->parameters->set_args($args);
185 3 return $self;
186 }
187  
188 3 ▶sub set_slurpy {
Subroutine set_slurpy: called CC=1 SCAR=0.0
Pod documented
189 3 my ($self, @args) = @_;
190 3 $self->parameters->set_slurpy(@args);
191 3 return $self;
192 }
193  
194 3 ▶sub set_nshift {
Subroutine set_nshift: called CC=3 SCAR=11.0
Pod documented
195 3 my ($self, $v) = @_;
196 3 ▶ if ($self->is_method && $v == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_method and $v == 0) 1 2 3
Condition100%3/3
$self->is_method and $v == 0
!ll&&!rl&&r
111
MC/DC100%2/2
$self->is_method and $v == 0
$self->is_method $v == 0
Truth table100%3/3
A and B
A= $self->is_methodB= $v == 0
ABresult
0X0
100
111
197 1 _croak 'nshift of method cannot be zero';
198 }
199 2 $self->parameters->set_nshift($v);
200 2 return $self;
201 }
202  
203 1 ▶sub set_invocant {
Subroutine set_invocant: called CC=1 SCAR=0.0
Pod documented
204 1 my ($self, $v) = @_;
205 1 $self->parameters->set_invocant($v);
206 1 return $self;
207 }
208  
209 199 ▶sub set_returns {
Subroutine set_returns: called CC=3 SCAR=11.0
Pod documented
210 199 my ($self, @args) = @_;
211 199 my $v = $args[0];
212 199 ▶ if (Scalar::Util::blessed($v) && $v->isa('Sub::Meta::Returns')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($v) and $v->isa('Sub::Meta::Returns')) { } 21 178 199
Condition100%3/3
builtin::blessed($v) and $v->isa("Sub::Meta::Returns")
!ll&&!rl&&r
1681021
MC/DC100%2/2
builtin::blessed($v) and $v->isa("Sub::Meta::Returns")
builtin::blessed($v) $v->isa("Sub::Meta::Returns")
Truth table100%3/3
A and B
A= builtin::blessed($v)B= $v->isa("Sub::Meta::Returns")
ABresult
0X0
100
111
213 21 $self->{returns} = $v
214 }
215 else {
216 178 $self->{returns} = $self->returns_class->new(@args);
217 }
218 199 return $self
219 }
220  
221 93 ▶sub _build_subinfo {
Subroutine _build_subinfo: called CC=3 SCAR=11.0
222 93 my $self = shift;
223 93 ▶ return [] unless $self->has_sub;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_sub 65 28 93
224 28 my @info = Sub::Identify::get_code_info($self->sub);
225 28 ▶ return [ $info[0], $info[1] eq '__ANON__' ? undef : $info[1] ];
Branch: 1 branch
BranchTrueFalseTotal
$info[1] eq '__ANON__' ? : 4 24 28
226 }
227  
228 46 ▶sub _build_file { my $self = shift; return $self->sub ? (Sub::Identify::get_code_location($self->sub))[0] : undef }
Subroutine _build_file: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$self->sub ? : 28 18 46
229 46 ▶sub _build_line { my $self = shift; return $self->sub ? (Sub::Identify::get_code_location($self->sub))[1] : undef }
Subroutine _build_line: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$self->sub ? : 28 18 46
230 55 ▶sub _build_is_constant { my $self = shift; return $self->sub ? Sub::Identify::is_sub_constant($self->sub) : undef }
Subroutine _build_is_constant: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$self->sub ? : 37 18 55
231 72 ▶sub _build_prototype { my $self = shift; return $self->sub ? Sub::Util::prototype($self->sub) : undef }
Subroutine _build_prototype: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$self->sub ? : 36 36 72
232 66 ▶sub _build_attribute { my $self = shift; return $self->sub ? [ attributes::get($self->sub) ] : undef }
Subroutine _build_attribute: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$self->sub ? : 30 36 66
233  
234 3 ▶sub apply_subname {
Subroutine apply_subname: called CC=2 SCAR=6.9
Pod documented
235 3 my ($self, $subname) = @_;
236 3 ▶ _croak 'apply_subname requires subroutine reference' unless $self->sub;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->sub 1 2 3
237 2 $self->set_subname($subname);
238 2 Sub::Util::set_subname($self->fullname, $self->sub);
239 2 return $self;
240 }
241  
242 3 ▶sub apply_prototype {
Subroutine apply_prototype: called CC=2 SCAR=6.9
Pod documented
243 3 my ($self, $prototype) = @_;
244 3 ▶ _croak 'apply_prototype requires subroutine reference' unless $self->sub;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->sub 1 2 3
245 2 Sub::Util::set_prototype($prototype, $self->sub);
246 2 $self->set_prototype($prototype);
247 2 return $self;
248 }
249  
250 4 ▶sub apply_attribute {
Subroutine apply_attribute: called CC=2 SCAR=6.9
Pod documented
251 4 my ($self, @attribute) = @_;
252 4 ▶ _croak 'apply_attribute requires subroutine reference' unless $self->sub;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->sub 1 3 4
253 {
254 29 ▶ no warnings qw(misc); ## no critic (ProhibitNoWarnings)
Subroutine BEGIN: called CC=1 SCAR=0.0
255 3 attributes->import($self->stashname, $self->sub, @attribute);
256 }
257 2 $self->set_attribute($self->_build_attribute);
258 2 return $self;
259 }
260  
261 1 ▶sub apply_meta {
Subroutine apply_meta: called CC=1 SCAR=0.0
Pod documented
262 1 my ($self, $other) = @_;
263  
264 1 $self->apply_subname($other->subname);
265 1 $self->apply_prototype($other->prototype);
266 1 $self->apply_attribute(@{$other->attribute});
267  
268 1 return $self;
269 }
270  
271 39 ▶sub is_same_interface {
Subroutine is_same_interface: called CC=9 SCAR=22.0
Pod documented
272 39 my ($self, $other) = @_;
273  
274 39 ▶ return unless Scalar::Util::blessed($other) && $other->isa('Sub::Meta');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) and $other->isa("Sub::Meta") 2 37 39
Condition100%3/3
builtin::blessed($other) and $other->isa("Sub::Meta")
!ll&&!rl&&r
1137
MC/DC100%2/2
builtin::blessed($other) and $other->isa("Sub::Meta")
builtin::blessed($other) $other->isa("Sub::Meta")
Truth table100%3/3
A and B
A= builtin::blessed($other)B= $other->isa("Sub::Meta")
ABresult
0X0
100
111
275  
276 37 ▶ if ($self->has_subname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_subname) { } 23 14 37
277 23 ▶ return unless $self->subname eq $other->subname
Branch: 1 branch
BranchTrueFalseTotal
unless $self->subname eq $other->subname 3 20 23
278 }
279 else {
280 14 ▶ return if $other->has_subname;
Branch: 1 branch
BranchTrueFalseTotal
if $other->has_subname 4 10 14
281 }
282  
283 30 ▶ return unless $self->is_method eq $other->is_method;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_method eq $other->is_method 5 25 30
284  
285 25 ▶ return unless $self->parameters->is_same_interface($other->parameters);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->parameters->is_same_interface($other->parameters) 6 19 25
286  
287 19 ▶ return unless $self->returns->is_same_interface($other->returns);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->returns->is_same_interface($other->returns) 5 14 19
288  
289 14 return !!1;
290 }
291  
292 sub is_strict_same_interface;
293 29 *is_strict_same_interface = \&is_same_interface;
294  
295 39 ▶sub is_relaxed_same_interface {
Subroutine is_relaxed_same_interface: called CC=8 SCAR=20.8
Pod documented
296 39 my ($self, $other) = @_;
297  
298 39 ▶ return unless Scalar::Util::blessed($other) && $other->isa('Sub::Meta');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) and $other->isa("Sub::Meta") 2 37 39
Condition100%3/3
builtin::blessed($other) and $other->isa("Sub::Meta")
!ll&&!rl&&r
1137
MC/DC100%2/2
builtin::blessed($other) and $other->isa("Sub::Meta")
builtin::blessed($other) $other->isa("Sub::Meta")
Truth table100%3/3
A and B
A= builtin::blessed($other)B= $other->isa("Sub::Meta")
ABresult
0X0
100
111
299  
300 37 ▶ if ($self->has_subname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_subname) 23 14 37
301 23 ▶ return unless $self->subname eq $other->subname
Branch: 1 branch
BranchTrueFalseTotal
unless $self->subname eq $other->subname 3 20 23
302 }
303  
304 34 ▶ return unless $self->is_method eq $other->is_method;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_method eq $other->is_method 5 29 34
305  
306 29 ▶ return unless $self->parameters->is_relaxed_same_interface($other->parameters);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->parameters->is_relaxed_same_interface($other->parameters) 5 24 29
307  
308 24 ▶ return unless $self->returns->is_relaxed_same_interface($other->returns);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->returns->is_relaxed_same_interface($other->returns) 3 21 24
309  
310 21 return !!1;
311 }
312  
313 11 ▶sub is_same_interface_inlined {
Subroutine is_same_interface_inlined: called CC=2 SCAR=6.9
Pod documented
314 11 my ($self, $v) = @_;
315  
316 11 my @src;
317  
318 11 push @src => sprintf("Scalar::Util::blessed(%s) && %s->isa('Sub::Meta')", $v, $v);
319  
320 11 ▶ push @src => $self->has_subname ? sprintf("'%s' eq %s->subname", $self->subname, $v)
Branch: 1 branch
BranchTrueFalseTotal
$self->has_subname ? : 5 6 11
321 : sprintf('!%s->has_subname', $v);
322  
323 11 push @src => sprintf("'%s' eq %s->is_method", $self->is_method, $v);
324  
325 11 push @src => $self->parameters->is_same_interface_inlined(sprintf('%s->parameters', $v));
326  
327 11 push @src => $self->returns->is_same_interface_inlined(sprintf('%s->returns', $v));
328  
329 11 return join "\n && ", @src;
330 }
331  
332 sub is_strict_same_interface_inlined;
333 29 *is_strict_same_interface_inlined = \&is_same_interface_inlined;
334  
335 15 ▶sub is_relaxed_same_interface_inlined {
Subroutine is_relaxed_same_interface_inlined: called CC=2 SCAR=6.9
Pod documented
336 15 my ($self, $v) = @_;
337  
338 15 my @src;
339  
340 15 push @src => sprintf("Scalar::Util::blessed(%s) && %s->isa('Sub::Meta')", $v, $v);
341  
342 15 ▶ push @src => sprintf("'%s' eq %s->subname", $self->subname, $v) if $self->has_subname;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_subname 5 10 15
343  
344 15 push @src => sprintf("'%s' eq %s->is_method", $self->is_method, $v);
345  
346 15 push @src => $self->parameters->is_relaxed_same_interface_inlined(sprintf('%s->parameters', $v));
347  
348 15 push @src => $self->returns->is_relaxed_same_interface_inlined(sprintf('%s->returns', $v));
349  
350 15 return join "\n && ", @src;
351 }
352  
353 22 ▶sub error_message {
Subroutine error_message: called CC=10 SCAR=23.0
Pod documented
354 22 my ($self, $other) = @_;
355  
356 22 ▶ return sprintf('other must be Sub::Meta. got: %s', $other // 'Undef')
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) and $other->isa("Sub::Meta") 3 19 22
Condition100%5/5
builtin::blessed($other) and $other->isa("Sub::Meta")
!ll&&!rl&&r
2119
$other // "Undef"
l!l
12
MC/DC100%2/2
builtin::blessed($other) and $other->isa("Sub::Meta")
builtin::blessed($other) $other->isa("Sub::Meta")
MC/DC100%1/1
$other // "Undef"
$other
Truth table100%3/3
A and B
A= builtin::blessed($other)B= $other->isa("Sub::Meta")
ABresult
0X0
100
111
Truth table100%2/2
A
A= $other
Aresult
11
00
357 unless Scalar::Util::blessed($other) && $other->isa('Sub::Meta');
358  
359 19 ▶ if ($self->has_subname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_subname) { } 7 12 19
360 7 ▶ return sprintf('invalid subname. got: %s, expected: %s', $other->subname, $self->subname)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->subname eq $other->subname 2 5 7
361 unless $self->subname eq $other->subname
362 }
363 else {
364 12 ▶ return sprintf('should not have subname. got: %s', $other->subname) if $other->has_subname;
Branch: 1 branch
BranchTrueFalseTotal
if $other->has_subname 1 11 12
365 }
366  
367 16 ▶ return 'invalid method'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_method eq $other->is_method 2 14 16
368 unless $self->is_method eq $other->is_method;
369  
370 14 ▶ return "invalid parameters: " . $self->parameters->error_message($other->parameters)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->parameters->is_same_interface($other->parameters) 4 10 14
371 unless $self->parameters->is_same_interface($other->parameters);
372  
373 10 ▶ return "invalid returns: " . $self->returns->error_message($other->returns)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->returns->is_same_interface($other->returns) 3 7 10
374 unless $self->returns->is_same_interface($other->returns);
375  
376 7 return '';
377 }
378  
379 23 ▶sub relaxed_error_message {
Subroutine relaxed_error_message: called CC=9 SCAR=22.0
Pod documented
380 23 my ($self, $other) = @_;
381  
382 23 ▶ return sprintf('other must be Sub::Meta. got: %s', $other // 'Undef')
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) and $other->isa("Sub::Meta") 3 20 23
Condition100%5/5
builtin::blessed($other) and $other->isa("Sub::Meta")
!ll&&!rl&&r
2120
$other // "Undef"
l!l
12
MC/DC100%2/2
builtin::blessed($other) and $other->isa("Sub::Meta")
builtin::blessed($other) $other->isa("Sub::Meta")
MC/DC100%1/1
$other // "Undef"
$other
Truth table100%3/3
A and B
A= builtin::blessed($other)B= $other->isa("Sub::Meta")
ABresult
0X0
100
111
Truth table100%2/2
A
A= $other
Aresult
11
00
383 unless Scalar::Util::blessed($other) && $other->isa('Sub::Meta');
384  
385 20 ▶ if ($self->has_subname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_subname) 7 13 20
386 7 ▶ return sprintf('invalid subname. got: %s, expected: %s', $other->subname, $self->subname)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->subname eq $other->subname 2 5 7
387 unless $self->subname eq $other->subname
388 }
389  
390 18 ▶ return 'invalid method'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_method eq $other->is_method 2 16 18
391 unless $self->is_method eq $other->is_method;
392  
393 16 ▶ return "invalid parameters: " . $self->parameters->relaxed_error_message($other->parameters)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->parameters->is_relaxed_same_interface($other->parameters) 4 12 16
394 unless $self->parameters->is_relaxed_same_interface($other->parameters);
395  
396 12 ▶ return "invalid returns: " . $self->returns->relaxed_error_message($other->returns)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->returns->is_relaxed_same_interface($other->returns) 2 10 12
397 unless $self->returns->is_relaxed_same_interface($other->returns);
398  
399 10 return '';
400 }
401  
402 36 ▶sub display {
Subroutine display: called CC=3 SCAR=11.0
Pod documented
403 36 my $self = shift;
404  
405 36 ▶ my $keyword = $self->is_method ? 'method' : 'sub';
Branch: 1 branch
BranchTrueFalseTotal
$self->is_method ? : 4 32 36
406 36 my $subname = $self->subname;
407  
408 36 my $s = $keyword;
409 36 ▶ $s .= ' ' . $subname if $subname;
Branch: 1 branch
BranchTrueFalseTotal
if $subname 13 23 36
410 36 $s .= '('. $self->parameters->display .')';
411 36 $s .= ' => ' . $self->returns->display;
412 36 return $s;
413 }
414  
415 29 1;
416 __END__
« Sub/Meta/Param.pm ↑ Summary Sub/Meta/Type.pm »