blib/lib/Mouse/Util/TypeConstraints.pm

filter: Statementstmt 91.6% 164 / 179 Branchbran 84.0% 74 / 88 Conditioncond 68.0% 32 / 47 MC/DCmcdc 43.3% 13 / 30 Subroutinesub 94.7% 36 / 38 Podpod 63.6% 14 / 22 totaltotal 82.4% 333 / 404 CC 60 SCAR 19.7
CC
60
Cov
86%
_define_type
22.4
_find_or_create_regular_type
6.3
enum
5.2
CRAP 7.2
« blib/lib/Mouse/Meta/Method/Delegation.pm ↑ Summary blib/lib/Mouse/Meta/Class.pm »
1 package Mouse::Util::TypeConstraints;
2 286 ▶use Mouse::Util; # enables strict and warnings
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 286 ▶use Mouse::Meta::TypeConstraint;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 286 ▶use Mouse::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 286 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 286 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 286 Mouse::Exporter->setup_import_methods(
11 as_is => [qw(
12 as where message optimize_as
13 from via
14  
15 type subtype class_type role_type maybe_type duck_type
16 enum
17 coerce
18  
19 find_type_constraint
20 register_type_constraint
21 )],
22 );
23  
24 286 our @CARP_NOT = qw(Mouse::Meta::Attribute);
25  
26 286 my %TYPE;
27  
28 # The root type
29 286 $TYPE{Any} = Mouse::Meta::TypeConstraint->new(
30 name => 'Any',
31 );
32  
33 286 my @builtins = (
34 # $name => $parent, $code,
35  
36 # the base type
37 Item => 'Any', undef,
38  
39 # the maybe[] type
40 Maybe => 'Item', undef,
41  
42 # value types
43 Undef => 'Item', \&Undef,
44 Defined => 'Item', \&Defined,
45 Bool => 'Item', \&Bool,
46 Value => 'Defined', \&Value,
47 Str => 'Value', \&Str,
48 Num => 'Str', \&Num,
49 Int => 'Num', \&Int,
50  
51 # ref types
52 Ref => 'Defined', \&Ref,
53 ScalarRef => 'Ref', \&ScalarRef,
54 ArrayRef => 'Ref', \&ArrayRef,
55 HashRef => 'Ref', \&HashRef,
56 CodeRef => 'Ref', \&CodeRef,
57 RegexpRef => 'Ref', \&RegexpRef,
58 GlobRef => 'Ref', \&GlobRef,
59  
60 # object types
61 FileHandle => 'GlobRef', \&FileHandle,
62 Object => 'Ref', \&Object,
63  
64 # special string types
65 ClassName => 'Str', \&ClassName,
66 RoleName => 'ClassName', \&RoleName,
67 );
68  
69 286 ▶while (my ($name, $parent, $code) = splice @builtins, 0, 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@builtins, 0, 3)) 5720 286 6006
70 $TYPE{$name} = Mouse::Meta::TypeConstraint->new(
71 name => $name,
72 5720 parent => $TYPE{$parent},
73 optimized => $code,
74 );
75 }
76  
77 # parametarizable types
78 286 $TYPE{Maybe} {constraint_generator} = \&_parameterize_Maybe_for;
79 286 $TYPE{ArrayRef}{constraint_generator} = \&_parameterize_ArrayRef_for;
80 286 $TYPE{HashRef} {constraint_generator} = \&_parameterize_HashRef_for;
81  
82 # sugars
83 59 ▶sub as ($) { (as => $_[0]) } ## no critic
Subroutine as: called CC=1 SCAR=0.0
Pod documented
84 59 ▶sub where (&) { (where => $_[0]) } ## no critic
Subroutine where: called CC=1 SCAR=0.0
Pod documented
85 7 ▶sub message (&) { (message => $_[0]) } ## no critic
Subroutine message: called CC=1 SCAR=0.0
Pod undocumented
86 0 ▶sub optimize_as (&) { (optimize_as => $_[0]) } ## no critic
Subroutine optimize_as: not called CC=1 SCAR=6.9
Pod undocumented
87  
88 37 ▶sub from { @_ }
Subroutine from: called CC=1 SCAR=0.0
Pod documented
89 37 ▶sub via (&) { $_[0] } ## no critic
Subroutine via: called CC=1 SCAR=0.0
Pod documented
90  
91 # type utilities
92  
93 0 ▶sub optimized_constraints { # DEPRECATED
Subroutine optimized_constraints: not called CC=1 SCAR=6.9
Pod undocumented
94 0 Carp::cluck('optimized_constraints() has been deprecated');
95 0 return \%TYPE;
96 }
97  
98 286 undef @builtins; # free the allocated memory
99 286 @builtins = keys %TYPE; # reuse it
100 1 ▶sub list_all_builtin_type_constraints { @builtins }
Subroutine list_all_builtin_type_constraints: called CC=1 SCAR=0.0
Pod documented
101 5 ▶sub list_all_type_constraints { keys %TYPE }
Subroutine list_all_type_constraints: called CC=1 SCAR=0.0
Pod documented
102  
103 858 ▶sub _define_type {
Subroutine _define_type: called CC=21 SCAR=31.1
104 858 my $is_subtype = shift;
105 858 my $name;
106 my %args;
107  
108 858 ▶ if(@_ == 1 && ref $_[0] ){ # @_ : { name => $name, where => ... }
Branch: 3 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0]) { } 0 858 858
elsif (@_ == 2 and ref $_[1]) { } 0 858 858
elsif (@_ % 2) { } 855 3 858
Condition33%1/3
@_ == 1 and ref $_[0]
!ll&&!rl&&r
85800
MC/DC0%0/2
@_ == 1 and ref $_[0]
@_ == 1 ref $_[0]
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0]
ABresult
0X0
100
111
109 0 %args = %{$_[0]};
110 }
111 ▶ elsif(@_ == 2 && ref $_[1]) { # @_ : $name => { where => ... }
Condition66%2/3
@_ == 2 and ref $_[1]
!ll&&!rl&&r
85710
MC/DC0%0/2
@_ == 2 and ref $_[1]
@_ == 2 ref $_[1]
Truth table66%2/3
A and B
A= @_ == 2B= ref $_[1]
ABresult
0X0
100
111
112 0 $name = $_[0];
113 0 %args = %{$_[1]};
114 }
115 elsif(@_ % 2) { # @_ : $name => ( where => ... )
116 855 ($name, %args) = @_;
117 }
118 else{ # @_ : (name => $name, where => ...)
119 3 %args = @_;
120 }
121  
122 858 ▶ if(!defined $name){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 7 851 858
123 7 $name = $args{name};
124 }
125  
126 858 $args{name} = $name;
127  
128 858 my $parent = delete $args{as};
129 858 ▶ if($is_subtype && !$parent){
Branch: 1 branch
BranchTrueFalseTotal
if ($is_subtype and not $parent) 3 855 858
Condition100%3/3
$is_subtype and not $parent
!ll&&!rl&&r
168393
MC/DC100%2/2
$is_subtype and not $parent
$is_subtype not $parent
Truth table100%3/3
A and not(B)
A= $is_subtypeB= not $parent
ABresult
0X0
100
111
130 3 $parent = delete $args{name};
131 3 $name = undef;
132 }
133  
134 858 ▶ if(defined $parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent) 842 16 858
135 842 $args{parent} = find_or_create_isa_type_constraint($parent);
136 }
137  
138 857 ▶ if(defined $name){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) 847 10 857
139 # set 'package_defined_in' only if it is not a core package
140 847 my $this = $args{package_defined_in};
141 847 ▶ if(!$this){
Branch: 1 branch
BranchTrueFalseTotal
unless ($this) 847 0 847
142 847 $this = caller(1);
143 847 ▶ if($this !~ /\A Mouse \b/xms){
Branch: 1 branch
BranchTrueFalseTotal
unless ($this =~ /\A Mouse \b/msx) 80 767 847
144 80 $args{package_defined_in} = $this;
145 }
146 }
147  
148 847 ▶ if(defined $TYPE{$name}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $TYPE{$name}) 10 837 847
149 10 ▶ my $that = $TYPE{$name}->{package_defined_in} || __PACKAGE__;
Condition100%2/2
$TYPE{$name}{'package_defined_in'} || __PACKAGE__
l!l
64
MC/DC100%1/1
$TYPE{$name}{'package_defined_in'} || __PACKAGE__
$TYPE{$name}{'package_defined_in'}
Truth table100%2/2
A
A= $TYPE{$name}{'package_defined_in'}
Aresult
11
00
150 10 ▶ if($this ne $that) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this ne $that) 3 7 10
151 3 my $note = '';
152 3 ▶ if($that eq __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($that eq __PACKAGE__) 1 2 3
153 $note = sprintf " ('%s' is %s type constraint)",
154 $name,
155 1 ▶ scalar(grep { $name eq $_ } list_all_builtin_type_constraints())
Branch: 1 branch
BranchTrueFalseTotal
scalar grep({$name eq $_;} list_all_builtin_type_constraints()) ? : 1 0 1
156 ? 'a builtin'
157 : 'an implicitly created';
158 }
159 3 Carp::croak("The type constraint '$name' has already been created in $that"
160 . " and cannot be created again in $this" . $note);
161 }
162 }
163 }
164  
165 854 ▶ $args{constraint} = delete $args{where} if exists $args{where};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"where"} 56 798 854
166 854 ▶ $args{optimized} = delete $args{optimized_as} if exists $args{optimized_as};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"optimized_as"} 780 74 854
167  
168 854 my $constraint = Mouse::Meta::TypeConstraint->new(%args);
169  
170 854 ▶ if(defined $name){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) { } 844 10 854
171 844 return $TYPE{$name} = $constraint;
172 }
173 else{
174 10 return $constraint;
175 }
176 }
177  
178 16 ▶sub type {
Subroutine type: called CC=1 SCAR=0.0
Pod documented
179 16 return _define_type 0, @_;
180 }
181  
182 829 ▶sub subtype {
Subroutine subtype: called CC=1 SCAR=0.0
Pod documented
183 829 return _define_type 1, @_;
184 }
185  
186 31 ▶sub coerce { # coerce $type, from $from, via { ... }, ...
Subroutine coerce: called CC=2 SCAR=6.9
Pod documented
187 31 my $type_name = shift;
188 31 ▶ my $type = find_type_constraint($type_name)
Branch: 1 branch
BranchTrueFalseTotal
my $type = find_type_constraint($type_name) or Carp::croak("Cannot find type '${type_name}', perhaps you forgot to load it") 30 1 31
189 or Carp::croak("Cannot find type '$type_name', perhaps you forgot to load it");
190  
191 30 $type->_add_type_coercions(@_);
192 28 return;
193 }
194  
195 574 ▶sub class_type {
Subroutine class_type: called CC=2 SCAR=7.6
Pod documented
196 574 my($name, $options) = @_;
197 574 ▶ my $class = $options->{class} || $name;
Condition33%1/3
$options->{'class'} || $name
l!l&&r!l&&!r
05740
MC/DC0%0/2
$options->{'class'} || $name
$options->{'class'} $name
Truth table33%1/3
A || B
A= $options->{'class'}B= $name
ABresult
1X1
011
000
198  
199 # ClassType
200 574 return subtype $name => (
201 as => 'Object',
202 optimized_as => Mouse::Util::generate_isa_predicate_for($class),
203 class => $class,
204 );
205 }
206  
207 193 ▶sub role_type {
Subroutine role_type: called CC=2 SCAR=7.0
Pod documented
208 193 my($name, $options) = @_;
209 193 ▶ my $role = $options->{role} || $name;
Condition66%2/3
$options->{'role'} || $name
l!l&&r!l&&!r
11920
MC/DC0%0/2
$options->{'role'} || $name
$options->{'role'} $name
Truth table66%2/3
A || B
A= $options->{'role'}B= $name
ABresult
1X1
011
000
210  
211 # RoleType
212 return subtype $name => (
213 as => 'Object',
214 23 ▶ optimized_as => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
215 23 ▶ return Scalar::Util::blessed($_[0])
Condition100%3/3
builtin::blessed($_[0]) && Mouse::Util::does_role($_[0], $role)
!ll&&!rl&&r
4109
MC/DC100%2/2
builtin::blessed($_[0]) && Mouse::Util::does_role($_[0], $role)
builtin::blessed($_[0]) Mouse::Util::does_role($_[0], $role)
Truth table100%3/3
A && B
A= builtin::blessed($_[0])B= Mouse::Util::does_role($_[0], $role)
ABresult
0X0
100
111
216 && Mouse::Util::does_role($_[0], $role);
217 },
218 193 role => $role,
219 );
220 }
221  
222 1 ▶sub maybe_type {
Subroutine maybe_type: called CC=1 SCAR=0.0
Pod undocumented
223 1 my $param = shift;
224 1 return _find_or_create_parameterized_type($TYPE{Maybe}, $param);
225 }
226  
227 6 ▶sub duck_type {
Subroutine duck_type: called CC=4 SCAR=13.9
Pod documented
228 6 my($name, @methods);
229  
230 6 ▶ if(ref($_[0]) ne 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] ne "ARRAY") 4 2 6
231 4 $name = shift;
232 }
233  
234 6 ▶ @methods = (@_ == 1 && ref($_[0]) eq 'ARRAY') ? @{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && ref $_[0] eq 'ARRAY' ? : 4 2 6
Condition66%2/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
024
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
235  
236 # DuckType
237 return _define_type 1, $name => (
238 as => 'Object',
239 optimized_as => Mouse::Util::generate_can_predicate_for(\@methods),
240 1 ▶ message => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
241 1 my($object) = @_;
242 1 my @missing = grep { !$object->can($_) } @methods;
243 1 return ref($object)
244 . ' is missing methods '
245 . Mouse::Util::quoted_english_list(@missing);
246 },
247 6 methods => \@methods,
248 );
249 }
250  
251 7 ▶sub enum {
Subroutine enum: called CC=5 SCAR=16.5
Pod documented
252 7 my($name, %valid);
253  
254 7 ▶ if(!(@_ == 1 && ref($_[0]) eq 'ARRAY')){
Branch: 1 branch
BranchTrueFalseTotal
unless (@_ == 1 and ref $_[0] eq "ARRAY") 5 2 7
Condition66%2/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
502
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
255 5 $name = shift;
256 }
257  
258 78 ▶ %valid = map{ $_ => undef }
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && ref $_[0] eq 'ARRAY' ? : 3 4 7
Condition66%2/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
403
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
259 7 (@_ == 1 && ref($_[0]) eq 'ARRAY' ? @{$_[0]} : @_);
260  
261 # EnumType
262 return _define_type 1, $name => (
263 as => 'Str',
264 120 ▶ optimized_as => sub{
Subroutine __ANON__: called CC=3 SCAR=13.1
265 120 ▶ return defined($_[0]) && !ref($_[0]) && exists $valid{$_[0]};
Condition50%3/6
defined $_[0] && !ref($_[0]) && exists $valid{$_[0]}
!ll&&!rl&&r
04278
defined $_[0] and not ref $_[0]
!ll&&!rl&&r
00120
MC/DC33%1/3
defined $_[0] && !ref($_[0]) && exists $valid{$_[0]}
defined $_[0] not ref $_[0] exists $valid{$_[0]}
Truth table50%2/4
A and not(B) && C
A= defined $_[0]B= not ref $_[0]C= exists $valid{$_[0]}
ABCresult
0XX0
10X0
1100
1111
266 },
267 7 );
268 }
269  
270 128 ▶sub _find_or_create_regular_type{
Subroutine _find_or_create_regular_type: called CC=5 SCAR=18.4
271 128 my($spec, $create) = @_;
272  
273 128 ▶ return $TYPE{$spec} if exists $TYPE{$spec};
Branch: 1 branch
BranchTrueFalseTotal
if exists $TYPE{$spec} 115 13 128
274  
275 13 my $meta = Mouse::Util::get_metaclass_by_name($spec);
276  
277 13 ▶ if(!defined $meta){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $meta) 13 0 13
278 13 ▶ return $create ? class_type($spec) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$create ? : 3 10 13
279 }
280  
281 0 ▶ if(Mouse::Util::is_a_metarole($meta)){
Branch: 1 branch
BranchTrueFalseTotal
if (Mouse::Util::is_a_metarole($meta)) { } 0 0 0
282 0 return role_type($spec);
283 }
284 else{
285 0 return class_type($spec);
286 }
287 }
288  
289 45 ▶sub _find_or_create_parameterized_type{
Subroutine _find_or_create_parameterized_type: called CC=2 SCAR=6.9
290 45 my($base, $param) = @_;
291  
292 45 my $name = sprintf '%s[%s]', $base->name, $param->name;
293  
294 45 ▶ $TYPE{$name} ||= $base->parameterize($param, $name);
Condition100%3/3
$TYPE{$name} ||= $base->parameterize($param, $name)
l!l&&r!l&&!r
1431
MC/DC100%2/2
$TYPE{$name} ||= $base->parameterize($param, $name)
$TYPE{$name} $base->parameterize($param, $name)
Truth table100%3/3
A ||= B
A= $TYPE{$name}B= $base->parameterize($param, $name)
ABresult
1X1
011
000
295 }
296  
297 22 ▶sub _find_or_create_union_type{
Subroutine _find_or_create_union_type: called CC=4 SCAR=14.0
298 22 ▶ return if grep{ not defined } @_; # all things must be defined
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} @_ 0 22 22
299 my @types = sort
300 22 ▶ map{ $_->{type_constraints} ? @{$_->{type_constraints}} : $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
$_->{'type_constraints'} ? : 2 46 48
301  
302 22 my $name = join '|', @types;
303  
304 # UnionType
305 22 ▶ $TYPE{$name} ||= Mouse::Meta::TypeConstraint->new(
Condition66%2/3
$TYPE{$name} ||= "Mouse::Meta::TypeConstraint"->new("name", $name, "type_constraints", \@types)
l!l&&r!l&&!r
4180
MC/DC0%0/2
$TYPE{$name} ||= "Mouse::Meta::TypeConstraint"->new("name", $name, "type_constraints", \@types)
$TYPE{$name} "Mouse::Meta::TypeConstraint"->new("name", $name, "type_constraints", \@types)
Truth table66%2/3
A ||= B
A= $TYPE{$name}B= "Mouse::Meta::TypeConstraint"->new("name", $name, "type_constraints", \@types)
ABresult
1X1
011
000
306 name => $name,
307 type_constraints => \@types,
308 );
309 }
310  
311 # The type parser
312  
313 # param : '[' type ']' | NOTHING
314 128 ▶sub _parse_param {
Subroutine _parse_param: called CC=3 SCAR=11.2
315 128 my($c) = @_;
316  
317 128 ▶ if($c->{spec} =~ s/^\[//){
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"spec"} =~ s/^\[//) 44 84 128
318 44 my $type = _parse_type($c, 1);
319  
320 44 ▶ if($c->{spec} =~ s/^\]//){
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"spec"} =~ s/^\]//) 44 0 44
321 44 return $type;
322 }
323 0 Carp::croak("Syntax error in type: missing right square bracket in '$c->{orig}'");
324 }
325  
326 84 return undef;
327 }
328  
329 # name : [\w.:]+
330 128 ▶sub _parse_name {
Subroutine _parse_name: called CC=2 SCAR=7.6
331 128 my($c, $create) = @_;
332  
333 128 ▶ if($c->{spec} =~ s/\A ([\w.:]+) //xms){
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"spec"} =~ s/\A ([\w.:]+) //msx) 128 0 128
334 128 return _find_or_create_regular_type($1, $create);
335 }
336 0 Carp::croak("Syntax error in type: expect type name near '$c->{spec}' in '$c->{orig}'");
337 }
338  
339 # single_type : name param
340 128 ▶sub _parse_single_type {
Subroutine _parse_single_type: called CC=4 SCAR=14.0
341 128 my($c, $create) = @_;
342  
343 128 my $type = _parse_name($c, $create);
344 128 my $param = _parse_param($c);
345  
346 128 ▶ if(defined $type){
Branch: 2 branches
BranchTrueFalseTotal
if (defined $type) { } 118 10 128
elsif (defined $param) { } 0 10 10
347 118 ▶ if(defined $param){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $param) { } 44 74 118
348 44 return _find_or_create_parameterized_type($type, $param);
349 }
350 else {
351 74 return $type;
352 }
353 }
354 elsif(defined $param){
355 0 Carp::croak("Undefined type with parameter [$param] in '$c->{orig}'");
356 }
357 else{
358 10 return undef;
359 }
360 }
361  
362 # type : single_type ('|' single_type)*
363 108 ▶sub _parse_type {
Subroutine _parse_type: called CC=4 SCAR=13.9
364 108 my($c, $create) = @_;
365  
366 108 my $type = _parse_single_type($c, $create);
367 107 ▶ if($c->{spec}){ # can be an union type
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"spec"}) 58 49 107
368 58 my @types;
369 58 ▶ while($c->{spec} =~ s/^\|//){
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"spec"} =~ s/^\|//) 20 58 78
370 20 push @types, _parse_single_type($c, $create);
371 }
372 58 ▶ if(@types){
Branch: 1 branch
BranchTrueFalseTotal
if (@types) 16 42 58
373 16 return _find_or_create_union_type($type, @types);
374 }
375 }
376 91 return $type;
377 }
378  
379  
380 975 ▶sub find_type_constraint {
Subroutine find_type_constraint: called CC=3 SCAR=11.0
Pod documented
381 975 my($spec) = @_;
382 975 ▶ return $spec if Mouse::Util::is_a_type_constraint($spec) or not defined $spec;
Branch: 1 branch
BranchTrueFalseTotal
if Mouse::Util::is_a_type_constraint($spec) or not defined $spec 1 974 975
Condition66%2/3
Mouse::Util::is_a_type_constraint($spec) or not defined $spec
l!l&&r!l&&!r
10974
MC/DC50%1/2
Mouse::Util::is_a_type_constraint($spec) or not defined $spec
Mouse::Util::is_a_type_constraint($spec) not defined $spec
Truth table66%2/3
A or not(B)
A= Mouse::Util::is_a_type_constraint($spec)B= not defined $spec
ABresult
1X1
011
000
383  
384 974 $spec =~ s/\s+//g;
385 974 return $TYPE{$spec};
386 }
387  
388 2 ▶sub register_type_constraint {
Subroutine register_type_constraint: called CC=2 SCAR=7.1
Pod undocumented
389 2 my($constraint) = @_;
390 2 ▶ Carp::croak("No type supplied / type is not a valid type constraint")
Branch: 1 branch
BranchTrueFalseTotal
unless Mouse::Util::is_a_type_constraint($constraint) 0 2 2
391 unless Mouse::Util::is_a_type_constraint($constraint);
392 2 return $TYPE{$constraint->name} = $constraint;
393 }
394  
395 1257 ▶sub find_or_parse_type_constraint {
Subroutine find_or_parse_type_constraint: called CC=5 SCAR=16.3
Pod undocumented
396 1257 my($spec) = @_;
397 1257 ▶ return $spec if Mouse::Util::is_a_type_constraint($spec) or not defined $spec;
Branch: 1 branch
BranchTrueFalseTotal
if Mouse::Util::is_a_type_constraint($spec) or not defined $spec 18 1239 1257
Condition66%2/3
Mouse::Util::is_a_type_constraint($spec) or not defined $spec
l!l&&r!l&&!r
1801239
MC/DC50%1/2
Mouse::Util::is_a_type_constraint($spec) or not defined $spec
Mouse::Util::is_a_type_constraint($spec) not defined $spec
Truth table66%2/3
A or not(B)
A= Mouse::Util::is_a_type_constraint($spec)B= not defined $spec
ABresult
1X1
011
000
398  
399 1239 $spec =~ tr/ \t\r\n//d;
400  
401 1239 my $tc = $TYPE{$spec};
402 1239 ▶ if(defined $tc) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tc) 1175 64 1239
403 1175 return $tc;
404 }
405  
406 64 my %context = (
407 spec => $spec,
408 orig => $spec,
409 );
410 64 $tc = _parse_type(\%context);
411  
412 63 ▶ if($context{spec}){
Branch: 1 branch
BranchTrueFalseTotal
if ($context{"spec"}) 0 63 63
413 0 Carp::croak("Syntax error: extra elements '$context{spec}' in '$context{orig}'");
414 }
415  
416 63 return $TYPE{$spec} = $tc;
417 }
418  
419 5 ▶sub find_or_create_does_type_constraint{
Subroutine find_or_create_does_type_constraint: called CC=2 SCAR=7.2
Pod undocumented
420 # XXX: Moose does not register a new role_type, but Mouse does.
421 5 my $tc = find_or_parse_type_constraint(@_);
422 5 ▶ return defined($tc) ? $tc : role_type(@_);
Branch: 1 branch
BranchTrueFalseTotal
defined $tc ? : 5 0 5
423 }
424  
425 1202 ▶sub find_or_create_isa_type_constraint {
Subroutine find_or_create_isa_type_constraint: called CC=2 SCAR=6.9
Pod undocumented
426 # XXX: Moose does not register a new class_type, but Mouse does.
427 1202 my $tc = find_or_parse_type_constraint(@_);
428 1201 ▶ return defined($tc) ? $tc : class_type(@_);
Branch: 1 branch
BranchTrueFalseTotal
defined $tc ? : 1192 9 1201
429 }
430  
431 286 1;
432 __END__
« blib/lib/Mouse/Meta/Method/Delegation.pm ↑ Summary blib/lib/Mouse/Meta/Class.pm »