blib/lib/Mouse/PurePerl.pm

filter: Statementstmt 26.3% 108 / 410 Branchbran 14.9% 26 / 174 Conditioncond 6.8% 7 / 102 MC/DCmcdc 0.0% 0 / 59 Subroutinesub 17.6% 23 / 130 Podpod 18.0% 17 / 94 totaltotal 18.6% 181 / 969 CC 140 SCAR 57.4
CC
140
Cov
21%
_process_options
1892.0
is_class_loaded
41.7
__ANON__
30.0
CRAP 311.2
« blib/lib/Mouse/Meta/Method/Constructor.pm ↑ Summary blib/lib/Mouse/Tiny.pm »
1 package Mouse::PurePerl;
2 # The pure Perl backend for Mouse
3 package Mouse::Util;
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings FATAL => 'redefine'; # to avoid to load Mouse::PurePerl twice
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use B ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 require Mouse::Util;
12  
13 # taken from Class/MOP.pm
14 1 ▶sub is_valid_class_name {
Subroutine is_valid_class_name: called CC=4 SCAR=15.6
Pod undocumented
15 1 my $class = shift;
16  
17 1 ▶ return 0 if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 1 1
18 1 ▶ return 0 unless defined($class);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $class 0 1 1
19  
20 1 ▶ return 1 if $class =~ /\A \w+ (?: :: \w+ )* \z/xms;
Branch: 1 branch
BranchTrueFalseTotal
if $class =~ /\A \w+ (?: :: \w+ )* \z/msx 1 0 1
21  
22 0 return 0;
23 }
24  
25 1 ▶sub is_class_loaded {
Subroutine is_class_loaded: called CC=17 SCAR=37.3
Pod documented
26 1 my $class = shift;
27  
28 1 ▶ return 0 if ref($class) || !defined($class) || !length($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class or not defined $class or not length $class 0 1 1
Condition33%2/6
ref $class or not defined $class or not length $class
l!l&&r!l&&!r
001
ref $class or not defined $class
l!l&&r!l&&!r
001
MC/DC0%0/3
ref $class or not defined $class or not length $class
ref $class not defined $class not length $class
Truth table25%1/4
A or not(B) or not(C)
A= ref $classB= not defined $classC= not length $class
ABCresult
1XX1
01X1
0011
0000
29  
30 # walk the symbol table tree to avoid autovififying
31 # \*{${main::}{"Foo::"}{"Bar::"}} == \*main::Foo::Bar::
32  
33 1 my $pack = \%::;
34 1 foreach my $part (split('::', $class)) {
35 2 $part .= '::';
36 2 ▶ return 0 if !exists $pack->{$part};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $pack->{$part} 0 2 2
37  
38 2 my $entry = \$pack->{$part};
39 2 ▶ return 0 if ref($entry) ne 'GLOB';
Branch: 1 branch
BranchTrueFalseTotal
if ref $entry ne "GLOB" 0 2 2
40 2 $pack = *{$entry}{HASH};
41 }
42  
43 1 ▶ return 0 if !%{$pack};
Branch: 1 branch
BranchTrueFalseTotal
unless %{$pack;} 0 1 1
44  
45 # check for $VERSION or @ISA
46 return 1 if exists $pack->{VERSION}
47 0 ▶ && defined *{$pack->{VERSION}}{SCALAR} && defined ${ $pack->{VERSION} };
Branch: 1 branch
BranchTrueFalseTotal
if exists $pack->{"VERSION"} and defined *{$pack->{"VERSION"};}{"SCALAR"} and defined ${$$pack{"VERSION"};} 0 1 1
Condition33%2/6
exists $pack->{"VERSION"} and defined *{$pack->{"VERSION"};}{"SCALAR"} and defined ${$$pack{"VERSION"};}
!ll&&!rl&&r
100
exists $pack->{"VERSION"} and defined *{$pack->{"VERSION"};}{"SCALAR"}
!ll&&!rl&&r
100
MC/DC0%0/3
exists $pack->{"VERSION"} and defined *{$pack->{"VERSION"};}{"SCALAR"} and defined ${$$pack{"VERSION"};}
exists $pack->{"VERSION"} defined *{$pack->{"VERSION"};}{"SCALAR"} defined ${$$pack{"VERSION"};}
Truth table25%1/4
A and B and C
A= exists $pack->{"VERSION"}B= defined *{$pack->{"VERSION"};}{"SCALAR"}C= defined ${$$pack{"VERSION"};}
ABCresult
0XX0
10X0
1100
1111
48 return 1 if exists $pack->{ISA}
49 0 ▶ && defined *{$pack->{ISA}}{ARRAY} && @{ $pack->{ISA} } != 0;
Branch: 1 branch
BranchTrueFalseTotal
if exists $pack->{"ISA"} and defined *{$pack->{"ISA"};}{"ARRAY"} and @{$pack->{"ISA"};} != 0 0 1 1
Condition33%2/6
exists $pack->{"ISA"} and defined *{$pack->{"ISA"};}{"ARRAY"} and @{$pack->{"ISA"};} != 0
!ll&&!rl&&r
100
exists $pack->{"ISA"} and defined *{$pack->{"ISA"};}{"ARRAY"}
!ll&&!rl&&r
100
MC/DC0%0/3
exists $pack->{"ISA"} and defined *{$pack->{"ISA"};}{"ARRAY"} and @{$pack->{"ISA"};} != 0
exists $pack->{"ISA"} defined *{$pack->{"ISA"};}{"ARRAY"} @{$pack->{"ISA"};} != 0
Truth table25%1/4
A and B and C
A= exists $pack->{"ISA"}B= defined *{$pack->{"ISA"};}{"ARRAY"}C= @{$pack->{"ISA"};} != 0
ABCresult
0XX0
10X0
1100
1111
50  
51 # check for any method
52 1 foreach my $name( keys %{$pack} ) {
53 1 my $entry = \$pack->{$name};
54 1 ▶ return 1 if ref($entry) ne 'GLOB' || defined *{$entry}{CODE};
Branch: 1 branch
BranchTrueFalseTotal
if ref $entry ne "GLOB" or defined *{$entry;}{"CODE"} 1 0 1
Condition33%1/3
ref $entry ne "GLOB" or defined *{$entry;}{"CODE"}
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $entry ne "GLOB" or defined *{$entry;}{"CODE"}
ref $entry ne "GLOB" defined *{$entry;}{"CODE"}
Truth table33%1/3
A or B
A= ref $entry ne "GLOB"B= defined *{$entry;}{"CODE"}
ABresult
1X1
011
000
55 }
56  
57 # fail
58 0 return 0;
59 }
60  
61  
62 # taken from Sub::Identify
63 2 ▶sub get_code_info {
Subroutine get_code_info: called CC=4 SCAR=14.3
Pod documented
64 2 my ($coderef) = @_;
65 2 ▶ ref($coderef) or return;
Branch: 1 branch
BranchTrueFalseTotal
ref $coderef or return 2 0 2
66  
67 2 my $cv = B::svref_2object($coderef);
68 2 ▶ $cv->isa('B::CV') or return;
Branch: 1 branch
BranchTrueFalseTotal
$cv->isa("B::CV") or return 2 0 2
69  
70 2 my $gv = $cv->GV;
71 2 ▶ $gv->isa('B::GV') or return;
Branch: 1 branch
BranchTrueFalseTotal
$gv->isa("B::GV") or return 2 0 2
72  
73 2 return ($gv->STASH->NAME, $gv->NAME);
74 }
75  
76 0 ▶sub get_code_package{
Subroutine get_code_package: not called CC=3 SCAR=24.8
Pod documented
77 0 my($coderef) = @_;
78  
79 0 my $cv = B::svref_2object($coderef);
80 0 ▶ $cv->isa('B::CV') or return '';
Branch: 1 branch
BranchTrueFalseTotal
$cv->isa("B::CV") or return "" 0 0 0
81  
82 0 my $gv = $cv->GV;
83 0 ▶ $gv->isa('B::GV') or return '';
Branch: 1 branch
BranchTrueFalseTotal
$gv->isa("B::GV") or return "" 0 0 0
84  
85 0 return $gv->STASH->NAME;
86 }
87  
88 0 ▶sub get_code_ref{
Subroutine get_code_ref: not called CC=1 SCAR=0.2
Pod documented
89 0 my($package, $name) = @_;
90 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
91 1 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
92 1 ▶ use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
93 0 return *{$package . '::' . $name}{CODE};
94 }
95  
96 1 ▶sub generate_isa_predicate_for {
Subroutine generate_isa_predicate_for: called CC=2 SCAR=9.7
Pod undocumented
97 1 my($for_class, $name) = @_;
98  
99 0 ▶ my $predicate = sub{ Scalar::Util::blessed($_[0]) && $_[0]->isa($for_class) };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) and $_[0]->isa($for_class) 0 0 0
100  
101 1 ▶ if(defined $name){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) 0 1 1
102 0 Mouse::Util::install_subroutines(scalar caller, $name => $predicate);
103 0 return;
104 }
105  
106 1 return $predicate;
107 }
108  
109 3 ▶sub generate_can_predicate_for {
Subroutine generate_can_predicate_for: called CC=2 SCAR=8.4
Pod undocumented
110 3 my($methods_ref, $name) = @_;
111  
112 3 my @methods = @{$methods_ref};
113  
114 2 ▶ my $predicate = sub{
Subroutine __ANON__: called CC=4 SCAR=20.9
115 2 my($instance) = @_;
116 2 ▶ if(Scalar::Util::blessed($instance)){
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($instance)) 0 2 2
117 0 foreach my $method(@methods){
118 0 ▶ if(!$instance->can($method)){
Branch: 1 branch
BranchTrueFalseTotal
unless ($instance->can($method)) 0 0 0
119 0 return 0;
120 }
121 }
122 0 return 1;
123 }
124 2 return 0;
125 3 };
126  
127 3 ▶ if(defined $name){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) 3 0 3
128 3 Mouse::Util::install_subroutines(scalar caller, $name => $predicate);
129 3 return;
130 }
131  
132 0 return $predicate;
133 }
134  
135 package Mouse::Util::TypeConstraints;
136  
137  
138 0 ▶sub Any { 1 }
Subroutine Any: not called CC=1 SCAR=6.9
Pod undocumented
139 0 ▶sub Item { 1 }
Subroutine Item: not called CC=1 SCAR=6.9
Pod undocumented
140  
141 0 ▶sub Bool { !$_[0] || $_[0] eq '1' }
Subroutine Bool: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
not $_[0] or $_[0] eq 1 0 0 0
142 0 ▶sub Undef { !defined($_[0]) }
Subroutine Undef: not called CC=1 SCAR=6.9
Pod undocumented
143 0 ▶sub Defined { defined($_[0]) }
Subroutine Defined: not called CC=1 SCAR=6.9
Pod undocumented
144 0 ▶sub Value { defined($_[0]) && !ref($_[0]) }
Subroutine Value: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and not ref $_[0] 0 0 0
145 0 ▶sub Num { Scalar::Util::looks_like_number($_[0]) }
Subroutine Num: not called CC=1 SCAR=6.9
Pod undocumented
146 0 ▶sub Str {
Subroutine Str: not called CC=2 SCAR=17.9
Pod undocumented
147 # We need to use a copy here to flatten MAGICs, for instance as in
148 # Str( substr($_, 0, 42) ).
149 0 my($value) = @_;
150 0 ▶ return defined($value) && ref(\$value) eq 'SCALAR';
Condition0%0/3
defined $value && ref \$value eq 'SCALAR'
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value && ref \$value eq 'SCALAR'
defined $value ref \$value eq 'SCALAR'
Truth table0%0/3
A && B
A= defined $valueB= ref \$value eq 'SCALAR'
ABresult
0X0
100
111
151 }
152 0 ▶sub Int {
Subroutine Int: not called CC=2 SCAR=17.9
Pod undocumented
153 # We need to use a copy here to save the original internal SV flags.
154 0 my($value) = @_;
155 0 ▶ return defined($value) && $value =~ /\A -? [0-9]+ \z/xms;
Condition0%0/3
defined $value && $value =~ /\A -? [0-9]+ \z/msx
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value && $value =~ /\A -? [0-9]+ \z/msx
defined $value $value =~ /\A -? [0-9]+ \z/msx
Truth table0%0/3
A && B
A= defined $valueB= $value =~ /\A -? [0-9]+ \z/msx
ABresult
0X0
100
111
156 }
157  
158 0 ▶sub Ref { ref($_[0]) }
Subroutine Ref: not called CC=1 SCAR=6.9
Pod undocumented
159 0 ▶sub ScalarRef {
Subroutine ScalarRef: not called CC=2 SCAR=17.9
Pod undocumented
160 0 my($value) = @_;
161 0 ▶ return ref($value) eq 'SCALAR' || ref($value) eq 'REF';
Condition0%0/3
ref $value eq 'SCALAR' || ref $value eq 'REF'
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $value eq 'SCALAR' || ref $value eq 'REF'
ref $value eq 'SCALAR' ref $value eq 'REF'
Truth table0%0/3
A || B
A= ref $value eq 'SCALAR'B= ref $value eq 'REF'
ABresult
1X1
011
000
162 }
163 0 ▶sub ArrayRef { ref($_[0]) eq 'ARRAY' }
Subroutine ArrayRef: not called CC=1 SCAR=6.9
Pod undocumented
164 0 ▶sub HashRef { ref($_[0]) eq 'HASH' }
Subroutine HashRef: not called CC=1 SCAR=6.9
Pod undocumented
165 0 ▶sub CodeRef { ref($_[0]) eq 'CODE' }
Subroutine CodeRef: not called CC=1 SCAR=6.9
Pod undocumented
166 0 ▶sub RegexpRef { ref($_[0]) eq 'Regexp' }
Subroutine RegexpRef: not called CC=1 SCAR=6.9
Pod undocumented
167 0 ▶sub GlobRef { ref($_[0]) eq 'GLOB' }
Subroutine GlobRef: not called CC=1 SCAR=6.9
Pod undocumented
168  
169 0 ▶sub FileHandle {
Subroutine FileHandle: not called CC=3 SCAR=24.8
Pod undocumented
170 0 my($value) = @_;
171 0 ▶ return Scalar::Util::openhandle($value)
Condition0%0/6
&Scalar::Util::openhandle($value) || builtin::blessed($value) && $value->isa('IO::Handle')
l!l&&r!l&&!r
000
builtin::blessed($value) and $value->isa("IO::Handle")
!ll&&!rl&&r
000
MC/DC0%0/3
&Scalar::Util::openhandle($value) || builtin::blessed($value) && $value->isa('IO::Handle')
&Scalar::Util::openhandle($value) builtin::blessed($value) $value->isa("IO::Handle")
Truth table0%0/4
A || B and C
A= &Scalar::Util::openhandle($value)B= builtin::blessed($value)C= $value->isa("IO::Handle")
ABCresult
1XX1
0111
00X0
0100
172 || (Scalar::Util::blessed($value) && $value->isa("IO::Handle"))
173 }
174  
175 0 ▶sub Object { Scalar::Util::blessed($_[0]) && ref($_[0]) ne 'Regexp' }
Subroutine Object: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) and ref $_[0] ne "Regexp" 0 0 0
176  
177 0 ▶sub ClassName { Mouse::Util::is_class_loaded($_[0]) }
Subroutine ClassName: not called CC=1 SCAR=6.9
Pod undocumented
178 0 ▶sub RoleName { (Mouse::Util::class_of($_[0]) || return 0)->isa('Mouse::Meta::Role') }
Subroutine RoleName: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/2
Mouse::Util::class_of($_[0]) || (return 0)
l!l
00
MC/DC0%0/1
Mouse::Util::class_of($_[0]) || (return 0)
Mouse::Util::class_of($_[0])
Truth table0%0/2
A
A= Mouse::Util::class_of($_[0])
Aresult
11
00
179  
180 0 ▶sub _parameterize_ArrayRef_for {
Subroutine _parameterize_ArrayRef_for: not called CC=1 SCAR=6.9
181 0 my($type_parameter) = @_;
182 0 my $check = $type_parameter->_compiled_type_constraint;
183  
184 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
185 0 foreach my $value (@{$_}) {
186 0 ▶ return undef unless $check->($value);
Branch: 1 branch
BranchTrueFalseTotal
unless &$check($value) 0 0 0
187 }
188 0 return 1;
189 }
190 0 }
191  
192 0 ▶sub _parameterize_HashRef_for {
Subroutine _parameterize_HashRef_for: not called CC=1 SCAR=6.9
193 0 my($type_parameter) = @_;
194 0 my $check = $type_parameter->_compiled_type_constraint;
195  
196 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
197 0 foreach my $value(values %{$_}){
198 0 ▶ return undef unless $check->($value);
Branch: 1 branch
BranchTrueFalseTotal
unless &$check($value) 0 0 0
199 }
200 0 return 1;
201 0 };
202 }
203  
204 # 'Maybe' type accepts 'Any', so it requires parameters
205 0 ▶sub _parameterize_Maybe_for {
Subroutine _parameterize_Maybe_for: not called CC=1 SCAR=6.9
206 0 my($type_parameter) = @_;
207 0 my $check = $type_parameter->_compiled_type_constraint;
208  
209 0 ▶ return sub{
Subroutine __ANON__: not called CC=2 SCAR=17.9
210 0 ▶ return !defined($_) || $check->($_);
Condition0%0/3
!defined($_) || &$check($_)
l!l&&r!l&&!r
000
MC/DC0%0/2
!defined($_) || &$check($_)
!defined($_) &$check($_)
Truth table0%0/3
not(A) || B
A= !defined($_)B= &$check($_)
ABresult
1X1
011
000
211 0 };
212 }
213  
214 package Mouse::Meta::Module;
215  
216 2 ▶sub name { $_[0]->{package} }
Subroutine name: called CC=1 SCAR=0.0
Pod undocumented
217  
218 0 ▶sub _method_map { $_[0]->{methods} }
Subroutine _method_map: not called CC=1 SCAR=6.9
219 0 ▶sub _attribute_map{ $_[0]->{attributes} }
Subroutine _attribute_map: not called CC=1 SCAR=6.9
220  
221 0 ▶sub namespace{
Subroutine namespace: not called CC=1 SCAR=1.2
Pod undocumented
222 0 my $name = $_[0]->{package};
223 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
224 0 return \%{ $name . '::' };
225 }
226  
227 1 ▶sub add_method {
Subroutine add_method: called CC=4 SCAR=16.3
Pod undocumented
228 1 my($self, $name, $code) = @_;
229  
230 1 ▶ if(!defined $name){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 0 1 1
231 0 $self->throw_error('You must pass a defined name');
232 }
233 1 ▶ if(!defined $code){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code) 0 1 1
234 0 $self->throw_error('You must pass a defined code');
235 }
236  
237 1 ▶ if(ref($code) ne 'CODE'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $code ne "CODE") 0 1 1
238 0 $code = \&{$code}; # coerce
239 }
240  
241 1 $self->{methods}->{$name} = $code; # Moose stores meta object here.
242  
243 1 Mouse::Util::install_subroutines($self->name,
244 $name => $code,
245 );
246 1 return;
247 }
248  
249 1 ▶my $generate_class_accessor = sub {
Subroutine __ANON__: called CC=1 SCAR=5.1
250 1 my($name) = @_;
251 0 ▶ return sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
252 0 my $self = shift;
253 0 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
254 0 return $self->{$name} = shift;
255 }
256  
257 0 foreach my $class($self->linearized_isa) {
258 0 ▶ my $meta = Mouse::Util::get_metaclass_by_name($class)
Branch: 1 branch
BranchTrueFalseTotal
my $meta = Mouse::Util::get_metaclass_by_name($class) or next 0 0 0
259 or next;
260  
261 0 ▶ if(exists $meta->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $meta->{$name}) 0 0 0
262 0 return $meta->{$name};
263 }
264 }
265 0 return undef;
266 1 };
267 1 };
268  
269  
270 package Mouse::Meta::Class;
271  
272 1 ▶use Mouse::Meta::Method::Constructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
273 1 ▶use Mouse::Meta::Method::Destructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
274  
275 0 ▶sub method_metaclass { $_[0]->{method_metaclass} || 'Mouse::Meta::Method' }
Subroutine method_metaclass: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"method_metaclass"} or "Mouse::Meta::Method" 0 0 0
276 0 ▶sub attribute_metaclass { $_[0]->{attribute_metaclass} || 'Mouse::Meta::Attribute' }
Subroutine attribute_metaclass: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"attribute_metaclass"} or "Mouse::Meta::Attribute" 0 0 0
277  
278 0 ▶sub constructor_class { $_[0]->{constructor_class} || 'Mouse::Meta::Method::Constructor' }
Subroutine constructor_class: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"constructor_class"} or "Mouse::Meta::Method::Constructor" 0 0 0
279 0 ▶sub destructor_class { $_[0]->{destructor_class} || 'Mouse::Meta::Method::Destructor' }
Subroutine destructor_class: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"destructor_class"} or "Mouse::Meta::Method::Destructor" 0 0 0
280  
281 0 ▶sub is_anon_class{
Subroutine is_anon_class: not called CC=1 SCAR=6.9
Pod undocumented
282 0 return exists $_[0]->{anon_serial_id};
283 }
284  
285 0 ▶sub roles { $_[0]->{roles} }
Subroutine roles: not called CC=1 SCAR=6.9
Pod undocumented
286  
287 0 ▶sub linearized_isa { @{ Mouse::Util::get_linear_isa($_[0]->{package}) } }
Subroutine linearized_isa: not called CC=1 SCAR=6.9
Pod documented
288  
289 0 ▶sub new_object {
Subroutine new_object: not called CC=5 SCAR=34.0
Pod documented
290 0 my $meta = shift;
291 0 ▶ my %args = (@_ == 1 ? %{$_[0]} : @_);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
292  
293 0 my $object = bless {}, $meta->name;
294  
295 0 $meta->_initialize_object($object, \%args, 0);
296 # BUILDALL
297 0 ▶ if( $object->can('BUILD') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->can("BUILD")) 0 0 0
298 0 for my $class (reverse $meta->linearized_isa) {
299 0 ▶ my $build = Mouse::Util::get_code_ref($class, 'BUILD')
Condition0%0/2
Mouse::Util::get_code_ref($class, 'BUILD') || (next)
l!l
00
MC/DC0%0/1
Mouse::Util::get_code_ref($class, 'BUILD') || (next)
Mouse::Util::get_code_ref($class, 'BUILD')
Truth table0%0/2
A
A= Mouse::Util::get_code_ref($class, 'BUILD')
Aresult
11
00
300 || next;
301  
302 0 $object->$build(\%args);
303 }
304 }
305 0 return $object;
306 }
307  
308 0 ▶sub clone_object {
Subroutine clone_object: not called CC=3 SCAR=24.8
Pod documented
309 0 my $class = shift;
310 0 my $object = shift;
311 0 my $args = $object->Mouse::Object::BUILDARGS(@_);
312  
313 0 ▶ (Scalar::Util::blessed($object) && $object->isa($class->name))
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($object) and $object->isa($class->name) or $class->throw_error('You must pass an instance of the metaclass (' . $class->name . "), not ($object)") 0 0 0
Condition0%0/3
builtin::blessed($object) and $object->isa($class->name)
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($object) and $object->isa($class->name)
builtin::blessed($object) $object->isa($class->name)
Truth table0%0/3
A and B
A= builtin::blessed($object)B= $object->isa($class->name)
ABresult
0X0
100
111
314 || $class->throw_error("You must pass an instance of the metaclass (" . $class->name . "), not ($object)");
315  
316 0 my $cloned = bless { %$object }, ref $object;
317 0 $class->_initialize_object($cloned, $args, 1);
318 0 return $cloned;
319 }
320  
321 0 ▶sub _initialize_object{
Subroutine _initialize_object: not called CC=2 SCAR=17.9
322 0 my($self, $object, $args, $is_cloning) = @_;
323 # The initializer, which is used everywhere, must be clear
324 # when an attribute is added. See Mouse::Meta::Class::add_attribute.
325 my $initializer = $self->{_mouse_cache}{_initialize_object} ||=
326 0 ▶ Mouse::Util::load_class($self->constructor_class)
Condition0%0/3
$self->{"_mouse_cache"}{"_initialize_object"} ||= Mouse::Util::load_class($self->constructor_class)->_generate_initialize_object($self)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_mouse_cache"}{"_initialize_object"} ||= Mouse::Util::load_class($self->constructor_class)->_generate_initialize_object($self)
$self->{"_mouse_cache"}{"_initialize_object"} Mouse::Util::load_class($self->constructor_class)->_generate_initialize_object($self)
Truth table0%0/3
A ||= B
A= $self->{"_mouse_cache"}{"_initialize_object"}B= Mouse::Util::load_class($self->constructor_class)->_generate_initialize_object($self)
ABresult
1X1
011
000
327 ->_generate_initialize_object($self);
328 0 goto &{$initializer};
329 }
330  
331 0 ▶sub get_all_attributes {
Subroutine get_all_attributes: not called CC=2 SCAR=17.9
Pod documented
332 0 my($self) = @_;
333 0 return @{ $self->{_mouse_cache}{all_attributes}
334 0 ▶ ||= $self->_calculate_all_attributes };
Condition0%0/3
$self->{"_mouse_cache"}{"all_attributes"} ||= $self->_calculate_all_attributes
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_mouse_cache"}{"all_attributes"} ||= $self->_calculate_all_attributes
$self->{"_mouse_cache"}{"all_attributes"} $self->_calculate_all_attributes
Truth table0%0/3
A ||= B
A= $self->{"_mouse_cache"}{"all_attributes"}B= $self->_calculate_all_attributes
ABresult
1X1
011
000
335 }
336  
337 0 ▶sub is_immutable { $_[0]->{is_immutable} }
Subroutine is_immutable: not called CC=1 SCAR=6.9
Pod undocumented
338  
339 sub strict_constructor;
340 1 *strict_constructor = $generate_class_accessor->('strict_constructor');
341  
342 0 ▶sub _invalidate_metaclass_cache {
Subroutine _invalidate_metaclass_cache: not called CC=1 SCAR=6.9
343 0 my($self) = @_;
344 0 delete $self->{_mouse_cache};
345 0 return;
346 }
347  
348 0 ▶sub _report_unknown_args {
Subroutine _report_unknown_args: not called CC=5 SCAR=34.0
349 0 my($metaclass, $attrs, $args) = @_;
350  
351 0 my @unknowns;
352 my %init_args;
353 0 foreach my $attr(@{$attrs}){
354 0 my $init_arg = $attr->init_arg;
355 0 ▶ if(defined $init_arg){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $init_arg) 0 0 0
356 0 $init_args{$init_arg}++;
357 }
358 }
359  
360 0 ▶ while(my $key = each %{$args}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $key = each %{$args;})) 0 0 0
361 0 ▶ if(!exists $init_args{$key}){
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $init_args{$key}) 0 0 0
362 0 push @unknowns, $key;
363 }
364 }
365  
366 0 $metaclass->throw_error( sprintf
367 "Unknown attribute passed to the constructor of %s: %s",
368 $metaclass->name, Mouse::Util::english_list(@unknowns),
369 );
370 }
371  
372 package Mouse::Meta::Role;
373  
374 0 ▶sub method_metaclass{ $_[0]->{method_metaclass} || 'Mouse::Meta::Role::Method' }
Subroutine method_metaclass: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"method_metaclass"} or "Mouse::Meta::Role::Method" 0 0 0
375  
376 0 ▶sub is_anon_role{
Subroutine is_anon_role: not called CC=1 SCAR=6.9
Pod undocumented
377 0 return exists $_[0]->{anon_serial_id};
378 }
379  
380 0 ▶sub get_roles { $_[0]->{roles} }
Subroutine get_roles: not called CC=1 SCAR=6.9
Pod undocumented
381  
382 0 ▶sub add_before_method_modifier {
Subroutine add_before_method_modifier: not called CC=2 SCAR=17.9
Pod undocumented
383 0 my ($self, $method_name, $method) = @_;
384  
385 0 ▶ push @{ $self->{before_method_modifiers}{$method_name} ||= [] }, $method;
Condition0%0/2
$self->{"before_method_modifiers"}{$method_name} ||= []
l!l
00
MC/DC0%0/1
$self->{"before_method_modifiers"}{$method_name} ||= []
$self->{"before_method_modifiers"}{$method_name}
Truth table0%0/2
A
A= $self->{"before_method_modifiers"}{$method_name}
Aresult
11
00
386 0 return;
387 }
388 0 ▶sub add_around_method_modifier {
Subroutine add_around_method_modifier: not called CC=2 SCAR=17.9
Pod undocumented
389 0 my ($self, $method_name, $method) = @_;
390  
391 0 ▶ push @{ $self->{around_method_modifiers}{$method_name} ||= [] }, $method;
Condition0%0/2
$self->{"around_method_modifiers"}{$method_name} ||= []
l!l
00
MC/DC0%0/1
$self->{"around_method_modifiers"}{$method_name} ||= []
$self->{"around_method_modifiers"}{$method_name}
Truth table0%0/2
A
A= $self->{"around_method_modifiers"}{$method_name}
Aresult
11
00
392 0 return;
393 }
394 0 ▶sub add_after_method_modifier {
Subroutine add_after_method_modifier: not called CC=2 SCAR=17.9
Pod undocumented
395 0 my ($self, $method_name, $method) = @_;
396  
397 0 ▶ push @{ $self->{after_method_modifiers}{$method_name} ||= [] }, $method;
Condition0%0/2
$self->{"after_method_modifiers"}{$method_name} ||= []
l!l
00
MC/DC0%0/1
$self->{"after_method_modifiers"}{$method_name} ||= []
$self->{"after_method_modifiers"}{$method_name}
Truth table0%0/2
A
A= $self->{"after_method_modifiers"}{$method_name}
Aresult
11
00
398 0 return;
399 }
400  
401 0 ▶sub get_before_method_modifiers {
Subroutine get_before_method_modifiers: not called CC=2 SCAR=17.9
Pod undocumented
402 0 my ($self, $method_name) = @_;
403 0 ▶ return @{ $self->{before_method_modifiers}{$method_name} ||= [] }
Condition0%0/2
$self->{"before_method_modifiers"}{$method_name} ||= []
l!l
00
MC/DC0%0/1
$self->{"before_method_modifiers"}{$method_name} ||= []
$self->{"before_method_modifiers"}{$method_name}
Truth table0%0/2
A
A= $self->{"before_method_modifiers"}{$method_name}
Aresult
11
00
404 }
405 0 ▶sub get_around_method_modifiers {
Subroutine get_around_method_modifiers: not called CC=2 SCAR=17.9
Pod undocumented
406 0 my ($self, $method_name) = @_;
407 0 ▶ return @{ $self->{around_method_modifiers}{$method_name} ||= [] }
Condition0%0/2
$self->{"around_method_modifiers"}{$method_name} ||= []
l!l
00
MC/DC0%0/1
$self->{"around_method_modifiers"}{$method_name} ||= []
$self->{"around_method_modifiers"}{$method_name}
Truth table0%0/2
A
A= $self->{"around_method_modifiers"}{$method_name}
Aresult
11
00
408 }
409 0 ▶sub get_after_method_modifiers {
Subroutine get_after_method_modifiers: not called CC=2 SCAR=17.9
Pod undocumented
410 0 my ($self, $method_name) = @_;
411 0 ▶ return @{ $self->{after_method_modifiers}{$method_name} ||= [] }
Condition0%0/2
$self->{"after_method_modifiers"}{$method_name} ||= []
l!l
00
MC/DC0%0/1
$self->{"after_method_modifiers"}{$method_name} ||= []
$self->{"after_method_modifiers"}{$method_name}
Truth table0%0/2
A
A= $self->{"after_method_modifiers"}{$method_name}
Aresult
11
00
412 }
413  
414 0 ▶sub add_metaclass_accessor { # for meta roles (a.k.a. traits)
Subroutine add_metaclass_accessor: not called CC=1 SCAR=6.9
Pod undocumented
415 0 my($meta, $name) = @_;
416 0 $meta->add_method($name => $generate_class_accessor->($name));
417 0 return;
418 }
419  
420 package Mouse::Meta::Attribute;
421  
422 1 require Mouse::Meta::Method::Accessor;
423  
424 0 ▶sub accessor_metaclass{ $_[0]->{accessor_metaclass} || 'Mouse::Meta::Method::Accessor' }
Subroutine accessor_metaclass: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"accessor_metaclass"} or "Mouse::Meta::Method::Accessor" 0 0 0
425  
426 # readers
427  
428 0 ▶sub name { $_[0]->{name} }
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
429 0 ▶sub associated_class { $_[0]->{associated_class} }
Subroutine associated_class: not called CC=1 SCAR=6.9
Pod undocumented
430  
431 0 ▶sub accessor { $_[0]->{accessor} }
Subroutine accessor: not called CC=1 SCAR=6.9
Pod undocumented
432 0 ▶sub reader { $_[0]->{reader} }
Subroutine reader: not called CC=1 SCAR=6.9
Pod undocumented
433 0 ▶sub writer { $_[0]->{writer} }
Subroutine writer: not called CC=1 SCAR=6.9
Pod undocumented
434 0 ▶sub predicate { $_[0]->{predicate} }
Subroutine predicate: not called CC=1 SCAR=6.9
Pod undocumented
435 0 ▶sub clearer { $_[0]->{clearer} }
Subroutine clearer: not called CC=1 SCAR=6.9
Pod undocumented
436 0 ▶sub handles { $_[0]->{handles} }
Subroutine handles: not called CC=1 SCAR=6.9
Pod undocumented
437  
438 0 ▶sub _is_metadata { $_[0]->{is} }
Subroutine _is_metadata: not called CC=1 SCAR=6.9
439 0 ▶sub is_required { $_[0]->{required} }
Subroutine is_required: not called CC=1 SCAR=6.9
Pod undocumented
440 0 ▶sub default {
Subroutine default: not called CC=3 SCAR=24.8
Pod undocumented
441 0 my($self, $instance) = @_;
442 0 my $value = $self->{default};
443 0 ▶ $value = $value->($instance) if defined($instance) and ref($value) eq "CODE";
Branch: 1 branch
BranchTrueFalseTotal
if defined $instance and ref $value eq "CODE" 0 0 0
Condition0%0/3
defined $instance and ref $value eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $instance and ref $value eq "CODE"
defined $instance ref $value eq "CODE"
Truth table0%0/3
A and B
A= defined $instanceB= ref $value eq "CODE"
ABresult
0X0
100
111
444 0 return $value;
445 }
446 0 ▶sub is_lazy { $_[0]->{lazy} }
Subroutine is_lazy: not called CC=1 SCAR=6.9
Pod undocumented
447 0 ▶sub is_lazy_build { $_[0]->{lazy_build} }
Subroutine is_lazy_build: not called CC=1 SCAR=6.9
Pod undocumented
448 0 ▶sub is_weak_ref { $_[0]->{weak_ref} }
Subroutine is_weak_ref: not called CC=1 SCAR=6.9
Pod undocumented
449 0 ▶sub init_arg { $_[0]->{init_arg} }
Subroutine init_arg: not called CC=1 SCAR=6.9
Pod undocumented
450 0 ▶sub type_constraint { $_[0]->{type_constraint} }
Subroutine type_constraint: not called CC=1 SCAR=6.9
Pod undocumented
451  
452 0 ▶sub trigger { $_[0]->{trigger} }
Subroutine trigger: not called CC=1 SCAR=6.9
Pod documented
453 0 ▶sub builder { $_[0]->{builder} }
Subroutine builder: not called CC=1 SCAR=6.9
Pod undocumented
454 0 ▶sub should_auto_deref { $_[0]->{auto_deref} }
Subroutine should_auto_deref: not called CC=1 SCAR=6.9
Pod undocumented
455 0 ▶sub should_coerce { $_[0]->{coerce} }
Subroutine should_coerce: not called CC=1 SCAR=6.9
Pod undocumented
456  
457 0 ▶sub documentation { $_[0]->{documentation} }
Subroutine documentation: not called CC=1 SCAR=6.9
Pod undocumented
458 0 ▶sub insertion_order { $_[0]->{insertion_order} }
Subroutine insertion_order: not called CC=1 SCAR=6.9
Pod undocumented
459  
460 # predicates
461  
462 0 ▶sub has_accessor { exists $_[0]->{accessor} }
Subroutine has_accessor: not called CC=1 SCAR=6.9
Pod undocumented
463 0 ▶sub has_reader { exists $_[0]->{reader} }
Subroutine has_reader: not called CC=1 SCAR=6.9
Pod undocumented
464 0 ▶sub has_writer { exists $_[0]->{writer} }
Subroutine has_writer: not called CC=1 SCAR=6.9
Pod undocumented
465 0 ▶sub has_predicate { exists $_[0]->{predicate} }
Subroutine has_predicate: not called CC=1 SCAR=6.9
Pod undocumented
466 0 ▶sub has_clearer { exists $_[0]->{clearer} }
Subroutine has_clearer: not called CC=1 SCAR=6.9
Pod undocumented
467 0 ▶sub has_handles { exists $_[0]->{handles} }
Subroutine has_handles: not called CC=1 SCAR=6.9
Pod undocumented
468  
469 0 ▶sub has_default { exists $_[0]->{default} }
Subroutine has_default: not called CC=1 SCAR=6.9
Pod undocumented
470 0 ▶sub has_type_constraint { exists $_[0]->{type_constraint} }
Subroutine has_type_constraint: not called CC=1 SCAR=6.9
Pod undocumented
471 0 ▶sub has_trigger { exists $_[0]->{trigger} }
Subroutine has_trigger: not called CC=1 SCAR=6.9
Pod undocumented
472 0 ▶sub has_builder { exists $_[0]->{builder} }
Subroutine has_builder: not called CC=1 SCAR=6.9
Pod undocumented
473  
474 0 ▶sub has_documentation { exists $_[0]->{documentation} }
Subroutine has_documentation: not called CC=1 SCAR=6.9
Pod undocumented
475  
476 0 ▶sub _process_options{
Subroutine _process_options: not called CC=43 SCAR=75.5
477 0 my($class, $name, $args) = @_;
478  
479 # taken from Class::MOP::Attribute::new
480  
481 0 ▶ defined($name)
Branch: 1 branch
BranchTrueFalseTotal
defined $name or $class->throw_error("You must provide a name for the attribute") 0 0 0
482 or $class->throw_error('You must provide a name for the attribute');
483  
484 0 ▶ if(!exists $args->{init_arg}){
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args->{"init_arg"}) 0 0 0
485 0 $args->{init_arg} = $name;
486 }
487  
488 # 'required' requires either 'init_arg', 'builder', or 'default'
489 0 my $can_be_required = defined( $args->{init_arg} );
490  
491 0 ▶ if(exists $args->{builder}){
Branch: 2 branches
BranchTrueFalseTotal
if (exists $args->{'builder'}) { } 0 0 0
elsif (exists $args->{'default'}) { } 0 0 0
492 # XXX:
493 # Moose refuses a CODE ref builder, but Mouse doesn't for backward compatibility
494 # This feature will be changed in a future. (gfx)
495 $class->throw_error('builder must be a defined scalar value which is a method name')
496 #if ref $args->{builder} || !defined $args->{builder};
497 0 ▶ if !defined $args->{builder};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args->{"builder"} 0 0 0
498  
499 0 $can_be_required++;
500 }
501 elsif(exists $args->{default}){
502 0 ▶ if(ref $args->{default} && ref($args->{default}) ne 'CODE'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args->{"default"} and ref $args->{"default"} ne "CODE") 0 0 0
Condition0%0/3
ref $args->{"default"} and ref $args->{"default"} ne "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $args->{"default"} and ref $args->{"default"} ne "CODE"
ref $args->{"default"} ref $args->{"default"} ne "CODE"
Truth table0%0/3
A and B
A= ref $args->{"default"}B= ref $args->{"default"} ne "CODE"
ABresult
0X0
100
111
503 0 $class->throw_error("References are not allowed as default values, you must "
504 . "wrap the default of '$name' in a CODE reference (ex: sub { [] } and not [])");
505 }
506 0 $can_be_required++;
507 }
508  
509 0 ▶ if( $args->{required} && !$can_be_required ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"required"} and not $can_be_required) 0 0 0
Condition0%0/3
$args->{"required"} and not $can_be_required
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{"required"} and not $can_be_required
$args->{"required"} not $can_be_required
Truth table0%0/3
A and not(B)
A= $args->{"required"}B= not $can_be_required
ABresult
0X0
100
111
510 0 $class->throw_error("You cannot have a required attribute ($name) without a default, builder, or an init_arg");
511 }
512  
513 # taken from Mouse::Meta::Attribute->new and ->_process_args
514  
515 0 ▶ if(exists $args->{is}){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"is"}) 0 0 0
516 0 my $is = $args->{is};
517  
518 0 ▶ if($is eq 'ro'){
Branch: 3 branches
BranchTrueFalseTotal
if ($is eq 'ro') { } 0 0 0
elsif ($is eq 'rw') { } 0 0 0
elsif ($is eq 'bare') { } 0 0 0
519 0 ▶ $args->{reader} ||= $name;
Condition0%0/3
$args->{"reader"} ||= $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{"reader"} ||= $name
$args->{"reader"} $name
Truth table0%0/3
A ||= B
A= $args->{"reader"}B= $name
ABresult
1X1
011
000
520 }
521 elsif($is eq 'rw'){
522 0 ▶ if(exists $args->{writer}){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{'writer'}) { } 0 0 0
523 0 ▶ $args->{reader} ||= $name;
Condition0%0/3
$args->{"reader"} ||= $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{"reader"} ||= $name
$args->{"reader"} $name
Truth table0%0/3
A ||= B
A= $args->{"reader"}B= $name
ABresult
1X1
011
000
524 }
525 else{
526 0 ▶ $args->{accessor} ||= $name;
Condition0%0/3
$args->{"accessor"} ||= $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{"accessor"} ||= $name
$args->{"accessor"} $name
Truth table0%0/3
A ||= B
A= $args->{"accessor"}B= $name
ABresult
1X1
011
000
527 }
528 }
529 elsif($is eq 'bare'){
530 # do nothing, but don't complain (later) about missing methods
531 }
532 else{
533 0 ▶ $is = 'undef' if !defined $is;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $is 0 0 0
534 0 $class->throw_error("I do not understand this option (is => $is) on attribute ($name)");
535 }
536 }
537  
538 0 my $tc;
539 0 ▶ if(exists $args->{isa}){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"isa"}) 0 0 0
540 0 $tc = $args->{type_constraint} = Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint($args->{isa});
541 }
542  
543 0 ▶ if(exists $args->{does}){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"does"}) 0 0 0
544 0 ▶ if(defined $tc){ # both isa and does supplied
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tc) { } 0 0 0
545 0 my $does_ok = do{
546 0 local $@;
547 0 eval{ "$tc"->does($args->{does}) };
548 };
549 0 ▶ if(!$does_ok){
Branch: 1 branch
BranchTrueFalseTotal
unless ($does_ok) 0 0 0
550 0 $class->throw_error("Cannot have both an isa option and a does option because '$tc' does not do '$args->{does}' on attribute ($name)");
551 }
552 }
553 else {
554 0 $tc = $args->{type_constraint} = Mouse::Util::TypeConstraints::find_or_create_does_type_constraint($args->{does});
555 }
556 }
557  
558 0 ▶ if($args->{coerce}){
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"coerce"}) 0 0 0
559 0 ▶ defined($tc)
Branch: 1 branch
BranchTrueFalseTotal
defined $tc or $class->throw_error("You cannot have coercion without specifying a type constraint on attribute ($name)") 0 0 0
560 || $class->throw_error("You cannot have coercion without specifying a type constraint on attribute ($name)");
561  
562 $args->{weak_ref}
563 0 ▶ && $class->throw_error("You cannot have a weak reference to a coerced value on attribute ($name)");
Branch: 1 branch
BranchTrueFalseTotal
$args->{"weak_ref"} and $class->throw_error("You cannot have a weak reference to a coerced value on attribute ($name)") 0 0 0
564 }
565  
566 0 ▶ if ($args->{lazy_build}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"lazy_build"}) 0 0 0
567 exists($args->{default})
568 0 ▶ && $class->throw_error("You can not use lazy_build and default for the same attribute ($name)");
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{"default"} and $class->throw_error("You can not use lazy_build and default for the same attribute ($name)") 0 0 0
569  
570 0 $args->{lazy} = 1;
571 0 ▶ $args->{builder} ||= "_build_${name}";
Condition0%0/2
$args->{"builder"} ||= "_build_$name"
l!l
00
MC/DC0%0/1
$args->{"builder"} ||= "_build_$name"
$args->{"builder"}
Truth table0%0/2
A
A= $args->{"builder"}
Aresult
11
00
572 0 ▶ if ($name =~ /^_/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^_/) { } 0 0 0
573 0 ▶ $args->{clearer} ||= "_clear${name}";
Condition0%0/2
$args->{"clearer"} ||= "_clear$name"
l!l
00
MC/DC0%0/1
$args->{"clearer"} ||= "_clear$name"
$args->{"clearer"}
Truth table0%0/2
A
A= $args->{"clearer"}
Aresult
11
00
574 0 ▶ $args->{predicate} ||= "_has${name}";
Condition0%0/2
$args->{"predicate"} ||= "_has$name"
l!l
00
MC/DC0%0/1
$args->{"predicate"} ||= "_has$name"
$args->{"predicate"}
Truth table0%0/2
A
A= $args->{"predicate"}
Aresult
11
00
575 }
576 else {
577 0 ▶ $args->{clearer} ||= "clear_${name}";
Condition0%0/2
$args->{"clearer"} ||= "clear_$name"
l!l
00
MC/DC0%0/1
$args->{"clearer"} ||= "clear_$name"
$args->{"clearer"}
Truth table0%0/2
A
A= $args->{"clearer"}
Aresult
11
00
578 0 ▶ $args->{predicate} ||= "has_${name}";
Condition0%0/2
$args->{"predicate"} ||= "has_$name"
l!l
00
MC/DC0%0/1
$args->{"predicate"} ||= "has_$name"
$args->{"predicate"}
Truth table0%0/2
A
A= $args->{"predicate"}
Aresult
11
00
579 }
580 }
581  
582 0 ▶ if ($args->{auto_deref}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"auto_deref"}) 0 0 0
583 0 ▶ defined($tc)
Branch: 1 branch
BranchTrueFalseTotal
defined $tc or $class->throw_error("You cannot auto-dereference without specifying a type constraint on attribute ($name)") 0 0 0
584 || $class->throw_error("You cannot auto-dereference without specifying a type constraint on attribute ($name)");
585  
586 0 ▶ ( $tc->is_a_type_of('ArrayRef') || $tc->is_a_type_of('HashRef') )
Branch: 1 branch
BranchTrueFalseTotal
$tc->is_a_type_of("ArrayRef") or $tc->is_a_type_of("HashRef") or $class->throw_error("You cannot auto-dereference anything other than a ArrayRef or HashRef on attribute ($name)") 0 0 0
Condition0%0/3
$tc->is_a_type_of("ArrayRef") or $tc->is_a_type_of("HashRef")
l!l&&r!l&&!r
000
MC/DC0%0/2
$tc->is_a_type_of("ArrayRef") or $tc->is_a_type_of("HashRef")
$tc->is_a_type_of("ArrayRef") $tc->is_a_type_of("HashRef")
Truth table0%0/3
A or B
A= $tc->is_a_type_of("ArrayRef")B= $tc->is_a_type_of("HashRef")
ABresult
1X1
011
000
587 || $class->throw_error("You cannot auto-dereference anything other than a ArrayRef or HashRef on attribute ($name)");
588 }
589  
590 0 ▶ if (exists $args->{trigger}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"trigger"}) 0 0 0
591 ('CODE' eq ref $args->{trigger})
592 0 ▶ || $class->throw_error("Trigger must be a CODE ref on attribute ($name)");
Branch: 1 branch
BranchTrueFalseTotal
"CODE" eq ref $args->{"trigger"} or $class->throw_error("Trigger must be a CODE ref on attribute ($name)") 0 0 0
593 }
594  
595 0 ▶ if ($args->{lazy}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"lazy"}) 0 0 0
596 (exists $args->{default} || defined $args->{builder})
597 0 ▶ || $class->throw_error("You cannot have a lazy attribute ($name) without specifying a default value for it");
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{"default"} or defined $args->{"builder"} or $class->throw_error("You cannot have a lazy attribute ($name) without specifying a default value for it") 0 0 0
Condition0%0/3
exists $args->{"default"} or defined $args->{"builder"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $args->{"default"} or defined $args->{"builder"}
exists $args->{"default"} defined $args->{"builder"}
Truth table0%0/3
A or B
A= exists $args->{"default"}B= defined $args->{"builder"}
ABresult
1X1
011
000
598 }
599  
600 0 return;
601 }
602  
603  
604 package Mouse::Meta::TypeConstraint;
605  
606 use overload
607 1 ▶ '""' => '_as_string',
Subroutine BEGIN: called CC=1 SCAR=0.0
608 '0+' => '_identity',
609 '|' => '_unite',
610  
611 1 fallback => 1;
612  
613 0 ▶sub name { $_[0]->{name} }
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
614 0 ▶sub parent { $_[0]->{parent} }
Subroutine parent: not called CC=1 SCAR=6.9
Pod documented
615 0 ▶sub message { $_[0]->{message} }
Subroutine message: not called CC=1 SCAR=6.9
Pod documented
616  
617 0 ▶sub _identity { Scalar::Util::refaddr($_[0]) } # overload 0+
Subroutine _identity: not called CC=1 SCAR=6.9
618  
619 0 ▶sub type_parameter { $_[0]->{type_parameter} }
Subroutine type_parameter: not called CC=1 SCAR=6.9
Pod undocumented
620 0 ▶sub _compiled_type_constraint{ $_[0]->{compiled_type_constraint} }
Subroutine _compiled_type_constraint: not called CC=1 SCAR=6.9
621  
622 0 ▶sub __is_parameterized { exists $_[0]->{type_parameter} }
Subroutine __is_parameterized: not called CC=1 SCAR=6.9
623 0 ▶sub has_coercion { exists $_[0]->{_compiled_type_coercion} }
Subroutine has_coercion: not called CC=1 SCAR=6.9
Pod documented
624  
625  
626 3 ▶sub compile_type_constraint{
Subroutine compile_type_constraint: called CC=7 SCAR=29.2
Pod undocumented
627 3 my($self) = @_;
628  
629 # add parents first
630 3 my @checks;
631 3 ▶ for(my $parent = $self->{parent}; defined $parent; $parent = $parent->{parent}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent) 3 3 6
632 3 ▶ if($parent->{hand_optimized_type_constraint}){
Branch: 2 branches
BranchTrueFalseTotal
if ($parent->{'hand_optimized_type_constraint'}) { } 0 3 3
elsif ($parent->{'constraint'}) { } 0 3 3
633 0 unshift @checks, $parent->{hand_optimized_type_constraint};
634 0 last; # a hand optimized constraint must include all the parents
635 }
636 elsif($parent->{constraint}){
637 0 unshift @checks, $parent->{constraint};
638 }
639 }
640  
641 # then add child
642 3 ▶ if($self->{constraint}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"constraint"}) 0 3 3
643 0 push @checks, $self->{constraint};
644 }
645  
646 3 ▶ if($self->{type_constraints}){ # Union
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"type_constraints"}) 0 3 3
647 0 my @types = map{ $_->{compiled_type_constraint} } @{ $self->{type_constraints} };
648 0 ▶ push @checks, sub{
Subroutine __ANON__: not called CC=3 SCAR=24.8
649 0 foreach my $c(@types){
650 0 ▶ return 1 if $c->($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if &$c($_[0]) 0 0 0
651 }
652 0 return 0;
653 0 };
654 }
655  
656 3 ▶ if(@checks == 0){
Branch: 1 branch
BranchTrueFalseTotal
if (@checks == 0) { } 3 0 3
657 3 $self->{compiled_type_constraint} = \&Mouse::Util::TypeConstraints::Any;
658 }
659 else{
660 0 ▶ $self->{compiled_type_constraint} = sub{
Subroutine __ANON__: not called CC=4 SCAR=30.0
661 0 my(@args) = @_;
662 0 for ($args[0]) { # local $_ will cancel tie-ness due to perl's bug
663 0 foreach my $c(@checks){
664 0 ▶ return undef if !$c->(@args);
Branch: 1 branch
BranchTrueFalseTotal
unless &$c(@args) 0 0 0
665 }
666 }
667 0 return 1;
668 0 };
669 }
670 3 return;
671 }
672  
673 0 ▶sub check {
Subroutine check: not called CC=1 SCAR=6.9
Pod documented
674 0 my $self = shift;
675 0 return $self->_compiled_type_constraint->(@_);
676 }
677  
678  
679 package Mouse::Object;
680  
681 0 ▶sub BUILDARGS {
Subroutine BUILDARGS: not called CC=3 SCAR=24.8
Pod documented
682 0 my $class = shift;
683  
684 0 ▶ if (scalar @_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 0 0 0
685 0 ▶ (ref($_[0]) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq "HASH" or $class->meta->throw_error("Single parameters to new() must be a HASH ref") 0 0 0
686 || $class->meta->throw_error("Single parameters to new() must be a HASH ref");
687  
688 0 return {%{$_[0]}};
689 }
690 else {
691 0 return {@_};
692 }
693 }
694  
695 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
696 0 my $class = shift;
697 0 my $args = $class->BUILDARGS(@_);
698 0 return $class->meta->new_object($args);
699 }
700  
701 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=5 SCAR=30.3
702 0 my $self = shift;
703  
704 0 ▶ return unless $self->can('DEMOLISH'); # short circuit
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can("DEMOLISH") 0 0 0
705  
706 0 my $e = do{
707 0 local $?;
708 0 local $@;
709 0 eval{
710 # DEMOLISHALL
711  
712 # We cannot count on being able to retrieve a previously made
713 # metaclass, _or_ being able to make a new one during global
714 # destruction. However, we should still be able to use mro at
715 # that time (at least tests suggest so ;)
716  
717 0 foreach my $class (@{ Mouse::Util::get_linear_isa(ref $self) }) {
718 0 ▶ my $demolish = Mouse::Util::get_code_ref($class, 'DEMOLISH')
Condition0%0/2
Mouse::Util::get_code_ref($class, 'DEMOLISH') || (next)
l!l
00
MC/DC0%0/1
Mouse::Util::get_code_ref($class, 'DEMOLISH') || (next)
Mouse::Util::get_code_ref($class, 'DEMOLISH')
Truth table0%0/2
A
A= Mouse::Util::get_code_ref($class, 'DEMOLISH')
Aresult
11
00
719 || next;
720  
721 0 $self->$demolish(Mouse::Util::in_global_destruction());
722 }
723 };
724 0 $@;
725 };
726  
727 1 ▶ no warnings 'misc';
Subroutine BEGIN: called CC=1 SCAR=0.0
728 0 ▶ die $e if $e; # rethrow
Branch: 1 branch
BranchTrueFalseTotal
if $e 0 0 0
729 }
730  
731 0 ▶sub BUILDALL {
Subroutine BUILDALL: not called CC=4 SCAR=30.0
Pod documented
732 0 my $self = shift;
733  
734 # short circuit
735 0 ▶ return unless $self->can('BUILD');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can("BUILD") 0 0 0
736  
737 0 for my $class (reverse $self->meta->linearized_isa) {
738 0 ▶ my $build = Mouse::Util::get_code_ref($class, 'BUILD')
Condition0%0/2
Mouse::Util::get_code_ref($class, 'BUILD') || (next)
l!l
00
MC/DC0%0/1
Mouse::Util::get_code_ref($class, 'BUILD') || (next)
Mouse::Util::get_code_ref($class, 'BUILD')
Truth table0%0/2
A
A= Mouse::Util::get_code_ref($class, 'BUILD')
Aresult
11
00
739 || next;
740  
741 0 $self->$build(@_);
742 }
743 0 return;
744 }
745  
746 sub DEMOLISHALL;
747 1 *DEMOLISHALL = \&DESTROY;
748  
749 1 1;
750 __END__
« blib/lib/Mouse/Meta/Method/Constructor.pm ↑ Summary blib/lib/Mouse/Tiny.pm »