blib/lib/Moose/Util/TypeConstraints.pm

filter: Statementstmt 97.4% 311 / 319 Branchbran 96.3% 106 / 110 Conditioncond 72.4% 50 / 69 MC/DCmcdc 46.5% 20 / 43 Subroutinesub 97.0% 66 / 68 Podpod 97.2% 35 / 36 totaltotal 91.1% 588 / 645 CC 82 SCAR 15.3
CC
82
Cov
94%
_create_type_constraint
12.0
match_on_type
10.0
create_class_type_constraint
7.1
CRAP 4.6
« blib/lib/Moose/Exception.pm ↑ Summary blib/lib/Class/MOP/Method/Wrapped.pm »
1 package Moose::Util::TypeConstraints;
2 398 our $VERSION = '2.4001';
3  
4 398 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 398 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 398 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 398 ▶use Moose::Deprecated;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 ## --------------------------------------------------------
10 # Prototyped subs must be predeclared because we have a
11 # circular dependency with Moose::Meta::Attribute et. al.
12 # so in case of us being use'd first the predeclaration
13 # ensures the prototypes are in scope when consumers are
14 # compiled.
15  
16 # dah sugah!
17 sub where (&);
18 sub via (&);
19 sub message (&);
20 sub inline_as (&);
21  
22 ## --------------------------------------------------------
23  
24 398 ▶use Moose::Meta::TypeConstraint;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 398 ▶use Moose::Meta::TypeConstraint::Union;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 398 ▶use Moose::Meta::TypeConstraint::Parameterized;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 398 ▶use Moose::Meta::TypeConstraint::Parameterizable;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 398 ▶use Moose::Meta::TypeConstraint::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 398 ▶use Moose::Meta::TypeConstraint::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 398 ▶use Moose::Meta::TypeConstraint::Enum;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 398 ▶use Moose::Meta::TypeConstraint::DuckType;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 398 ▶use Moose::Meta::TypeCoercion;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 398 ▶use Moose::Meta::TypeCoercion::Union;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 398 ▶use Moose::Meta::TypeConstraint::Registry;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 398 ▶use Moose::Util 'throw_exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 398 Moose::Exporter->setup_import_methods(
39 as_is => [
40 qw(
41 type subtype class_type role_type maybe_type duck_type
42 as where message inline_as
43 coerce from via
44 enum union
45 find_type_constraint
46 register_type_constraint
47 match_on_type )
48 ],
49 );
50  
51 ## --------------------------------------------------------
52 ## type registry and some useful functions for it
53 ## --------------------------------------------------------
54  
55 398 my $REGISTRY = Moose::Meta::TypeConstraint::Registry->new;
56  
57 4 ▶sub get_type_constraint_registry {$REGISTRY}
Subroutine get_type_constraint_registry: called CC=1 SCAR=0.0
Pod documented
58 398 ▶sub list_all_type_constraints { keys %{ $REGISTRY->type_constraints } }
Subroutine list_all_type_constraints: called CC=1 SCAR=0.0
Pod documented
59  
60 5 ▶sub export_type_constraints_as_functions {
Subroutine export_type_constraints_as_functions: called CC=2 SCAR=6.9
Pod documented
61 5 my $pkg = caller();
62 398 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
63 5 foreach my $constraint ( keys %{ $REGISTRY->type_constraints } ) {
64 120 my $tc = $REGISTRY->get_type_constraint($constraint)
65 ->_compiled_type_constraint;
66 120 *{"${pkg}::${constraint}"}
67 120 ▶ = sub { $tc->( $_[0] ) ? 1 : undef }; # the undef is for compat
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&$tc($_[0]) ? : 86 55 141
68 }
69 }
70  
71 66 ▶sub create_type_constraint_union {
Subroutine create_type_constraint_union: called CC=1 SCAR=0.0
Pod documented
72 66 _create_type_constraint_union(\@_);
73 }
74  
75 3 ▶sub create_named_type_constraint_union {
Subroutine create_named_type_constraint_union: called CC=1 SCAR=0.0
Pod documented
76 3 my $name = shift;
77 3 _create_type_constraint_union($name, \@_);
78 }
79  
80 69 ▶sub _create_type_constraint_union {
Subroutine _create_type_constraint_union: called CC=7 SCAR=19.5
81 69 my $name;
82 69 ▶ $name = shift if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 3 66 69
83 69 my @tcs = @{ shift() };
84  
85 69 my @type_constraint_names;
86  
87 69 ▶ if ( scalar @tcs == 1 && _detect_type_constraint_union( $tcs[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @tcs == 1 and _detect_type_constraint_union($tcs[0])) { } 62 7 69
Condition66%2/3
scalar @tcs == 1 and _detect_type_constraint_union($tcs[0])
!ll&&!rl&&r
7062
MC/DC50%1/2
scalar @tcs == 1 and _detect_type_constraint_union($tcs[0])
scalar @tcs == 1 _detect_type_constraint_union($tcs[0])
Truth table66%2/3
A and B
A= scalar @tcs == 1B= _detect_type_constraint_union($tcs[0])
ABresult
0X0
100
111
88 62 @type_constraint_names = _parse_type_constraint_union( $tcs[0] );
89 }
90 else {
91 7 @type_constraint_names = @tcs;
92 }
93  
94 68 ▶ ( scalar @type_constraint_names >= 2 )
Branch: 1 branch
BranchTrueFalseTotal
scalar @type_constraint_names >= 2 or throw_exception("UnionTakesAtleastTwoTypeNames") 66 2 68
95 || throw_exception("UnionTakesAtleastTwoTypeNames");
96  
97 my @type_constraints = map {
98 66 ▶ find_or_parse_type_constraint($_)
Condition66%2/3
find_or_parse_type_constraint($_) || throw_exception('CouldNotLocateTypeConstraintForUnion', 'type_name', $_)
l!l&&r!l&&!r
13301
MC/DC0%0/2
find_or_parse_type_constraint($_) || throw_exception('CouldNotLocateTypeConstraintForUnion', 'type_name', $_)
find_or_parse_type_constraint($_) throw_exception('CouldNotLocateTypeConstraintForUnion', 'type_name', $_)
Truth table33%1/3
A || B
A= find_or_parse_type_constraint($_)B= throw_exception('CouldNotLocateTypeConstraintForUnion', 'type_name', $_)
ABresult
1X1
011
000
99 || throw_exception( CouldNotLocateTypeConstraintForUnion => type_name => $_ );
100 } @type_constraint_names;
101  
102 65 my %options = (
103 type_constraints => \@type_constraints
104 );
105 65 ▶ $options{name} = $name if defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 2 63 65
106  
107 65 return Moose::Meta::TypeConstraint::Union->new(%options);
108 }
109  
110  
111 134 ▶sub create_parameterized_type_constraint {
Subroutine create_parameterized_type_constraint: called CC=4 SCAR=13.9
Pod documented
112 134 my $type_constraint_name = shift;
113 134 my ( $base_type, $type_parameter )
114 = _parse_parameterized_type_constraint($type_constraint_name);
115  
116 134 ▶ ( defined $base_type && defined $type_parameter )
Branch: 1 branch
BranchTrueFalseTotal
defined $base_type and defined $type_parameter or throw_exception("InvalidTypeGivenToCreateParameterizedTypeConstraint", "type_name", $type_constraint_name) 133 1 134
Condition66%2/3
defined $base_type and defined $type_parameter
!ll&&!rl&&r
01133
MC/DC50%1/2
defined $base_type and defined $type_parameter
defined $base_type defined $type_parameter
Truth table66%2/3
A and B
A= defined $base_typeB= defined $type_parameter
ABresult
0X0
100
111
117 || throw_exception( InvalidTypeGivenToCreateParameterizedTypeConstraint => type_name => $type_constraint_name );
118  
119 133 ▶ if ( $REGISTRY->has_type_constraint($base_type) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($REGISTRY->has_type_constraint($base_type)) { } 132 1 133
120 132 my $base_type_tc = $REGISTRY->get_type_constraint($base_type);
121 132 return _create_parameterized_type_constraint(
122 $base_type_tc,
123 $type_parameter
124 );
125 }
126 else {
127 1 throw_exception( InvalidBaseTypeGivenToCreateParameterizedTypeConstraint => type_name => $base_type );
128 }
129 }
130  
131 132 ▶sub _create_parameterized_type_constraint {
Subroutine _create_parameterized_type_constraint: called CC=2 SCAR=6.9
132 132 my ( $base_type_tc, $type_parameter ) = @_;
133 132 ▶ if ( $base_type_tc->can('parameterize') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base_type_tc->can('parameterize')) { } 129 3 132
134 129 return $base_type_tc->parameterize($type_parameter);
135 }
136 else {
137 3 return Moose::Meta::TypeConstraint::Parameterized->new(
138 name => $base_type_tc->name . '[' . $type_parameter . ']',
139 parent => $base_type_tc,
140 type_parameter =>
141 find_or_create_isa_type_constraint($type_parameter),
142 );
143 }
144 }
145  
146 #should we also support optimized checks?
147 1761 ▶sub create_class_type_constraint {
Subroutine create_class_type_constraint: called CC=7 SCAR=19.6
Pod documented
148 1761 my ( $class, $options ) = @_;
149  
150 # too early for this check
151 #find_type_constraint("ClassName")->check($class)
152 # || __PACKAGE__->_throw_error("Can't create a class type constraint because '$class' is not a class name");
153  
154 1761 ▶ my $pkg_defined_in = $options->{package_defined_in} || scalar( caller(1) );
Condition100%2/2
$options->{'package_defined_in'} || scalar caller 1
l!l
2541507
MC/DC100%1/1
$options->{'package_defined_in'} || scalar caller 1
$options->{'package_defined_in'}
Truth table100%2/2
A
A= $options->{'package_defined_in'}
Aresult
11
00
155  
156 1761 ▶ if (my $type = $REGISTRY->get_type_constraint($class)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = $REGISTRY->get_type_constraint($class)) 9 1752 1761
157 9 ▶ if (!($type->isa('Moose::Meta::TypeConstraint::Class') && $type->class eq $class)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $type->isa('Moose::Meta::TypeConstraint::Class') && $type->class eq $class) { } 1 8 9
Condition66%2/3
$type->isa('Moose::Meta::TypeConstraint::Class') && $type->class eq $class
!ll&&!rl&&r
108
MC/DC50%1/2
$type->isa('Moose::Meta::TypeConstraint::Class') && $type->class eq $class
$type->isa('Moose::Meta::TypeConstraint::Class') $type->class eq $class
Truth table66%2/3
A && B
A= $type->isa('Moose::Meta::TypeConstraint::Class')B= $type->class eq $class
ABresult
0X0
100
111
158 1 throw_exception( TypeConstraintIsAlreadyCreated => package_defined_in => $pkg_defined_in,
159 type_name => $type->name,
160 );
161 }
162 else {
163 8 return $type;
164 }
165 }
166  
167 my %options = (
168 class => $class,
169 name => $class,
170 package_defined_in => $pkg_defined_in,
171 1752 ▶ %{ $options || {} }, # overrides options from above
Condition50%1/2
$options || {}
l!l
17520
MC/DC0%0/1
$options || {}
$options
Truth table50%1/2
A
A= $options
Aresult
11
00
172 );
173  
174 1752 ▶ $options{name} ||= "__ANON__";
Condition50%1/2
$options{"name"} ||= "__ANON__"
l!l
17520
MC/DC0%0/1
$options{"name"} ||= "__ANON__"
$options{"name"}
Truth table50%1/2
A
A= $options{"name"}
Aresult
11
00
175  
176 1752 my $tc = Moose::Meta::TypeConstraint::Class->new(%options);
177 1752 $REGISTRY->add_type_constraint($tc);
178 1752 return $tc;
179 }
180  
181 1288 ▶sub create_role_type_constraint {
Subroutine create_role_type_constraint: called CC=7 SCAR=19.5
Pod documented
182 1288 my ( $role, $options ) = @_;
183  
184 # too early for this check
185 #find_type_constraint("ClassName")->check($class)
186 # || __PACKAGE__->_throw_error("Can't create a class type constraint because '$class' is not a class name");
187  
188 1288 ▶ my $pkg_defined_in = $options->{package_defined_in} || scalar( caller(1) );
Condition100%2/2
$options->{'package_defined_in'} || scalar caller 1
l!l
41284
MC/DC100%1/1
$options->{'package_defined_in'} || scalar caller 1
$options->{'package_defined_in'}
Truth table100%2/2
A
A= $options->{'package_defined_in'}
Aresult
11
00
189  
190 1288 ▶ if (my $type = $REGISTRY->get_type_constraint($role)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = $REGISTRY->get_type_constraint($role)) 3 1285 1288
191 3 ▶ if (!($type->isa('Moose::Meta::TypeConstraint::Role') && $type->role eq $role)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $type->isa('Moose::Meta::TypeConstraint::Role') && $type->role eq $role) { } 1 2 3
Condition66%2/3
$type->isa('Moose::Meta::TypeConstraint::Role') && $type->role eq $role
!ll&&!rl&&r
102
MC/DC50%1/2
$type->isa('Moose::Meta::TypeConstraint::Role') && $type->role eq $role
$type->isa('Moose::Meta::TypeConstraint::Role') $type->role eq $role
Truth table66%2/3
A && B
A= $type->isa('Moose::Meta::TypeConstraint::Role')B= $type->role eq $role
ABresult
0X0
100
111
192 1 throw_exception( TypeConstraintIsAlreadyCreated => type_name => $type->name,
193 package_defined_in => $pkg_defined_in
194 );
195 }
196 else {
197 2 return $type;
198 }
199 }
200  
201 my %options = (
202 role => $role,
203 name => $role,
204 package_defined_in => $pkg_defined_in,
205 1285 ▶ %{ $options || {} },
Condition50%1/2
$options || {}
l!l
12850
MC/DC0%0/1
$options || {}
$options
Truth table50%1/2
A
A= $options
Aresult
11
00
206 );
207  
208 1285 ▶ $options{name} ||= "__ANON__";
Condition100%2/2
$options{"name"} ||= "__ANON__"
l!l
12841
MC/DC100%1/1
$options{"name"} ||= "__ANON__"
$options{"name"}
Truth table100%2/2
A
A= $options{"name"}
Aresult
11
00
209  
210 1285 my $tc = Moose::Meta::TypeConstraint::Role->new(%options);
211 1285 $REGISTRY->add_type_constraint($tc);
212 1285 return $tc;
213 }
214  
215 216 ▶sub find_or_create_type_constraint {
Subroutine find_or_create_type_constraint: called CC=3 SCAR=16.0
Pod undocumented
216 216 my ( $type_constraint_name, $options_for_anon_type ) = @_;
217  
218 216 ▶ if ( my $constraint
Branch: 2 branches
BranchTrueFalseTotal
if (my $constraint = find_or_parse_type_constraint($type_constraint_name)) { } 216 0 216
elsif (defined $options_for_anon_type) { } 0 0 0
219 = find_or_parse_type_constraint($type_constraint_name) ) {
220 216 return $constraint;
221 }
222 elsif ( defined $options_for_anon_type ) {
223  
224 # NOTE:
225 # if there is no $options_for_anon_type
226 # specified, then we assume they don't
227 # want to create one, and return nothing.
228  
229 # otherwise assume that we should create
230 # an ANON type with the $options_for_anon_type
231 # options which can be passed in. It should
232 # be noted that these don't get registered
233 # so we need to return it.
234 # - SL
235 return Moose::Meta::TypeConstraint->new(
236 name => '__ANON__',
237 0 %{$options_for_anon_type}
238 );
239 }
240  
241 0 return;
242 }
243  
244 8558 ▶sub find_or_create_isa_type_constraint {
Subroutine find_or_create_isa_type_constraint: called CC=2 SCAR=6.9
Pod documented
245 8558 my ($type_constraint_name, $options) = @_;
246 8558 ▶ find_or_parse_type_constraint($type_constraint_name)
Branch: 1 branch
BranchTrueFalseTotal
find_or_parse_type_constraint($type_constraint_name) or create_class_type_constraint($type_constraint_name, $options) 8280 276 8556
247 || create_class_type_constraint($type_constraint_name, $options);
248 }
249  
250 8 ▶sub find_or_create_does_type_constraint {
Subroutine find_or_create_does_type_constraint: called CC=2 SCAR=6.9
Pod documented
251 8 my ($type_constraint_name, $options) = @_;
252 8 ▶ find_or_parse_type_constraint($type_constraint_name)
Branch: 1 branch
BranchTrueFalseTotal
find_or_parse_type_constraint($type_constraint_name) or create_role_type_constraint($type_constraint_name, $options) 4 4 8
253 || create_role_type_constraint($type_constraint_name, $options);
254 }
255  
256 9388 ▶sub find_or_parse_type_constraint {
Subroutine find_or_parse_type_constraint: called CC=4 SCAR=13.9
Pod documented
257 9388 my $type_constraint_name = normalize_type_constraint_name(shift);
258 9388 my $constraint;
259  
260 9388 ▶ if ( $constraint = find_type_constraint($type_constraint_name) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($constraint = find_type_constraint($type_constraint_name)) { } 8920 468 9388
elsif (_detect_type_constraint_union($type_constraint_name)) { } 57 411 468
elsif (_detect_parameterized_type_constraint($type_constraint_name)) { } 127 284 411
261 8920 return $constraint;
262 }
263 elsif ( _detect_type_constraint_union($type_constraint_name) ) {
264 57 $constraint = create_type_constraint_union($type_constraint_name);
265 }
266 elsif ( _detect_parameterized_type_constraint($type_constraint_name) ) {
267 127 $constraint
268 = create_parameterized_type_constraint($type_constraint_name);
269 }
270 else {
271 284 return;
272 }
273  
274 182 $REGISTRY->add_type_constraint($constraint);
275 182 return $constraint;
276 }
277  
278 9388 ▶sub normalize_type_constraint_name {
Subroutine normalize_type_constraint_name: called CC=1 SCAR=0.0
Pod documented
279 9388 my $type_constraint_name = shift;
280 9388 $type_constraint_name =~ s/\s//g;
281 9388 return $type_constraint_name;
282 }
283  
284 0 ▶sub _confess {
Subroutine _confess: not called CC=1 SCAR=6.9
285 0 my $error = shift;
286  
287 0 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
288 0 Carp::confess($error);
289 }
290  
291 ## --------------------------------------------------------
292 ## exported functions ...
293 ## --------------------------------------------------------
294  
295 20302 ▶sub find_type_constraint {
Subroutine find_type_constraint: called CC=4 SCAR=13.9
Pod documented
296 20302 my $type = shift;
297  
298 20302 ▶ if ( blessed $type and $type->isa("Moose::Meta::TypeConstraint") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($type) and $type->isa('Moose::Meta::TypeConstraint')) { } 2192 18110 20302
Condition66%2/3
builtin::blessed($type) and $type->isa("Moose::Meta::TypeConstraint")
!ll&&!rl&&r
1811002192
MC/DC50%1/2
builtin::blessed($type) and $type->isa("Moose::Meta::TypeConstraint")
builtin::blessed($type) $type->isa("Moose::Meta::TypeConstraint")
Truth table66%2/3
A and B
A= builtin::blessed($type)B= $type->isa("Moose::Meta::TypeConstraint")
ABresult
0X0
100
111
299 2192 return $type;
300 }
301 else {
302 18110 ▶ return unless $REGISTRY->has_type_constraint($type);
Branch: 1 branch
BranchTrueFalseTotal
unless $REGISTRY->has_type_constraint($type) 3241 14869 18110
303 14869 return $REGISTRY->get_type_constraint($type);
304 }
305 }
306  
307 45 ▶sub register_type_constraint {
Subroutine register_type_constraint: called CC=2 SCAR=6.9
Pod documented
308 45 my $constraint = shift;
309 45 ▶ throw_exception( CannotRegisterUnnamedTypeConstraint => type => $constraint )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $constraint->name 1 44 45
310 unless defined $constraint->name;
311 44 $REGISTRY->add_type_constraint($constraint);
312 44 return $constraint;
313 }
314  
315 # type constructors
316  
317 412 ▶sub type {
Subroutine type: called CC=1 SCAR=0.0
Pod documented
318 412 my $name = shift;
319  
320 412 my %p = map { %{$_} } @_;
321  
322 return _create_type_constraint(
323 $name, undef, $p{where}, $p{message},
324 $p{inline_as},
325 412 );
326 }
327  
328 6492 ▶sub subtype {
Subroutine subtype: called CC=6 SCAR=17.9
Pod documented
329 6492 ▶ if ( @_ == 1 && !ref $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and not ref $_[0]) 2 6490 6492
Condition100%3/3
@_ == 1 and not ref $_[0]
!ll&&!rl&&r
648462
MC/DC100%2/2
@_ == 1 and not ref $_[0]
@_ == 1 not ref $_[0]
Truth table100%3/3
A and not(B)
A= @_ == 1B= not ref $_[0]
ABresult
0X0
100
111
330 2 throw_exception( NoParentGivenToSubtype => name => $_[0] );
331 }
332  
333 # The blessed check is mostly to accommodate MooseX::Types, which
334 # uses an object which overloads stringification as a type name.
335 6490 ▶ my $name = ref $_[0] && !blessed $_[0] ? undef : shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] && !builtin::blessed($_[0]) ? : 16 6474 6490
Condition66%2/3
ref $_[0] and not builtin::blessed($_[0])
!ll&&!rl&&r
6474016
MC/DC50%1/2
ref $_[0] and not builtin::blessed($_[0])
ref $_[0] not builtin::blessed($_[0])
Truth table66%2/3
A and not(B)
A= ref $_[0]B= not builtin::blessed($_[0])
ABresult
0X0
100
111
336  
337 6490 my %p = map { %{$_} } @_;
338  
339 # subtype Str => where { ... };
340 6490 ▶ if ( !exists $p{as} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $p{"as"}) 6 6484 6490
341 6 $p{as} = $name;
342 6 $name = undef;
343 }
344  
345 return _create_type_constraint(
346 $name, $p{as}, $p{where}, $p{message},
347 $p{inline_as},
348 6490 );
349 }
350  
351 1485 ▶sub class_type {
Subroutine class_type: called CC=1 SCAR=0.0
Pod documented
352 1485 create_class_type_constraint(@_);
353 }
354  
355 1284 ▶sub role_type ($;$) {
Subroutine role_type: called CC=1 SCAR=0.0
Pod documented
356 1284 create_role_type_constraint(@_);
357 }
358  
359 1 ▶sub maybe_type {
Subroutine maybe_type: called CC=1 SCAR=0.0
Pod documented
360 1 my ($type_parameter) = @_;
361  
362 1 register_type_constraint(
363 $REGISTRY->get_type_constraint('Maybe')->parameterize($type_parameter)
364 );
365 }
366  
367 25 ▶sub duck_type {
Subroutine duck_type: called CC=5 SCAR=16.2
Pod documented
368 25 my ( $type_name, @methods ) = @_;
369 25 ▶ if ( ref $type_name eq 'ARRAY' && !@methods ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $type_name eq "ARRAY" and not @methods) 1 24 25
Condition66%2/3
ref $type_name eq "ARRAY" and not @methods
!ll&&!rl&&r
2401
MC/DC50%1/2
ref $type_name eq "ARRAY" and not @methods
ref $type_name eq "ARRAY" not @methods
Truth table66%2/3
A and not(B)
A= ref $type_name eq "ARRAY"B= not @methods
ABresult
0X0
100
111
370 1 @methods = ($type_name);
371 1 $type_name = undef;
372 }
373 25 ▶ if ( @methods == 1 && ref $methods[0] eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@methods == 1 and ref $methods[0] eq 'ARRAY') { } 24 1 25
Condition66%2/3
@methods == 1 and ref $methods[0] eq "ARRAY"
!ll&&!rl&&r
1024
MC/DC50%1/2
@methods == 1 and ref $methods[0] eq "ARRAY"
@methods == 1 ref $methods[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @methods == 1B= ref $methods[0] eq "ARRAY"
ABresult
0X0
100
111
374 24 @methods = @{ $methods[0] };
375 }
376 else {
377 1 Moose::Deprecated::deprecated(
378 feature => 'non-arrayref form of duck_type',
379 message => "Passing a list of values to duck_type is deprecated. "
380 . "The method names should be wrapped in an arrayref.",
381 );
382 }
383  
384 25 register_type_constraint(
385 create_duck_type_constraint(
386 $type_name,
387 \@methods,
388 )
389 );
390 }
391  
392 44 ▶sub coerce {
Subroutine coerce: called CC=1 SCAR=0.0
Pod documented
393 44 my ( $type_name, @coercion_map ) = @_;
394 44 _install_type_coercions( $type_name, \@coercion_map );
395 }
396  
397 # The trick of returning @_ lets us avoid having to specify a
398 # prototype. Perl will parse this:
399 #
400 # subtype 'Foo'
401 # => as 'Str'
402 # => where { ... }
403 #
404 # as this:
405 #
406 # subtype( 'Foo', as( 'Str', where { ... } ) );
407 #
408 # If as() returns all its extra arguments, this just works, and
409 # preserves backwards compatibility.
410 6480 ▶sub as { +{ as => shift }, @_ }
Subroutine as: called CC=1 SCAR=0.0
Pod documented
411 6454 ▶sub where (&) { +{ where => $_[0] } }
Subroutine where: called CC=1 SCAR=0.0
Pod documented
412 12 ▶sub message (&) { +{ message => $_[0] } }
Subroutine message: called CC=1 SCAR=0.0
Pod documented
413 6767 ▶sub inline_as (&) { +{ inline_as => $_[0] } }
Subroutine inline_as: called CC=1 SCAR=0.0
Pod documented
414  
415 47 ▶sub from { @_ }
Subroutine from: called CC=1 SCAR=0.0
Pod documented
416 46 ▶sub via (&) { $_[0] }
Subroutine via: called CC=1 SCAR=0.0
Pod documented
417  
418 16 ▶sub enum {
Subroutine enum: called CC=5 SCAR=16.1
Pod documented
419 16 my ( $type_name, @values ) = @_;
420  
421 # NOTE:
422 # if only an array-ref is passed then
423 # you get an anon-enum
424 # - SL
425 16 ▶ if ( ref $type_name eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $type_name eq "ARRAY") 7 9 16
426 7 ▶ @values == 0
Branch: 1 branch
BranchTrueFalseTotal
@values == 0 or throw_exception("EnumCalledWithAnArrayRefAndAdditionalArgs", "array", $type_name, "args", \@values) 5 2 7
427 || throw_exception( EnumCalledWithAnArrayRefAndAdditionalArgs => array => $type_name,
428 args => \@values
429 );
430 5 @values = ($type_name);
431 5 $type_name = undef;
432 }
433 14 ▶ if ( @values == 1 && ref $values[0] eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@values == 1 and ref $values[0] eq 'ARRAY') { } 13 1 14
Condition66%2/3
@values == 1 and ref $values[0] eq "ARRAY"
!ll&&!rl&&r
1013
MC/DC50%1/2
@values == 1 and ref $values[0] eq "ARRAY"
@values == 1 ref $values[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @values == 1B= ref $values[0] eq "ARRAY"
ABresult
0X0
100
111
434 13 @values = @{ $values[0] };
435 }
436 else {
437 1 Moose::Deprecated::deprecated(
438 feature => 'non-arrayref form of enum',
439 message => "Passing a list of values to enum is deprecated. "
440 . "Enum values should be wrapped in an arrayref.",
441 );
442 }
443  
444 14 register_type_constraint(
445 create_enum_type_constraint(
446 $type_name,
447 \@values,
448 )
449 );
450 }
451  
452 6 ▶sub union {
Subroutine union: called CC=6 SCAR=17.9
Pod documented
453 6 my ( $type_name, @constraints ) = @_;
454 6 ▶ if ( ref $type_name eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $type_name eq "ARRAY") 3 3 6
455 3 ▶ @constraints == 0
Branch: 1 branch
BranchTrueFalseTotal
@constraints == 0 or throw_exception("UnionCalledWithAnArrayRefAndAdditionalArgs", "array", $type_name, "args", \@constraints) 2 1 3
456 || throw_exception( UnionCalledWithAnArrayRefAndAdditionalArgs => array => $type_name,
457 args => \@constraints
458 );
459 2 @constraints = @$type_name;
460 2 $type_name = undef;
461 }
462 5 ▶ if ( @constraints == 1 && ref $constraints[0] eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@constraints == 1 and ref $constraints[0] eq "ARRAY") 2 3 5
Condition100%3/3
@constraints == 1 and ref $constraints[0] eq "ARRAY"
!ll&&!rl&&r
212
MC/DC100%2/2
@constraints == 1 and ref $constraints[0] eq "ARRAY"
@constraints == 1 ref $constraints[0] eq "ARRAY"
Truth table100%3/3
A and B
A= @constraints == 1B= ref $constraints[0] eq "ARRAY"
ABresult
0X0
100
111
463 2 @constraints = @{ $constraints[0] };
464 }
465 5 ▶ if ( defined $type_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type_name) 3 2 5
466 3 return register_type_constraint(
467 create_named_type_constraint_union( $type_name, @constraints )
468 );
469 }
470 2 return create_type_constraint_union( @constraints );
471 }
472  
473 14 ▶sub create_enum_type_constraint {
Subroutine create_enum_type_constraint: called CC=2 SCAR=6.9
Pod documented
474 14 my ( $type_name, $values ) = @_;
475  
476 14 ▶ Moose::Meta::TypeConstraint::Enum->new(
Condition100%2/2
$type_name || '__ANON__'
l!l
95
MC/DC100%1/1
$type_name || '__ANON__'
$type_name
Truth table100%2/2
A
A= $type_name
Aresult
11
00
477 name => $type_name || '__ANON__',
478 values => $values,
479 );
480 }
481  
482 25 ▶sub create_duck_type_constraint {
Subroutine create_duck_type_constraint: called CC=2 SCAR=6.9
Pod documented
483 25 my ( $type_name, $methods ) = @_;
484  
485 25 ▶ Moose::Meta::TypeConstraint::DuckType->new(
Condition100%2/2
$type_name || '__ANON__'
l!l
241
MC/DC100%1/1
$type_name || '__ANON__'
$type_name
Truth table100%2/2
A
A= $type_name
Aresult
11
00
486 name => $type_name || '__ANON__',
487 methods => $methods,
488 );
489 }
490  
491 187 ▶sub match_on_type {
Subroutine match_on_type: called CC=10 SCAR=23.0
Pod documented
492 187 my ($to_match, @cases) = @_;
493 187 my $default;
494 187 ▶ if (@cases % 2 != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@cases % 2 != 0) 38 149 187
495 38 $default = pop @cases;
496 38 ▶ (ref $default eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
ref $default eq "CODE" or throw_exception("DefaultToMatchOnTypeMustBeCodeRef", "to_match", $to_match, "default_action", $default, "cases_to_be_matched", \@cases) 37 1 38
497 || throw_exception( DefaultToMatchOnTypeMustBeCodeRef => to_match => $to_match,
498 default_action => $default,
499 cases_to_be_matched => \@cases
500 );
501 }
502 186 ▶ while (@cases) {
Branch: 1 branch
BranchTrueFalseTotal
if (@cases) 421 4 425
503 421 my ($type, $action) = splice @cases, 0, 2;
504  
505 421 ▶ unless (blessed $type && $type->isa('Moose::Meta::TypeConstraint')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($type) and $type->isa("Moose::Meta::TypeConstraint")) 411 10 421
Condition66%2/3
builtin::blessed($type) and $type->isa("Moose::Meta::TypeConstraint")
!ll&&!rl&&r
411010
MC/DC50%1/2
builtin::blessed($type) and $type->isa("Moose::Meta::TypeConstraint")
builtin::blessed($type) $type->isa("Moose::Meta::TypeConstraint")
Truth table66%2/3
A and B
A= builtin::blessed($type)B= $type->isa("Moose::Meta::TypeConstraint")
ABresult
0X0
100
111
506 411 ▶ $type = find_or_parse_type_constraint($type)
Condition66%2/3
find_or_parse_type_constraint($type) || throw_exception('CannotFindTypeGivenToMatchOnType', 'type', $type, 'to_match', $to_match, 'action', $action)
l!l&&r!l&&!r
41010
MC/DC0%0/2
find_or_parse_type_constraint($type) || throw_exception('CannotFindTypeGivenToMatchOnType', 'type', $type, 'to_match', $to_match, 'action', $action)
find_or_parse_type_constraint($type) throw_exception('CannotFindTypeGivenToMatchOnType', 'type', $type, 'to_match', $to_match, 'action', $action)
Truth table33%1/3
A || B
A= find_or_parse_type_constraint($type)B= throw_exception('CannotFindTypeGivenToMatchOnType', 'type', $type, 'to_match', $to_match, 'action', $action)
ABresult
1X1
011
000
507 || throw_exception( CannotFindTypeGivenToMatchOnType => type => $type,
508 to_match => $to_match,
509 action => $action
510 );
511 }
512  
513 420 ▶ (ref $action eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
ref $action eq "CODE" or throw_exception("MatchActionMustBeACodeRef", "type_name", $type->name, "action", $action, "to_match", $to_match) 419 1 420
514 || throw_exception( MatchActionMustBeACodeRef => type_name => $type->name,
515 action => $action,
516 to_match => $to_match
517 );
518  
519 419 ▶ if ($type->check($to_match)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type->check($to_match)) 180 239 419
520 180 local $_ = $to_match;
521 180 return $action->($to_match);
522 }
523 }
524 4 ▶ (defined $default)
Branch: 1 branch
BranchTrueFalseTotal
defined $default or throw_exception("NoCasesMatched", "to_match", $to_match, "cases_to_be_matched", \@cases) 2 2 4
525 || throw_exception( NoCasesMatched => to_match => $to_match,
526 cases_to_be_matched => \@cases
527 );
528 {
529 2 local $_ = $to_match;
530 2 return $default->($to_match);
531 }
532 }
533  
534  
535 ## --------------------------------------------------------
536 ## desugaring functions ...
537 ## --------------------------------------------------------
538  
539 6902 ▶sub _create_type_constraint ($$$;$) {
Subroutine _create_type_constraint: called CC=12 SCAR=24.9
540 6902 my $name = shift;
541 6902 my $parent = shift;
542 6902 my $check = shift;
543 6902 my $message = shift;
544 6902 my $inlined = shift;
545  
546 6902 my $pkg_defined_in = scalar( caller(1) );
547  
548 6902 ▶ if ( defined $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) 6880 22 6902
549 6880 my $type = $REGISTRY->get_type_constraint($name);
550  
551 6880 ▶ ( $type->_package_defined_in eq $pkg_defined_in )
Branch: 1 branch
BranchTrueFalseTotal
if defined $type 10 6870 6880
Condition80%4/5
defined $type && ($type->_package_defined_in eq $pkg_defined_in || throw_exception('TypeConstraintIsAlreadyCreated', 'package_defined_in', $pkg_defined_in, 'type_name', $type->name))
!ll
687010
$type->_package_defined_in eq $pkg_defined_in or throw_exception("TypeConstraintIsAlreadyCreated", "package_defined_in", $pkg_defined_in, "type_name", $type->name)
l!l&&r!l&&!r
640
MC/DC0%0/3
defined $type && ($type->_package_defined_in eq $pkg_defined_in || throw_exception('TypeConstraintIsAlreadyCreated', 'package_defined_in', $pkg_defined_in, 'type_name', $type->name))
defined $type $type->_package_defined_in eq $pkg_defined_in throw_exception("TypeConstraintIsAlreadyCreated", "package_defined_in", $pkg_defined_in, "type_name", $type->name)
Truth table0%0/4
A && B or C
A= defined $typeB= $type->_package_defined_in eq $pkg_defined_inC= throw_exception("TypeConstraintIsAlreadyCreated", "package_defined_in", $pkg_defined_in, "type_name", $type->name)
ABCresult
0XX0
1000
11X1
1011
552 || throw_exception( TypeConstraintIsAlreadyCreated => package_defined_in => $pkg_defined_in,
553 type_name => $type->name,
554 )
555 if defined $type;
556  
557 6876 ▶ if( $name !~ /^[\w:\.]+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name =~ /^[\w:\.]+$/) 2 6874 6876
558 2 throw_exception( InvalidNameForType => name => $name );
559 }
560 }
561  
562 6896 ▶ my %opts = (
Branch: 3 branches
BranchTrueFalseTotal
$check ? : 6454 442 6896
$message ? : 9 6887 6896
$inlined ? : 6767 129 6896
563 name => $name,
564 package_defined_in => $pkg_defined_in,
565  
566 ( $check ? ( constraint => $check ) : () ),
567 ( $message ? ( message => $message ) : () ),
568 ( $inlined ? ( inlined => $inlined ) : () ),
569 );
570  
571 6896 my $constraint;
572 6896 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if (defined $parent and $parent = builtin::blessed($parent) ? $parent : find_or_create_isa_type_constraint($parent)) { } 6484 411 6895
builtin::blessed($parent) ? : 5 6480 6485
Condition66%2/3
defined $parent and $parent = builtin::blessed($parent) ? $parent : find_or_create_isa_type_constraint($parent)
!ll&&!rl&&r
41106485
MC/DC50%1/2
defined $parent and $parent = builtin::blessed($parent) ? $parent : find_or_create_isa_type_constraint($parent)
defined $parent $parent = builtin::blessed($parent) ? $parent : find_or_create_isa_type_constraint($parent)
Truth table66%2/3
A and B
A= defined $parentB= $parent = builtin::blessed($parent) ? $parent : find_or_create_isa_type_constraint($parent)
ABresult
0X0
100
111
573 defined $parent
574 and $parent
575 = blessed $parent
576 ? $parent
577 : find_or_create_isa_type_constraint($parent)
578 ) {
579 6484 $constraint = $parent->create_child_type(%opts);
580 }
581 else {
582 411 $constraint = Moose::Meta::TypeConstraint->new(%opts);
583 }
584  
585 6895 ▶ $REGISTRY->add_type_constraint($constraint)
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 6873 22 6895
586 if defined $name;
587  
588 6895 return $constraint;
589 }
590  
591 44 ▶sub _install_type_coercions ($$) {
Subroutine _install_type_coercions: called CC=3 SCAR=11.0
592 44 my ( $type_name, $coercion_map ) = @_;
593 44 my $type = find_type_constraint($type_name);
594 44 ▶ ( defined $type )
Branch: 1 branch
BranchTrueFalseTotal
defined $type or throw_exception("CannotFindType", "type_name", $type_name) 43 1 44
595 || throw_exception( CannotFindType => type_name => $type_name );
596  
597 43 ▶ if ( $type->has_coercion ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type->has_coercion) { } 5 38 43
598 5 $type->coercion->add_type_coercions(@$coercion_map);
599 }
600 else {
601 38 my $type_coercion = Moose::Meta::TypeCoercion->new(
602 type_coercion_map => $coercion_map,
603 type_constraint => $type
604 );
605 37 $type->coercion($type_coercion);
606 }
607 }
608  
609 ## --------------------------------------------------------
610 ## type notation parsing ...
611 ## --------------------------------------------------------
612  
613 {
614  
615 # All I have to say is mugwump++ cause I know
616 # do not even have enough regexp-fu to be able
617 # to have written this (I can only barely
618 # understand it as it is)
619 # - SL
620  
621 398 ▶ use re "eval";
Subroutine BEGIN: called CC=1 SCAR=0.0
622  
623 398 my $valid_chars = qr{[\w:\.]};
624 398 my $type_atom = qr{ (?>$valid_chars+) }x;
625 398 my $ws = qr{ (?>\s*) }x;
626 398 my $op_union = qr{ $ws \| $ws }x;
627  
628 398 my ($type, $type_capture_parts, $type_with_parameter, $union, $any);
629 398 if (Class::MOP::IS_RUNNING_ON_5_10) {
630 398 my $type_pattern
631 = q{ (?&type_atom) (?: \[ (?&ws) (?&any) (?&ws) \] )? };
632 398 my $type_capture_parts_pattern
633 = q{ ((?&type_atom)) (?: \[ (?&ws) ((?&any)) (?&ws) \] )? };
634 398 my $type_with_parameter_pattern
635 = q{ (?&type_atom) \[ (?&ws) (?&any) (?&ws) \] };
636 398 my $union_pattern
637 = q{ (?&type) (?> (?: (?&op_union) (?&type) )+ ) };
638 398 my $any_pattern
639 = q{ (?&type) | (?&union) };
640  
641 398 my $defines = qr{(?(DEFINE)
642 (?<valid_chars> $valid_chars)
643 (?<type_atom> $type_atom)
644 (?<ws> $ws)
645 (?<op_union> $op_union)
646 (?<type> $type_pattern)
647 (?<type_capture_parts> $type_capture_parts_pattern)
648 (?<type_with_parameter> $type_with_parameter_pattern)
649 (?<union> $union_pattern)
650 (?<any> $any_pattern)
651 )}x;
652  
653 398 $type = qr{ $type_pattern $defines }x;
654 398 $type_capture_parts = qr{ $type_capture_parts_pattern $defines }x;
655 398 $type_with_parameter = qr{ $type_with_parameter_pattern $defines }x;
656 398 $union = qr{ $union_pattern $defines }x;
657 398 $any = qr{ $any_pattern $defines }x;
658 }
659 else {
660 $type
661 = qr{ $type_atom (?: \[ $ws (??{$any}) $ws \] )? }x;
662 $type_capture_parts
663 = qr{ ($type_atom) (?: \[ $ws ((??{$any})) $ws \] )? }x;
664 $type_with_parameter
665 = qr{ $type_atom \[ $ws (??{$any}) $ws \] }x;
666 $union
667 = qr{ $type (?> (?: $op_union $type )+ ) }x;
668 $any
669 = qr{ $type | $union }x;
670 }
671  
672  
673 148 ▶ sub _parse_parameterized_type_constraint {
Subroutine _parse_parameterized_type_constraint: called CC=1 SCAR=0.0
674 398 ▶ { no warnings 'void'; $any; } # force capture of interpolated lexical
Subroutine BEGIN: called CC=1 SCAR=0.0
675 148 $_[0] =~ m{ $type_capture_parts }x;
676 148 return ( $1, $2 );
677 }
678  
679 426 ▶ sub _detect_parameterized_type_constraint {
Subroutine _detect_parameterized_type_constraint: called CC=1 SCAR=0.0
680 398 ▶ { no warnings 'void'; $any; } # force capture of interpolated lexical
Subroutine BEGIN: called CC=1 SCAR=0.0
681 426 $_[0] =~ m{ ^ $type_with_parameter $ }x;
682 }
683  
684 74 ▶ sub _parse_type_constraint_union {
Subroutine _parse_type_constraint_union: called CC=3 SCAR=11.0
685 398 ▶ { no warnings 'void'; $any; } # force capture of interpolated lexical
Subroutine BEGIN: called CC=1 SCAR=0.0
686 74 my $given = shift;
687 74 my @rv;
688 74 ▶ while ( $given =~ m{ \G (?: $op_union )? ($type) }gcx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($given =~ / \G (?: $op_union )? ($type) /cgx) 159 74 233
689 159 push @rv => $1;
690 }
691 74 ▶ ( pos($given) eq length($given) )
Branch: 1 branch
BranchTrueFalseTotal
pos $given eq length $given or throw_exception("CouldNotParseType", "type", $given, "position", pos $given) 73 1 74
692 || throw_exception( CouldNotParseType => type => $given,
693 position => pos($given)
694 );
695 73 @rv;
696 }
697  
698 545 ▶ sub _detect_type_constraint_union {
Subroutine _detect_type_constraint_union: called CC=1 SCAR=0.0
699 398 ▶ { no warnings 'void'; $any; } # force capture of interpolated lexical
Subroutine BEGIN: called CC=1 SCAR=0.0
700 545 $_[0] =~ m{^ $type $op_union $type ( $op_union .* )? $}x;
701 }
702 }
703  
704 ## --------------------------------------------------------
705 # define some basic built-in types
706 ## --------------------------------------------------------
707  
708 # By making these classes immutable before creating all the types in
709 # Moose::Util::TypeConstraints::Builtin , we avoid repeatedly calling the slow
710 # MOP-based accessors.
711 398 $_->make_immutable(
712 inline_constructor => 1,
713 constructor_name => "_new",
714  
715 # these are Class::MOP accessors, so they need inlining
716 inline_accessors => 1
717 398 ) for grep { $_->is_mutable }
718 3582 map { Class::MOP::class_of($_) }
719 qw(
720 Moose::Meta::TypeConstraint
721 Moose::Meta::TypeConstraint::Union
722 Moose::Meta::TypeConstraint::Parameterized
723 Moose::Meta::TypeConstraint::Parameterizable
724 Moose::Meta::TypeConstraint::Class
725 Moose::Meta::TypeConstraint::Role
726 Moose::Meta::TypeConstraint::Enum
727 Moose::Meta::TypeConstraint::DuckType
728 Moose::Meta::TypeConstraint::Registry
729 );
730  
731 398 require Moose::Util::TypeConstraints::Builtins;
732 398 Moose::Util::TypeConstraints::Builtins::define_builtins($REGISTRY);
733  
734 my @PARAMETERIZABLE_TYPES
735 398 = map { $REGISTRY->get_type_constraint($_) } qw[ScalarRef ArrayRef HashRef Maybe];
736  
737 145 ▶sub get_all_parameterizable_types {@PARAMETERIZABLE_TYPES}
Subroutine get_all_parameterizable_types: called CC=1 SCAR=0.0
Pod documented
738  
739 1 ▶sub add_parameterizable_type {
Subroutine add_parameterizable_type: called CC=3 SCAR=14.2
Pod documented
740 1 my $type = shift;
741 1 ▶ ( blessed $type
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($type) and $type->isa("Moose::Meta::TypeConstraint::Parameterizable") or throw_exception("AddParameterizableTypeTakesParameterizableType", "type_name", $type) 0 1 1
Condition33%1/3
builtin::blessed($type) and $type->isa("Moose::Meta::TypeConstraint::Parameterizable")
!ll&&!rl&&r
100
MC/DC0%0/2
builtin::blessed($type) and $type->isa("Moose::Meta::TypeConstraint::Parameterizable")
builtin::blessed($type) $type->isa("Moose::Meta::TypeConstraint::Parameterizable")
Truth table33%1/3
A and B
A= builtin::blessed($type)B= $type->isa("Moose::Meta::TypeConstraint::Parameterizable")
ABresult
0X0
100
111
742 && $type->isa('Moose::Meta::TypeConstraint::Parameterizable') )
743 || throw_exception( AddParameterizableTypeTakesParameterizableType => type_name => $type );
744  
745 0 push @PARAMETERIZABLE_TYPES => $type;
746 }
747  
748 ## --------------------------------------------------------
749 # end of built-in types ...
750 ## --------------------------------------------------------
751  
752 {
753 398 my @BUILTINS = list_all_type_constraints();
754 0 ▶ sub list_all_builtin_type_constraints {@BUILTINS}
Subroutine list_all_builtin_type_constraints: not called CC=1 SCAR=6.9
Pod documented
755 }
756  
757 398 1;
758  
759 # ABSTRACT: Type constraint system for Moose
760  
761 __END__
« blib/lib/Moose/Exception.pm ↑ Summary blib/lib/Class/MOP/Method/Wrapped.pm »