← Index
NYTProf Performance Profile   « line view »
For fastest.pl
  Run on Fri Jan 31 20:48:16 2014
Reported on Fri Jan 31 20:49:41 2014

Filename/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Util/TypeConstraints.pm
StatementsExecuted 832 statements in 8.44ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.59ms1.95msMoose::Util::TypeConstraints::::BEGIN@614Moose::Util::TypeConstraints::BEGIN@614
1111.58ms3.99msMoose::Util::TypeConstraints::::BEGIN@33Moose::Util::TypeConstraints::BEGIN@33
1111.12ms2.25msMoose::Util::TypeConstraints::::BEGIN@36Moose::Util::TypeConstraints::BEGIN@36
1111.11ms2.50msMoose::Util::TypeConstraints::::BEGIN@39Moose::Util::TypeConstraints::BEGIN@39
1111.08ms2.21msMoose::Util::TypeConstraints::::BEGIN@37Moose::Util::TypeConstraints::BEGIN@37
1111.02ms7.70msMoose::Util::TypeConstraints::::BEGIN@38Moose::Util::TypeConstraints::BEGIN@38
111924µs5.74msMoose::Util::TypeConstraints::::BEGIN@34Moose::Util::TypeConstraints::BEGIN@34
111703µs2.66msMoose::Util::TypeConstraints::::BEGIN@42Moose::Util::TypeConstraints::BEGIN@42
14101659µs659µsMoose::Util::TypeConstraints::::CORE:regcompMoose::Util::TypeConstraints::CORE:regcomp (opcode)
1721472µs12.4msMoose::Util::TypeConstraints::::_create_type_constraintMoose::Util::TypeConstraints::_create_type_constraint
3084254µs578µsMoose::Util::TypeConstraints::::find_type_constraintMoose::Util::TypeConstraints::find_type_constraint
2011203µs997µsMoose::Util::TypeConstraints::::find_or_parse_type_constraintMoose::Util::TypeConstraints::find_or_parse_type_constraint
1611182µs6.93msMoose::Util::TypeConstraints::::subtypeMoose::Util::TypeConstraints::subtype
2033132µs3.29msMoose::Util::TypeConstraints::::find_or_create_isa_type_constraintMoose::Util::TypeConstraints::find_or_create_isa_type_constraint
42196µs3.02msMoose::Util::TypeConstraints::::create_class_type_constraintMoose::Util::TypeConstraints::create_class_type_constraint
201175µs94µsMoose::Util::TypeConstraints::::normalize_type_constraint_nameMoose::Util::TypeConstraints::normalize_type_constraint_name
233150µs50µsMoose::Util::TypeConstraints::::CORE:matchMoose::Util::TypeConstraints::CORE:match (opcode)
161132µs32µsMoose::Util::TypeConstraints::::asMoose::Util::TypeConstraints::as
31129µs185µsMoose::Util::TypeConstraints::::_detect_type_constraint_unionMoose::Util::TypeConstraints::_detect_type_constraint_union
161128µs28µsMoose::Util::TypeConstraints::::whereMoose::Util::TypeConstraints::where
31124µs103µsMoose::Util::TypeConstraints::::_detect_parameterized_type_constraintMoose::Util::TypeConstraints::_detect_parameterized_type_constraint
171123µs23µsMoose::Util::TypeConstraints::::inline_asMoose::Util::TypeConstraints::inline_as
201119µs19µsMoose::Util::TypeConstraints::::CORE:substMoose::Util::TypeConstraints::CORE:subst (opcode)
1010118µs18µsMoose::Util::TypeConstraints::::CORE:qrMoose::Util::TypeConstraints::CORE:qr (opcode)
11117µs31µsMoose::Util::TypeConstraints::::BEGIN@68Moose::Util::TypeConstraints::BEGIN@68
11114µs5.70msMoose::Util::TypeConstraints::::typeMoose::Util::TypeConstraints::type
11112µs29µsMoose::Util::TypeConstraints::::BEGIN@667Moose::Util::TypeConstraints::BEGIN@667
11112µs12µsMoose::Util::TypeConstraints::::BEGIN@3Moose::Util::TypeConstraints::BEGIN@3
11111µs22µsMoose::Util::TypeConstraints::::BEGIN@673Moose::Util::TypeConstraints::BEGIN@673
11111µs22µsMoose::Util::TypeConstraints::::BEGIN@694Moose::Util::TypeConstraints::BEGIN@694
11111µs22µsMoose::Util::TypeConstraints::::BEGIN@678Moose::Util::TypeConstraints::BEGIN@678
11110µs16µsMoose::Util::TypeConstraints::::BEGIN@31Moose::Util::TypeConstraints::BEGIN@31
11110µs36µsMoose::Util::TypeConstraints::::BEGIN@13Moose::Util::TypeConstraints::BEGIN@13
11110µs50µsMoose::Util::TypeConstraints::::BEGIN@12Moose::Util::TypeConstraints::BEGIN@12
11110µs47µsMoose::Util::TypeConstraints::::BEGIN@11Moose::Util::TypeConstraints::BEGIN@11
1119µs9µsMoose::Util::TypeConstraints::::BEGIN@40Moose::Util::TypeConstraints::BEGIN@40
1118µs9µsMoose::Util::TypeConstraints::::list_all_type_constraintsMoose::Util::TypeConstraints::list_all_type_constraints
1117µs887µsMoose::Util::TypeConstraints::::class_typeMoose::Util::TypeConstraints::class_type
1116µs6µsMoose::Util::TypeConstraints::::BEGIN@32Moose::Util::TypeConstraints::BEGIN@32
1116µs6µsMoose::Util::TypeConstraints::::BEGIN@35Moose::Util::TypeConstraints::BEGIN@35
1115µs5µsMoose::Util::TypeConstraints::::BEGIN@41Moose::Util::TypeConstraints::BEGIN@41
1114µs4µsMoose::Util::TypeConstraints::::BEGIN@10Moose::Util::TypeConstraints::BEGIN@10
0000s0sMoose::Util::TypeConstraints::::__ANON__[:654]Moose::Util::TypeConstraints::__ANON__[:654]
0000s0sMoose::Util::TypeConstraints::::__ANON__[:656]Moose::Util::TypeConstraints::__ANON__[:656]
0000s0sMoose::Util::TypeConstraints::::__ANON__[:658]Moose::Util::TypeConstraints::__ANON__[:658]
0000s0sMoose::Util::TypeConstraints::::__ANON__[:73]Moose::Util::TypeConstraints::__ANON__[:73]
0000s0sMoose::Util::TypeConstraints::::_confessMoose::Util::TypeConstraints::_confess
0000s0sMoose::Util::TypeConstraints::::_create_parameterized_type_constraintMoose::Util::TypeConstraints::_create_parameterized_type_constraint
0000s0sMoose::Util::TypeConstraints::::_create_type_constraint_unionMoose::Util::TypeConstraints::_create_type_constraint_union
0000s0sMoose::Util::TypeConstraints::::_install_type_coercionsMoose::Util::TypeConstraints::_install_type_coercions
0000s0sMoose::Util::TypeConstraints::::_parse_parameterized_type_constraintMoose::Util::TypeConstraints::_parse_parameterized_type_constraint
0000s0sMoose::Util::TypeConstraints::::_parse_type_constraint_unionMoose::Util::TypeConstraints::_parse_type_constraint_union
0000s0sMoose::Util::TypeConstraints::::_throw_errorMoose::Util::TypeConstraints::_throw_error
0000s0sMoose::Util::TypeConstraints::::add_parameterizable_typeMoose::Util::TypeConstraints::add_parameterizable_type
0000s0sMoose::Util::TypeConstraints::::coerceMoose::Util::TypeConstraints::coerce
0000s0sMoose::Util::TypeConstraints::::create_duck_type_constraintMoose::Util::TypeConstraints::create_duck_type_constraint
0000s0sMoose::Util::TypeConstraints::::create_enum_type_constraintMoose::Util::TypeConstraints::create_enum_type_constraint
0000s0sMoose::Util::TypeConstraints::::create_named_type_constraint_unionMoose::Util::TypeConstraints::create_named_type_constraint_union
0000s0sMoose::Util::TypeConstraints::::create_parameterized_type_constraintMoose::Util::TypeConstraints::create_parameterized_type_constraint
0000s0sMoose::Util::TypeConstraints::::create_role_type_constraintMoose::Util::TypeConstraints::create_role_type_constraint
0000s0sMoose::Util::TypeConstraints::::create_type_constraint_unionMoose::Util::TypeConstraints::create_type_constraint_union
0000s0sMoose::Util::TypeConstraints::::duck_typeMoose::Util::TypeConstraints::duck_type
0000s0sMoose::Util::TypeConstraints::::enumMoose::Util::TypeConstraints::enum
0000s0sMoose::Util::TypeConstraints::::export_type_constraints_as_functionsMoose::Util::TypeConstraints::export_type_constraints_as_functions
0000s0sMoose::Util::TypeConstraints::::find_or_create_does_type_constraintMoose::Util::TypeConstraints::find_or_create_does_type_constraint
0000s0sMoose::Util::TypeConstraints::::find_or_create_type_constraintMoose::Util::TypeConstraints::find_or_create_type_constraint
0000s0sMoose::Util::TypeConstraints::::fromMoose::Util::TypeConstraints::from
0000s0sMoose::Util::TypeConstraints::::get_all_parameterizable_typesMoose::Util::TypeConstraints::get_all_parameterizable_types
0000s0sMoose::Util::TypeConstraints::::get_type_constraint_registryMoose::Util::TypeConstraints::get_type_constraint_registry
0000s0sMoose::Util::TypeConstraints::::list_all_builtin_type_constraintsMoose::Util::TypeConstraints::list_all_builtin_type_constraints
0000s0sMoose::Util::TypeConstraints::::match_on_typeMoose::Util::TypeConstraints::match_on_type
0000s0sMoose::Util::TypeConstraints::::maybe_typeMoose::Util::TypeConstraints::maybe_type
0000s0sMoose::Util::TypeConstraints::::messageMoose::Util::TypeConstraints::message
0000s0sMoose::Util::TypeConstraints::::optimize_asMoose::Util::TypeConstraints::optimize_as
0000s0sMoose::Util::TypeConstraints::::register_type_constraintMoose::Util::TypeConstraints::register_type_constraint
0000s0sMoose::Util::TypeConstraints::::role_typeMoose::Util::TypeConstraints::role_type
0000s0sMoose::Util::TypeConstraints::::unionMoose::Util::TypeConstraints::union
0000s0sMoose::Util::TypeConstraints::::viaMoose::Util::TypeConstraints::via
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1
2package Moose::Util::TypeConstraints;
3
# spent 12µs within Moose::Util::TypeConstraints::BEGIN@3 which was called: # once (12µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 5
BEGIN {
416µs $Moose::Util::TypeConstraints::AUTHORITY = 'cpan:STEVAN';
5139µs112µs}
# spent 12µs making 1 call to Moose::Util::TypeConstraints::BEGIN@3
6{
721µs $Moose::Util::TypeConstraints::VERSION = '2.1005';
8}
9
10245µs14µs
# spent 4µs within Moose::Util::TypeConstraints::BEGIN@10 which was called: # once (4µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 10
use Carp ();
# spent 4µs making 1 call to Moose::Util::TypeConstraints::BEGIN@10
11238µs284µs
# spent 47µs (10+37) within Moose::Util::TypeConstraints::BEGIN@11 which was called: # once (10µs+37µs) by Moose::Meta::Attribute::BEGIN@24 at line 11
use List::MoreUtils qw( all any );
# spent 47µs making 1 call to Moose::Util::TypeConstraints::BEGIN@11 # spent 37µs making 1 call to Exporter::import
12234µs290µs
# spent 50µs (10+40) within Moose::Util::TypeConstraints::BEGIN@12 which was called: # once (10µs+40µs) by Moose::Meta::Attribute::BEGIN@24 at line 12
use Scalar::Util qw( blessed reftype );
# spent 50µs making 1 call to Moose::Util::TypeConstraints::BEGIN@12 # spent 40µs making 1 call to Exporter::import
13272µs262µs
# spent 36µs (10+26) within Moose::Util::TypeConstraints::BEGIN@13 which was called: # once (10µs+26µs) by Moose::Meta::Attribute::BEGIN@24 at line 13
use Moose::Exporter;
# spent 36µs making 1 call to Moose::Util::TypeConstraints::BEGIN@13 # spent 26µs making 1 call to Moose::Exporter::import
14
15## --------------------------------------------------------
16# Prototyped subs must be predeclared because we have a
17# circular dependency with Moose::Meta::Attribute et. al.
18# so in case of us being use'd first the predeclaration
19# ensures the prototypes are in scope when consumers are
20# compiled.
21
22# dah sugah!
23sub where (&);
24sub via (&);
25sub message (&);
26sub optimize_as (&);
27sub inline_as (&);
28
29## --------------------------------------------------------
30
31237µs221µs
# spent 16µs (10+5) within Moose::Util::TypeConstraints::BEGIN@31 which was called: # once (10µs+5µs) by Moose::Meta::Attribute::BEGIN@24 at line 31
use Moose::Deprecated;
32236µs16µs
# spent 6µs within Moose::Util::TypeConstraints::BEGIN@32 which was called: # once (6µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 32
use Moose::Meta::TypeConstraint;
# spent 6µs making 1 call to Moose::Util::TypeConstraints::BEGIN@32
332149µs13.99ms
# spent 3.99ms (1.58+2.41) within Moose::Util::TypeConstraints::BEGIN@33 which was called: # once (1.58ms+2.41ms) by Moose::Meta::Attribute::BEGIN@24 at line 33
use Moose::Meta::TypeConstraint::Union;
# spent 3.99ms making 1 call to Moose::Util::TypeConstraints::BEGIN@33
342138µs15.74ms
# spent 5.74ms (924µs+4.82) within Moose::Util::TypeConstraints::BEGIN@34 which was called: # once (924µs+4.82ms) by Moose::Meta::Attribute::BEGIN@24 at line 34
use Moose::Meta::TypeConstraint::Parameterized;
# spent 5.74ms making 1 call to Moose::Util::TypeConstraints::BEGIN@34
35231µs16µs
# spent 6µs within Moose::Util::TypeConstraints::BEGIN@35 which was called: # once (6µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 35
use Moose::Meta::TypeConstraint::Parameterizable;
# spent 6µs making 1 call to Moose::Util::TypeConstraints::BEGIN@35
362144µs12.25ms
# spent 2.25ms (1.12+1.14) within Moose::Util::TypeConstraints::BEGIN@36 which was called: # once (1.12ms+1.14ms) by Moose::Meta::Attribute::BEGIN@24 at line 36
use Moose::Meta::TypeConstraint::Class;
# spent 2.25ms making 1 call to Moose::Util::TypeConstraints::BEGIN@36
372135µs12.21ms
# spent 2.21ms (1.08+1.13) within Moose::Util::TypeConstraints::BEGIN@37 which was called: # once (1.08ms+1.13ms) by Moose::Meta::Attribute::BEGIN@24 at line 37
use Moose::Meta::TypeConstraint::Role;
# spent 2.21ms making 1 call to Moose::Util::TypeConstraints::BEGIN@37
382141µs17.70ms
# spent 7.70ms (1.02+6.68) within Moose::Util::TypeConstraints::BEGIN@38 which was called: # once (1.02ms+6.68ms) by Moose::Meta::Attribute::BEGIN@24 at line 38
use Moose::Meta::TypeConstraint::Enum;
# spent 7.70ms making 1 call to Moose::Util::TypeConstraints::BEGIN@38
392143µs12.50ms
# spent 2.50ms (1.11+1.39) within Moose::Util::TypeConstraints::BEGIN@39 which was called: # once (1.11ms+1.39ms) by Moose::Meta::Attribute::BEGIN@24 at line 39
use Moose::Meta::TypeConstraint::DuckType;
# spent 2.50ms making 1 call to Moose::Util::TypeConstraints::BEGIN@39
40235µs19µs
# spent 9µs within Moose::Util::TypeConstraints::BEGIN@40 which was called: # once (9µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 40
use Moose::Meta::TypeCoercion;
# spent 9µs making 1 call to Moose::Util::TypeConstraints::BEGIN@40
41229µs15µs
# spent 5µs within Moose::Util::TypeConstraints::BEGIN@41 which was called: # once (5µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 41
use Moose::Meta::TypeCoercion::Union;
# spent 5µs making 1 call to Moose::Util::TypeConstraints::BEGIN@41
422241µs12.66ms
# spent 2.66ms (703µs+1.95) within Moose::Util::TypeConstraints::BEGIN@42 which was called: # once (703µs+1.95ms) by Moose::Meta::Attribute::BEGIN@24 at line 42
use Moose::Meta::TypeConstraint::Registry;
# spent 2.66ms making 1 call to Moose::Util::TypeConstraints::BEGIN@42
43
4418µs11.27msMoose::Exporter->setup_import_methods(
# spent 1.27ms making 1 call to Moose::Exporter::setup_import_methods
45 as_is => [
46 qw(
47 type subtype class_type role_type maybe_type duck_type
48 as where message optimize_as inline_as
49 coerce from via
50 enum union
51 find_type_constraint
52 register_type_constraint
53 match_on_type )
54 ],
55);
56
57## --------------------------------------------------------
58## type registry and some useful functions for it
59## --------------------------------------------------------
60
6112µs1287µsmy $REGISTRY = Moose::Meta::TypeConstraint::Registry->new;
# spent 287µs making 1 call to Moose::Meta::TypeConstraint::Registry::new
62
63sub get_type_constraint_registry {$REGISTRY}
6417µs11µs
# spent 9µs (8+1) within Moose::Util::TypeConstraints::list_all_type_constraints which was called: # once (8µs+1µs) by Moose::Meta::Attribute::BEGIN@24 at line 749
sub list_all_type_constraints { keys %{ $REGISTRY->type_constraints } }
65
66sub export_type_constraints_as_functions {
67 my $pkg = caller();
6823.12ms245µs
# spent 31µs (17+14) within Moose::Util::TypeConstraints::BEGIN@68 which was called: # once (17µs+14µs) by Moose::Meta::Attribute::BEGIN@24 at line 68
no strict 'refs';
# spent 31µs making 1 call to Moose::Util::TypeConstraints::BEGIN@68 # spent 14µs making 1 call to strict::unimport
69 foreach my $constraint ( keys %{ $REGISTRY->type_constraints } ) {
70 my $tc = $REGISTRY->get_type_constraint($constraint)
71 ->_compiled_type_constraint;
72 *{"${pkg}::${constraint}"}
73 = sub { $tc->( $_[0] ) ? 1 : undef }; # the undef is for compat
74 }
75}
76
77sub create_type_constraint_union {
78 _create_type_constraint_union(\@_);
79}
80
81sub create_named_type_constraint_union {
82 my $name = shift;
83 _create_type_constraint_union($name, \@_);
84}
85
86sub _create_type_constraint_union {
87 my $name;
88 $name = shift if @_ > 1;
89 my @tcs = @{ shift() };
90
91 my @type_constraint_names;
92
93 if ( scalar @tcs == 1 && _detect_type_constraint_union( $tcs[0] ) ) {
94 @type_constraint_names = _parse_type_constraint_union( $tcs[0] );
95 }
96 else {
97 @type_constraint_names = @tcs;
98 }
99
100 ( scalar @type_constraint_names >= 2 )
101 || __PACKAGE__->_throw_error(
102 "You must pass in at least 2 type names to make a union");
103
104 my @type_constraints = map {
105 find_or_parse_type_constraint($_)
106 || __PACKAGE__->_throw_error(
107 "Could not locate type constraint ($_) for the union");
108 } @type_constraint_names;
109
110 my %options = (
111 type_constraints => \@type_constraints
112 );
113 $options{name} = $name if defined $name;
114
115 return Moose::Meta::TypeConstraint::Union->new(%options);
116}
117
118
119sub create_parameterized_type_constraint {
120 my $type_constraint_name = shift;
121 my ( $base_type, $type_parameter )
122 = _parse_parameterized_type_constraint($type_constraint_name);
123
124 ( defined $base_type && defined $type_parameter )
125 || __PACKAGE__->_throw_error(
126 "Could not parse type name ($type_constraint_name) correctly");
127
128 if ( $REGISTRY->has_type_constraint($base_type) ) {
129 my $base_type_tc = $REGISTRY->get_type_constraint($base_type);
130 return _create_parameterized_type_constraint(
131 $base_type_tc,
132 $type_parameter
133 );
134 }
135 else {
136 __PACKAGE__->_throw_error(
137 "Could not locate the base type ($base_type)");
138 }
139}
140
141sub _create_parameterized_type_constraint {
142 my ( $base_type_tc, $type_parameter ) = @_;
143 if ( $base_type_tc->can('parameterize') ) {
144 return $base_type_tc->parameterize($type_parameter);
145 }
146 else {
147 return Moose::Meta::TypeConstraint::Parameterized->new(
148 name => $base_type_tc->name . '[' . $type_parameter . ']',
149 parent => $base_type_tc,
150 type_parameter =>
151 find_or_create_isa_type_constraint($type_parameter),
152 );
153 }
154}
155
156#should we also support optimized checks?
157
# spent 3.02ms (96µs+2.93) within Moose::Util::TypeConstraints::create_class_type_constraint which was called 4 times, avg 756µs/call: # 3 times (70µs+2.07ms) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 260, avg 715µs/call # once (26µs+853µs) by Moose::Util::TypeConstraints::class_type at line 368
sub create_class_type_constraint {
15842µs my ( $class, $options ) = @_;
159
160# too early for this check
161#find_type_constraint("ClassName")->check($class)
162# || __PACKAGE__->_throw_error("Can't create a class type constraint because '$class' is not a class name");
163
16445µs my $pkg_defined_in = $options->{package_defined_in} || scalar( caller(1) );
165
16648µs428µs if (my $type = $REGISTRY->get_type_constraint($class)) {
# spent 28µs making 4 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 7µs/call
167 if (!($type->isa('Moose::Meta::TypeConstraint::Class') && $type->class eq $class)) {
168 _confess(
169 "The type constraint '$class' has already been created in "
170 . $type->_package_defined_in
171 . " and cannot be created again in "
172 . $pkg_defined_in )
173 }
174 else {
175 return $type;
176 }
177 }
178
179 my %options = (
180 class => $class,
181 name => $class,
182 package_defined_in => $pkg_defined_in,
183413µs %{ $options || {} },
184 );
185
18642µs $options{name} ||= "__ANON__";
187
188422µs42.80ms my $tc = Moose::Meta::TypeConstraint::Class->new(%options);
# spent 2.80ms making 4 calls to Moose::Meta::TypeConstraint::Class::new, avg 700µs/call
18949µs4101µs $REGISTRY->add_type_constraint($tc);
# spent 101µs making 4 calls to Moose::Meta::TypeConstraint::Registry::add_type_constraint, avg 25µs/call
190419µs return $tc;
191}
192
193sub create_role_type_constraint {
194 my ( $role, $options ) = @_;
195
196# too early for this check
197#find_type_constraint("ClassName")->check($class)
198# || __PACKAGE__->_throw_error("Can't create a class type constraint because '$class' is not a class name");
199
200 my $pkg_defined_in = $options->{package_defined_in} || scalar( caller(1) );
201
202 if (my $type = $REGISTRY->get_type_constraint($role)) {
203 if (!($type->isa('Moose::Meta::TypeConstraint::Role') && $type->role eq $role)) {
204 _confess(
205 "The type constraint '$role' has already been created in "
206 . $type->_package_defined_in
207 . " and cannot be created again in "
208 . $pkg_defined_in )
209 }
210 else {
211 return $type;
212 }
213 }
214
215 my %options = (
216 role => $role,
217 name => $role,
218 package_defined_in => $pkg_defined_in,
219 %{ $options || {} },
220 );
221
222 $options{name} ||= "__ANON__";
223
224 my $tc = Moose::Meta::TypeConstraint::Role->new(%options);
225 $REGISTRY->add_type_constraint($tc);
226 return $tc;
227}
228
229sub find_or_create_type_constraint {
230 my ( $type_constraint_name, $options_for_anon_type ) = @_;
231
232 if ( my $constraint
233 = find_or_parse_type_constraint($type_constraint_name) ) {
234 return $constraint;
235 }
236 elsif ( defined $options_for_anon_type ) {
237
238 # NOTE:
239 # if there is no $options_for_anon_type
240 # specified, then we assume they don't
241 # want to create one, and return nothing.
242
243 # otherwise assume that we should create
244 # an ANON type with the $options_for_anon_type
245 # options which can be passed in. It should
246 # be noted that these don't get registered
247 # so we need to return it.
248 # - SL
249 return Moose::Meta::TypeConstraint->new(
250 name => '__ANON__',
251 %{$options_for_anon_type}
252 );
253 }
254
255 return;
256}
257
258
# spent 3.29ms (132µs+3.16) within Moose::Util::TypeConstraints::find_or_create_isa_type_constraint which was called 20 times, avg 164µs/call: # 16 times (98µs+561µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 565, avg 41µs/call # 3 times (26µs+2.55ms) by Moo::HandleMoose::inject_fake_metaclass_for at line 44 of Moo/HandleMoose.pm, avg 859µs/call # once (8µs+44µs) by Moose::Meta::Attribute::_process_isa_option at line 374 of Moose/Meta/Attribute.pm
sub find_or_create_isa_type_constraint {
259208µs my ($type_constraint_name, $options) = @_;
2602090µs403.16ms find_or_parse_type_constraint($type_constraint_name)
# spent 2.14ms making 3 calls to Moose::Util::TypeConstraints::create_class_type_constraint, avg 715µs/call # spent 997µs making 20 calls to Moose::Util::TypeConstraints::find_or_parse_type_constraint, avg 50µs/call # spent 14µs making 17 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:16], avg 841ns/call
261 || create_class_type_constraint($type_constraint_name, $options);
262}
263
264sub find_or_create_does_type_constraint {
265 my ($type_constraint_name, $options) = @_;
266 find_or_parse_type_constraint($type_constraint_name)
267 || create_role_type_constraint($type_constraint_name, $options);
268}
269
270
# spent 997µs (203+794) within Moose::Util::TypeConstraints::find_or_parse_type_constraint which was called 20 times, avg 50µs/call: # 20 times (203µs+794µs) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 260, avg 50µs/call
sub find_or_parse_type_constraint {
2712024µs2094µs my $type_constraint_name = normalize_type_constraint_name(shift);
# spent 94µs making 20 calls to Moose::Util::TypeConstraints::normalize_type_constraint_name, avg 5µs/call
272202µs my $constraint;
273
27420116µs43700µs if ( $constraint = find_type_constraint($type_constraint_name) ) {
# spent 379µs making 20 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 19µs/call # spent 185µs making 3 calls to Moose::Util::TypeConstraints::_detect_type_constraint_union, avg 62µs/call # spent 103µs making 3 calls to Moose::Util::TypeConstraints::_detect_parameterized_type_constraint, avg 34µs/call # spent 34µs making 17 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:16], avg 2µs/call
275 return $constraint;
276 }
277 elsif ( _detect_type_constraint_union($type_constraint_name) ) {
278 $constraint = create_type_constraint_union($type_constraint_name);
279 }
280 elsif ( _detect_parameterized_type_constraint($type_constraint_name) ) {
281 $constraint
282 = create_parameterized_type_constraint($type_constraint_name);
283 }
284 else {
28539µs return;
286 }
287
288 $REGISTRY->add_type_constraint($constraint);
289 return $constraint;
290}
291
292
# spent 94µs (75+19) within Moose::Util::TypeConstraints::normalize_type_constraint_name which was called 20 times, avg 5µs/call: # 20 times (75µs+19µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 271, avg 5µs/call
sub normalize_type_constraint_name {
293205µs my $type_constraint_name = shift;
2942058µs2019µs $type_constraint_name =~ s/\s//g;
# spent 19µs making 20 calls to Moose::Util::TypeConstraints::CORE:subst, avg 940ns/call
2952048µs return $type_constraint_name;
296}
297
298sub _confess {
299 my $error = shift;
300
301 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
302 Carp::confess($error);
303}
304
305## --------------------------------------------------------
306## exported functions ...
307## --------------------------------------------------------
308
309
# spent 578µs (254+324) within Moose::Util::TypeConstraints::find_type_constraint which was called 30 times, avg 19µs/call: # 20 times (164µs+216µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 274, avg 19µs/call # 4 times (35µs+46µs) by Moose::Meta::TypeConstraint::Class::new at line 35 of Moose/Meta/TypeConstraint/Class.pm, avg 20µs/call # once (12µs+11µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 204 of Moose/Util/TypeConstraints/Builtins.pm # once (10µs+11µs) by Moose::init_meta at line 165 of Moose.pm # once (9µs+10µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 85 of Moose/Util/TypeConstraints/Builtins.pm # once (8µs+10µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 300 of Moose/Util/TypeConstraints/Builtins.pm # once (8µs+10µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 239 of Moose/Util/TypeConstraints/Builtins.pm # once (8µs+10µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 274 of Moose/Util/TypeConstraints/Builtins.pm
sub find_type_constraint {
3103011µs my $type = shift;
311
3123077µs3014µs if ( blessed $type and $type->isa("Moose::Meta::TypeConstraint") ) {
# spent 14µs making 30 calls to Scalar::Util::blessed, avg 453ns/call
313 return $type;
314 }
315 else {
3163061µs30186µs return unless $REGISTRY->has_type_constraint($type);
# spent 186µs making 30 calls to Moose::Meta::TypeConstraint::Registry::has_type_constraint, avg 6µs/call
3172690µs26124µs return $REGISTRY->get_type_constraint($type);
# spent 124µs making 26 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 5µs/call
318 }
319}
320
321sub register_type_constraint {
322 my $constraint = shift;
323 __PACKAGE__->_throw_error("can't register an unnamed type constraint")
324 unless defined $constraint->name;
325 $REGISTRY->add_type_constraint($constraint);
326 return $constraint;
327}
328
329# type constructors
330
331
# spent 5.70ms (14µs+5.69) within Moose::Util::TypeConstraints::type which was called: # once (14µs+5.69ms) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 16 of Moose/Util/TypeConstraints/Builtins.pm
sub type {
3321600ns my $name = shift;
333
33416µs my %p = map { %{$_} } @_;
335
33618µs15.69ms return _create_type_constraint(
337 $name, undef, $p{where}, $p{message},
338 $p{optimize_as}, $p{inline_as},
339 );
340}
341
342
# spent 6.93ms (182µs+6.75) within Moose::Util::TypeConstraints::subtype which was called 16 times, avg 433µs/call: # 16 times (182µs+6.75ms) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 17 of Moose/Util/TypeConstraints/Builtins.pm, avg 433µs/call
sub subtype {
343165µs if ( @_ == 1 && !ref $_[0] ) {
344 __PACKAGE__->_throw_error(
345 'A subtype cannot consist solely of a name, it must have a parent'
346 );
347 }
348
349 # The blessed check is mostly to accommodate MooseX::Types, which
350 # uses an object which overloads stringification as a type name.
351168µs my $name = ref $_[0] && !blessed $_[0] ? undef : shift;
352
3531680µs my %p = map { %{$_} } @_;
354
355 # subtype Str => where { ... };
356167µs if ( !exists $p{as} ) {
357 $p{as} = $name;
358 $name = undef;
359 }
360
3611674µs166.75ms return _create_type_constraint(
# spent 6.75ms making 16 calls to Moose::Util::TypeConstraints::_create_type_constraint, avg 422µs/call
362 $name, $p{as}, $p{where}, $p{message},
363 $p{optimize_as}, $p{inline_as},
364 );
365}
366
367
# spent 887µs (7+880) within Moose::Util::TypeConstraints::class_type which was called: # once (7µs+880µs) by Moose::init_meta at line 165 of Moose.pm
sub class_type {
36815µs1880µs create_class_type_constraint(@_);
369}
370
371sub role_type ($;$) {
372 create_role_type_constraint(@_);
373}
374
375sub maybe_type {
376 my ($type_parameter) = @_;
377
378 register_type_constraint(
379 $REGISTRY->get_type_constraint('Maybe')->parameterize($type_parameter)
380 );
381}
382
383sub duck_type {
384 my ( $type_name, @methods ) = @_;
385 if ( ref $type_name eq 'ARRAY' && !@methods ) {
386 @methods = @$type_name;
387 $type_name = undef;
388 }
389 if ( @methods == 1 && ref $methods[0] eq 'ARRAY' ) {
390 @methods = @{ $methods[0] };
391 }
392
393 register_type_constraint(
394 create_duck_type_constraint(
395 $type_name,
396 \@methods,
397 )
398 );
399}
400
401sub coerce {
402 my ( $type_name, @coercion_map ) = @_;
403 _install_type_coercions( $type_name, \@coercion_map );
404}
405
406# The trick of returning @_ lets us avoid having to specify a
407# prototype. Perl will parse this:
408#
409# subtype 'Foo'
410# => as 'Str'
411# => where { ... }
412#
413# as this:
414#
415# subtype( 'Foo', as( 'Str', where { ... } ) );
416#
417# If as() returns all its extra arguments, this just works, and
418# preserves backwards compatibility.
4191649µs
# spent 32µs within Moose::Util::TypeConstraints::as which was called 16 times, avg 2µs/call: # 16 times (32µs+0s) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 18 of Moose/Util/TypeConstraints/Builtins.pm, avg 2µs/call
sub as { { as => shift }, @_ }
4201647µs
# spent 28µs within Moose::Util::TypeConstraints::where which was called 16 times, avg 2µs/call: # 16 times (28µs+0s) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 19 of Moose/Util/TypeConstraints/Builtins.pm, avg 2µs/call
sub where (&) { { where => $_[0] } }
421sub message (&) { { message => $_[0] } }
422sub optimize_as (&) { { optimize_as => $_[0] } }
4231744µs
# spent 23µs within Moose::Util::TypeConstraints::inline_as which was called 17 times, avg 1µs/call: # 17 times (23µs+0s) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 21 of Moose/Util/TypeConstraints/Builtins.pm, avg 1µs/call
sub inline_as (&) { { inline_as => $_[0] } }
424
425sub from {@_}
426sub via (&) { $_[0] }
427
428sub enum {
429 my ( $type_name, @values ) = @_;
430
431 # NOTE:
432 # if only an array-ref is passed then
433 # you get an anon-enum
434 # - SL
435 if ( ref $type_name eq 'ARRAY' ) {
436 @values == 0
437 || __PACKAGE__->_throw_error("enum called with an array reference and additional arguments. Did you mean to parenthesize the enum call's parameters?");
438
439 @values = @$type_name;
440 $type_name = undef;
441 }
442 if ( @values == 1 && ref $values[0] eq 'ARRAY' ) {
443 @values = @{ $values[0] };
444 }
445
446 register_type_constraint(
447 create_enum_type_constraint(
448 $type_name,
449 \@values,
450 )
451 );
452}
453
454sub union {
455 my ( $type_name, @constraints ) = @_;
456 if ( ref $type_name eq 'ARRAY' ) {
457 @constraints == 0
458 || __PACKAGE__->_throw_error("union called with an array reference and additional arguments.");
459 @constraints = @$type_name;
460 $type_name = undef;
461 }
462 if ( @constraints == 1 && ref $constraints[0] eq 'ARRAY' ) {
463 @constraints = @{ $constraints[0] };
464 }
465 if ( defined $type_name ) {
466 return register_type_constraint(
467 create_named_type_constraint_union( $type_name, @constraints )
468 );
469 }
470 return create_type_constraint_union( @constraints );
471}
472
473sub create_enum_type_constraint {
474 my ( $type_name, $values ) = @_;
475
476 Moose::Meta::TypeConstraint::Enum->new(
477 name => $type_name || '__ANON__',
478 values => $values,
479 );
480}
481
482sub create_duck_type_constraint {
483 my ( $type_name, $methods ) = @_;
484
485 Moose::Meta::TypeConstraint::DuckType->new(
486 name => $type_name || '__ANON__',
487 methods => $methods,
488 );
489}
490
491sub match_on_type {
492 my ($to_match, @cases) = @_;
493 my $default;
494 if (@cases % 2 != 0) {
495 $default = pop @cases;
496 (ref $default eq 'CODE')
497 || __PACKAGE__->_throw_error("Default case must be a CODE ref, not $default");
498 }
499 while (@cases) {
500 my ($type, $action) = splice @cases, 0, 2;
501
502 unless (blessed $type && $type->isa('Moose::Meta::TypeConstraint')) {
503 $type = find_or_parse_type_constraint($type)
504 || __PACKAGE__->_throw_error("Cannot find or parse the type '$type'")
505 }
506
507 (ref $action eq 'CODE')
508 || __PACKAGE__->_throw_error("Match action must be a CODE ref, not $action");
509
510 if ($type->check($to_match)) {
511 local $_ = $to_match;
512 return $action->($to_match);
513 }
514 }
515 (defined $default)
516 || __PACKAGE__->_throw_error("No cases matched for $to_match");
517 {
518 local $_ = $to_match;
519 return $default->($to_match);
520 }
521}
522
523
524## --------------------------------------------------------
525## desugaring functions ...
526## --------------------------------------------------------
527
528
# spent 12.4ms (472µs+12.0) within Moose::Util::TypeConstraints::_create_type_constraint which was called 17 times, avg 732µs/call: # 16 times (434µs+6.32ms) by Moose::Util::TypeConstraints::subtype at line 361, avg 422µs/call # once (38µs+5.65ms) by Moose::Util::TypeConstraints::type at line 336
sub _create_type_constraint ($$$;$$) {
529174µs my $name = shift;
530173µs my $parent = shift;
531172µs my $check = shift;
532179µs my $message = shift;
533174µs my $optimized = shift;
534172µs my $inlined = shift;
535
5361710µs my $pkg_defined_in = scalar( caller(1) );
537
538174µs if ( defined $name ) {
5391728µs17115µs my $type = $REGISTRY->get_type_constraint($name);
# spent 115µs making 17 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 7µs/call
540
541172µs ( $type->_package_defined_in eq $pkg_defined_in )
542 || _confess(
543 "The type constraint '$name' has already been created in "
544 . $type->_package_defined_in
545 . " and cannot be created again in "
546 . $pkg_defined_in )
547 if defined $type;
548
5491786µs1746µs $name =~ /^[\w:\.]+$/
# spent 46µs making 17 calls to Moose::Util::TypeConstraints::CORE:match, avg 3µs/call
550 or die qq{$name contains invalid characters for a type name.}
551 . qq{ Names can contain alphanumeric character, ":", and "."\n};
552 }
553
5541742µs my %opts = (
555 name => $name,
556 package_defined_in => $pkg_defined_in,
557
558 ( $check ? ( constraint => $check ) : () ),
559 ( $message ? ( message => $message ) : () ),
560 ( $optimized ? ( optimized => $optimized ) : () ),
561 ( $inlined ? ( inlined => $inlined ) : () ),
562 );
563
564172µs my $constraint;
56517127µs645.86ms if (
# spent 5.18ms making 16 calls to Moose::Meta::TypeConstraint::create_child_type, avg 323µs/call # spent 659µs making 16 calls to Moose::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 41µs/call # spent 13µs making 16 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:16], avg 806ns/call # spent 12µs making 16 calls to Scalar::Util::blessed, avg 781ns/call
566 defined $parent
567 and $parent
568 = blessed $parent
569 ? $parent
570 : find_or_create_isa_type_constraint($parent)
571 ) {
572 $constraint = $parent->create_child_type(%opts);
573 }
574 else {
57514µs15.60ms $constraint = Moose::Meta::TypeConstraint->new(%opts);
# spent 5.60ms making 1 call to Moose::Meta::TypeConstraint::new
576 }
577
5781730µs17352µs $REGISTRY->add_type_constraint($constraint)
# spent 352µs making 17 calls to Moose::Meta::TypeConstraint::Registry::add_type_constraint, avg 21µs/call
579 if defined $name;
580
5811754µs return $constraint;
582}
583
584sub _install_type_coercions ($$) {
585 my ( $type_name, $coercion_map ) = @_;
586 my $type = find_type_constraint($type_name);
587 ( defined $type )
588 || __PACKAGE__->_throw_error(
589 "Cannot find type '$type_name', perhaps you forgot to load it");
590 if ( $type->has_coercion ) {
591 $type->coercion->add_type_coercions(@$coercion_map);
592 }
593 else {
594 my $type_coercion = Moose::Meta::TypeCoercion->new(
595 type_coercion_map => $coercion_map,
596 type_constraint => $type
597 );
598 $type->coercion($type_coercion);
599 }
600}
601
602## --------------------------------------------------------
603## type notation parsing ...
604## --------------------------------------------------------
605
606{
607
608 # All I have to say is mugwump++ cause I know
609 # do not even have enough regexp-fu to be able
610 # to have written this (I can only barely
611 # understand it as it is)
612 # - SL
613
6143521µs21.97ms
# spent 1.95ms (1.59+356µs) within Moose::Util::TypeConstraints::BEGIN@614 which was called: # once (1.59ms+356µs) by Moose::Meta::Attribute::BEGIN@24 at line 614
use re "eval";
# spent 1.95ms making 1 call to Moose::Util::TypeConstraints::BEGIN@614 # spent 15µs making 1 call to re::import
615
61617µs12µs my $valid_chars = qr{[\w:\.]};
# spent 2µs making 1 call to Moose::Util::TypeConstraints::CORE:qr
617136µs226µs my $type_atom = qr{ (?>$valid_chars+) }x;
# spent 25µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 2µs making 1 call to Moose::Util::TypeConstraints::CORE:qr
61814µs11µs my $ws = qr{ (?>\s*) }x;
# spent 1µs making 1 call to Moose::Util::TypeConstraints::CORE:qr
619122µs212µs my $op_union = qr{ $ws \| $ws }x;
# spent 11µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 1µs making 1 call to Moose::Util::TypeConstraints::CORE:qr
620
6211200ns my ($type, $type_capture_parts, $type_with_parameter, $union, $any);
62213µs if (Class::MOP::IS_RUNNING_ON_5_10) {
6231400ns my $type_pattern
624 = q{ (?&type_atom) (?: \[ (?&ws) (?&any) (?&ws) \] )? };
6251200ns my $type_capture_parts_pattern
626 = q{ ((?&type_atom)) (?: \[ (?&ws) ((?&any)) (?&ws) \] )? };
6271200ns my $type_with_parameter_pattern
628 = q{ (?&type_atom) \[ (?&ws) (?&any) (?&ws) \] };
6291200ns my $union_pattern
630 = q{ (?&type) (?> (?: (?&op_union) (?&type) )+ ) };
6311200ns my $any_pattern
632 = q{ (?&type) | (?&union) };
633
634183µs271µs my $defines = qr{(?(DEFINE)
# spent 70µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 1µs making 1 call to Moose::Util::TypeConstraints::CORE:qr
635 (?<valid_chars> $valid_chars)
636 (?<type_atom> $type_atom)
637 (?<ws> $ws)
638 (?<op_union> $op_union)
639 (?<type> $type_pattern)
640 (?<type_capture_parts> $type_capture_parts_pattern)
641 (?<type_with_parameter> $type_with_parameter_pattern)
642 (?<union> $union_pattern)
643 (?<any> $any_pattern)
644 )}x;
645
646179µs266µs $type = qr{ $type_pattern $defines }x;
# spent 65µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 1µs making 1 call to Moose::Util::TypeConstraints::CORE:qr
647179µs266µs $type_capture_parts = qr{ $type_capture_parts_pattern $defines }x;
# spent 65µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 1µs making 1 call to Moose::Util::TypeConstraints::CORE:qr
648184µs271µs $type_with_parameter = qr{ $type_with_parameter_pattern $defines }x;
# spent 67µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 5µs making 1 call to Moose::Util::TypeConstraints::CORE:qr
649182µs266µs $union = qr{ $union_pattern $defines }x;
# spent 64µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 2µs making 1 call to Moose::Util::TypeConstraints::CORE:qr
650179µs264µs $any = qr{ $any_pattern $defines }x;
# spent 63µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 2µs making 1 call to Moose::Util::TypeConstraints::CORE:qr
651 }
652 else {
653 $type
654 = qr{ $type_atom (?: \[ $ws (??{$any}) $ws \] )? }x;
655 $type_capture_parts
656 = qr{ ($type_atom) (?: \[ $ws ((??{$any})) $ws \] )? }x;
657 $type_with_parameter
658 = qr{ $type_atom \[ $ws (??{$any}) $ws \] }x;
659 $union
660 = qr{ $type (?> (?: $op_union $type )+ ) }x;
661 $any
662 = qr{ $type | $union }x;
663 }
664
665
666 sub _parse_parameterized_type_constraint {
667294µs246µs
# spent 29µs (12+17) within Moose::Util::TypeConstraints::BEGIN@667 which was called: # once (12µs+17µs) by Moose::Meta::Attribute::BEGIN@24 at line 667
{ no warnings 'void'; $any; } # force capture of interpolated lexical
# spent 29µs making 1 call to Moose::Util::TypeConstraints::BEGIN@667 # spent 17µs making 1 call to warnings::unimport
668 $_[0] =~ m{ $type_capture_parts }x;
669 return ( $1, $2 );
670 }
671
672
# spent 103µs (24+78) within Moose::Util::TypeConstraints::_detect_parameterized_type_constraint which was called 3 times, avg 34µs/call: # 3 times (24µs+78µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 274, avg 34µs/call
sub _detect_parameterized_type_constraint {
673880µs233µs
# spent 22µs (11+11) within Moose::Util::TypeConstraints::BEGIN@673 which was called: # once (11µs+11µs) by Moose::Meta::Attribute::BEGIN@24 at line 673
{ no warnings 'void'; $any; } # force capture of interpolated lexical
# spent 22µs making 1 call to Moose::Util::TypeConstraints::BEGIN@673 # spent 11µs making 1 call to warnings::unimport
6743103µs678µs $_[0] =~ m{ ^ $type_with_parameter $ }x;
# spent 77µs making 3 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 26µs/call # spent 1µs making 3 calls to Moose::Util::TypeConstraints::CORE:match, avg 467ns/call
675 }
676
677 sub _parse_type_constraint_union {
6782148µs232µs
# spent 22µs (11+11) within Moose::Util::TypeConstraints::BEGIN@678 which was called: # once (11µs+11µs) by Moose::Meta::Attribute::BEGIN@24 at line 678
{ no warnings 'void'; $any; } # force capture of interpolated lexical
# spent 22µs making 1 call to Moose::Util::TypeConstraints::BEGIN@678 # spent 11µs making 1 call to warnings::unimport
679 my $given = shift;
680 my @rv;
681 while ( $given =~ m{ \G (?: $op_union )? ($type) }gcx ) {
682 push @rv => $1;
683 }
684 ( pos($given) eq length($given) )
685 || __PACKAGE__->_throw_error( "'$given' didn't parse (parse-pos="
686 . pos($given)
687 . " and str-length="
688 . length($given)
689 . ")" );
690 @rv;
691 }
692
693
# spent 185µs (29+156) within Moose::Util::TypeConstraints::_detect_type_constraint_union which was called 3 times, avg 62µs/call: # 3 times (29µs+156µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 274, avg 62µs/call
sub _detect_type_constraint_union {
6948462µs232µs
# spent 22µs (11+11) within Moose::Util::TypeConstraints::BEGIN@694 which was called: # once (11µs+11µs) by Moose::Meta::Attribute::BEGIN@24 at line 694
{ no warnings 'void'; $any; } # force capture of interpolated lexical
# spent 22µs making 1 call to Moose::Util::TypeConstraints::BEGIN@694 # spent 11µs making 1 call to warnings::unimport
6953185µs6156µs $_[0] =~ m{^ $type $op_union $type ( $op_union .* )? $}x;
# spent 153µs making 3 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 51µs/call # spent 2µs making 3 calls to Moose::Util::TypeConstraints::CORE:match, avg 800ns/call
696 }
697}
698
699## --------------------------------------------------------
700# define some basic built-in types
701## --------------------------------------------------------
702
703# By making these classes immutable before creating all the types in
704# Moose::Util::TypeConstraints::Builtin , we avoid repeatedly calling the slow
705# MOP-based accessors.
706$_->make_immutable(
70797µs96µs inline_constructor => 1,
# spent 6µs making 9 calls to Class::MOP::Class::is_mutable, avg 644ns/call
708 constructor_name => "_new",
709
710 # these are Class::MOP accessors, so they need inlining
711 inline_accessors => 1
7121029µs1857.6ms ) for grep { $_->is_mutable }
# spent 57.6ms making 9 calls to Class::MOP::Class::make_immutable, avg 6.40ms/call # spent 38µs making 9 calls to Class::MOP::class_of, avg 4µs/call
713 map { Class::MOP::class_of($_) }
714 qw(
715 Moose::Meta::TypeConstraint
716 Moose::Meta::TypeConstraint::Union
717 Moose::Meta::TypeConstraint::Parameterized
718 Moose::Meta::TypeConstraint::Parameterizable
719 Moose::Meta::TypeConstraint::Class
720 Moose::Meta::TypeConstraint::Role
721 Moose::Meta::TypeConstraint::Enum
722 Moose::Meta::TypeConstraint::DuckType
723 Moose::Meta::TypeConstraint::Registry
724);
725
7261127µsrequire Moose::Util::TypeConstraints::Builtins;
72713µs114.8msMoose::Util::TypeConstraints::Builtins::define_builtins($REGISTRY);
728
729my @PARAMETERIZABLE_TYPES
73057µs419µs = map { $REGISTRY->get_type_constraint($_) } qw[ScalarRef ArrayRef HashRef Maybe];
# spent 19µs making 4 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 5µs/call
731
732sub get_all_parameterizable_types {@PARAMETERIZABLE_TYPES}
733
734sub add_parameterizable_type {
735 my $type = shift;
736 ( blessed $type
737 && $type->isa('Moose::Meta::TypeConstraint::Parameterizable') )
738 || __PACKAGE__->_throw_error(
739 "Type must be a Moose::Meta::TypeConstraint::Parameterizable not $type"
740 );
741 push @PARAMETERIZABLE_TYPES => $type;
742}
743
744## --------------------------------------------------------
745# end of built-in types ...
746## --------------------------------------------------------
747
748{
74925µs19µs my @BUILTINS = list_all_type_constraints();
750 sub list_all_builtin_type_constraints {@BUILTINS}
751}
752
753sub _throw_error {
754 shift;
755 require Moose;
756 unshift @_, 'Moose';
757 goto &Moose::throw_error;
758}
759
760156µs1;
761
762# ABSTRACT: Type constraint system for Moose
763
764__END__
 
# spent 50µs within Moose::Util::TypeConstraints::CORE:match which was called 23 times, avg 2µs/call: # 17 times (46µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint at line 549, avg 3µs/call # 3 times (2µs+0s) by Moose::Util::TypeConstraints::_detect_type_constraint_union at line 695, avg 800ns/call # 3 times (1µs+0s) by Moose::Util::TypeConstraints::_detect_parameterized_type_constraint at line 674, avg 467ns/call
sub Moose::Util::TypeConstraints::CORE:match; # opcode
# spent 18µs within Moose::Util::TypeConstraints::CORE:qr which was called 10 times, avg 2µs/call: # once (5µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 648 # once (2µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 616 # once (2µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 649 # once (2µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 650 # once (2µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 617 # once (1µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 619 # once (1µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 646 # once (1µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 634 # once (1µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 618 # once (1µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 647
sub Moose::Util::TypeConstraints::CORE:qr; # opcode
# spent 659µs within Moose::Util::TypeConstraints::CORE:regcomp which was called 14 times, avg 47µs/call: # 3 times (153µs+0s) by Moose::Util::TypeConstraints::_detect_type_constraint_union at line 695, avg 51µs/call # 3 times (77µs+0s) by Moose::Util::TypeConstraints::_detect_parameterized_type_constraint at line 674, avg 26µs/call # once (70µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 634 # once (67µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 648 # once (65µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 646 # once (65µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 647 # once (64µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 649 # once (63µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 650 # once (25µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 617 # once (11µs+0s) by Moose::Meta::Attribute::BEGIN@24 at line 619
sub Moose::Util::TypeConstraints::CORE:regcomp; # opcode
# spent 19µs within Moose::Util::TypeConstraints::CORE:subst which was called 20 times, avg 940ns/call: # 20 times (19µs+0s) by Moose::Util::TypeConstraints::normalize_type_constraint_name at line 294, avg 940ns/call
sub Moose::Util::TypeConstraints::CORE:subst; # opcode