← Index
NYTProf Performance Profile   « line view »
For /home/ss5/perl5/perlbrew/perls/perl-5.22.0/bin/benchmarkanything-storage
  Run on Mon Jan 29 16:55:34 2018
Reported on Mon Jan 29 16:57:06 2018

Filename/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Util/TypeConstraints.pm
StatementsExecuted 1649 statements in 11.0ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
661111.85ms1.85msMoose::Util::TypeConstraints::::CORE:regcompMoose::Util::TypeConstraints::CORE:regcomp (opcode)
111880µs1.06msMoose::Util::TypeConstraints::::BEGIN@621Moose::Util::TypeConstraints::BEGIN@621
111747µs2.85msMoose::Util::TypeConstraints::::BEGIN@25Moose::Util::TypeConstraints::BEGIN@25
111556µs1.55msMoose::Util::TypeConstraints::::BEGIN@28Moose::Util::TypeConstraints::BEGIN@28
111546µs1.22msMoose::Util::TypeConstraints::::BEGIN@31Moose::Util::TypeConstraints::BEGIN@31
111466µs1.38msMoose::Util::TypeConstraints::::BEGIN@30Moose::Util::TypeConstraints::BEGIN@30
111459µs3.52msMoose::Util::TypeConstraints::::BEGIN@26Moose::Util::TypeConstraints::BEGIN@26
111442µs1.10msMoose::Util::TypeConstraints::::BEGIN@29Moose::Util::TypeConstraints::BEGIN@29
111439µs5.92msMoose::Util::TypeConstraints::::BEGIN@34Moose::Util::TypeConstraints::BEGIN@34
107116419µs878µsMoose::Util::TypeConstraints::::find_type_constraintMoose::Util::TypeConstraints::find_type_constraint
4621328µs3.78msMoose::Util::TypeConstraints::::find_or_parse_type_constraintMoose::Util::TypeConstraints::find_or_parse_type_constraint (recurses: max depth 2, inclusive time 850µs)
1521251µs14.8msMoose::Util::TypeConstraints::::create_class_type_constraintMoose::Util::TypeConstraints::create_class_type_constraint
1721234µs7.90msMoose::Util::TypeConstraints::::_create_type_constraintMoose::Util::TypeConstraints::_create_type_constraint
2811174µs689µsMoose::Util::TypeConstraints::::_detect_type_constraint_unionMoose::Util::TypeConstraints::_detect_type_constraint_union
1211173µs9.22msMoose::Util::TypeConstraints::::create_role_type_constraintMoose::Util::TypeConstraints::create_role_type_constraint
3444146µs17.8msMoose::Util::TypeConstraints::::find_or_create_isa_type_constraintMoose::Util::TypeConstraints::find_or_create_isa_type_constraint (recurses: max depth 2, inclusive time 861µs)
4611118µs155µsMoose::Util::TypeConstraints::::normalize_type_constraint_nameMoose::Util::TypeConstraints::normalize_type_constraint_name
2811110µs567µsMoose::Util::TypeConstraints::::_detect_parameterized_type_constraintMoose::Util::TypeConstraints::_detect_parameterized_type_constraint
161194µs7.30msMoose::Util::TypeConstraints::::subtypeMoose::Util::TypeConstraints::subtype
121164µs9.75msMoose::Util::TypeConstraints::::find_or_create_does_type_constraintMoose::Util::TypeConstraints::find_or_create_does_type_constraint
754163µs63µsMoose::Util::TypeConstraints::::CORE:matchMoose::Util::TypeConstraints::CORE:match (opcode)
461137µs37µsMoose::Util::TypeConstraints::::CORE:substMoose::Util::TypeConstraints::CORE:subst (opcode)
161126µs26µsMoose::Util::TypeConstraints::::asMoose::Util::TypeConstraints::as
21120µs1.63msMoose::Util::TypeConstraints::::create_parameterized_type_constraintMoose::Util::TypeConstraints::create_parameterized_type_constraint (recurses: max depth 1, inclusive time 783µs)
21116µs163µsMoose::Util::TypeConstraints::::_parse_parameterized_type_constraintMoose::Util::TypeConstraints::_parse_parameterized_type_constraint
161115µs15µsMoose::Util::TypeConstraints::::whereMoose::Util::TypeConstraints::where
21112µs1.45msMoose::Util::TypeConstraints::::_create_parameterized_type_constraintMoose::Util::TypeConstraints::_create_parameterized_type_constraint (recurses: max depth 1, inclusive time 763µs)
171110µs10µsMoose::Util::TypeConstraints::::inline_asMoose::Util::TypeConstraints::inline_as
1119µs23µsMoose::Util::TypeConstraints::::BEGIN@674Moose::Util::TypeConstraints::BEGIN@674
1118µs700µsMoose::Util::TypeConstraints::::typeMoose::Util::TypeConstraints::type
1118µs12µsMoose::Util::TypeConstraints::::BEGIN@685Moose::Util::TypeConstraints::BEGIN@685
101018µs8µsMoose::Util::TypeConstraints::::CORE:qrMoose::Util::TypeConstraints::CORE:qr (opcode)
1117µs17µsMoose::Util::TypeConstraints::::BEGIN@62Moose::Util::TypeConstraints::BEGIN@62
1116µs6µsMoose::Util::TypeConstraints::::BEGIN@4Moose::Util::TypeConstraints::BEGIN@4
1116µs12µsMoose::Util::TypeConstraints::::BEGIN@680Moose::Util::TypeConstraints::BEGIN@680
1116µs6µsMoose::Util::TypeConstraints::::BEGIN@32Moose::Util::TypeConstraints::BEGIN@32
1116µs124µsMoose::Util::TypeConstraints::::BEGIN@36Moose::Util::TypeConstraints::BEGIN@36
1116µs6µsMoose::Util::TypeConstraints::::list_all_type_constraintsMoose::Util::TypeConstraints::list_all_type_constraints
1115µs10µsMoose::Util::TypeConstraints::::BEGIN@699Moose::Util::TypeConstraints::BEGIN@699
1115µs15µsMoose::Util::TypeConstraints::::BEGIN@6Moose::Util::TypeConstraints::BEGIN@6
1114µs10µsMoose::Util::TypeConstraints::::BEGIN@7Moose::Util::TypeConstraints::BEGIN@7
1114µs20µsMoose::Util::TypeConstraints::::BEGIN@5Moose::Util::TypeConstraints::BEGIN@5
1114µs461µsMoose::Util::TypeConstraints::::class_typeMoose::Util::TypeConstraints::class_type
1113µs3µsMoose::Util::TypeConstraints::::BEGIN@24Moose::Util::TypeConstraints::BEGIN@24
1113µs3µsMoose::Util::TypeConstraints::::BEGIN@27Moose::Util::TypeConstraints::BEGIN@27
1113µs3µsMoose::Util::TypeConstraints::::BEGIN@33Moose::Util::TypeConstraints::BEGIN@33
2112µs2µsMoose::Util::TypeConstraints::::get_all_parameterizable_typesMoose::Util::TypeConstraints::get_all_parameterizable_types
0000s0sMoose::Util::TypeConstraints::::__ANON__[:661]Moose::Util::TypeConstraints::__ANON__[:661]
0000s0sMoose::Util::TypeConstraints::::__ANON__[:663]Moose::Util::TypeConstraints::__ANON__[:663]
0000s0sMoose::Util::TypeConstraints::::__ANON__[:665]Moose::Util::TypeConstraints::__ANON__[:665]
0000s0sMoose::Util::TypeConstraints::::__ANON__[:67]Moose::Util::TypeConstraints::__ANON__[:67]
0000s0sMoose::Util::TypeConstraints::::_confessMoose::Util::TypeConstraints::_confess
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_type_constraint_unionMoose::Util::TypeConstraints::_parse_type_constraint_union
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_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_type_constraintMoose::Util::TypeConstraints::find_or_create_type_constraint
0000s0sMoose::Util::TypeConstraints::::fromMoose::Util::TypeConstraints::from
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::::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
1package Moose::Util::TypeConstraints;
21400nsour $VERSION = '2.1605';
3
4217µs16µs
# spent 6µs within Moose::Util::TypeConstraints::BEGIN@4 which was called: # once (6µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 4
use Carp ();
# spent 6µs making 1 call to Moose::Util::TypeConstraints::BEGIN@4
5215µs236µs
# spent 20µs (4+16) within Moose::Util::TypeConstraints::BEGIN@5 which was called: # once (4µs+16µs) by Moose::Meta::Attribute::BEGIN@16 at line 5
use Scalar::Util qw( blessed );
# spent 20µs making 1 call to Moose::Util::TypeConstraints::BEGIN@5 # spent 16µs making 1 call to Exporter::import
6213µs226µs
# spent 15µs (5+10) within Moose::Util::TypeConstraints::BEGIN@6 which was called: # once (5µs+10µs) by Moose::Meta::Attribute::BEGIN@16 at line 6
use Moose::Exporter;
# spent 15µs making 1 call to Moose::Util::TypeConstraints::BEGIN@6 # spent 10µs making 1 call to Moose::Exporter::import
7231µs215µs
# spent 10µs (4+5) within Moose::Util::TypeConstraints::BEGIN@7 which was called: # once (4µs+5µs) by Moose::Meta::Attribute::BEGIN@16 at line 7
use Moose::Deprecated;
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!
17sub where (&);
18sub via (&);
19sub message (&);
20sub inline_as (&);
21
22## --------------------------------------------------------
23
2423.76ms13µs
# spent 3µs within Moose::Util::TypeConstraints::BEGIN@24 which was called: # once (3µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 24
use Moose::Meta::TypeConstraint;
# spent 3µs making 1 call to Moose::Util::TypeConstraints::BEGIN@24
252120µs12.85ms
# spent 2.85ms (747µs+2.10) within Moose::Util::TypeConstraints::BEGIN@25 which was called: # once (747µs+2.10ms) by Moose::Meta::Attribute::BEGIN@16 at line 25
use Moose::Meta::TypeConstraint::Union;
# spent 2.85ms making 1 call to Moose::Util::TypeConstraints::BEGIN@25
26291µs13.52ms
# spent 3.52ms (459µs+3.06) within Moose::Util::TypeConstraints::BEGIN@26 which was called: # once (459µs+3.06ms) by Moose::Meta::Attribute::BEGIN@16 at line 26
use Moose::Meta::TypeConstraint::Parameterized;
# spent 3.52ms making 1 call to Moose::Util::TypeConstraints::BEGIN@26
27214µs13µs
# spent 3µs within Moose::Util::TypeConstraints::BEGIN@27 which was called: # once (3µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 27
use Moose::Meta::TypeConstraint::Parameterizable;
# spent 3µs making 1 call to Moose::Util::TypeConstraints::BEGIN@27
28299µs11.55ms
# spent 1.55ms (556µs+990µs) within Moose::Util::TypeConstraints::BEGIN@28 which was called: # once (556µs+990µs) by Moose::Meta::Attribute::BEGIN@16 at line 28
use Moose::Meta::TypeConstraint::Class;
# spent 1.55ms making 1 call to Moose::Util::TypeConstraints::BEGIN@28
29288µs11.10ms
# spent 1.10ms (442µs+657µs) within Moose::Util::TypeConstraints::BEGIN@29 which was called: # once (442µs+657µs) by Moose::Meta::Attribute::BEGIN@16 at line 29
use Moose::Meta::TypeConstraint::Role;
# spent 1.10ms making 1 call to Moose::Util::TypeConstraints::BEGIN@29
30278µs11.38ms
# spent 1.38ms (466µs+913µs) within Moose::Util::TypeConstraints::BEGIN@30 which was called: # once (466µs+913µs) by Moose::Meta::Attribute::BEGIN@16 at line 30
use Moose::Meta::TypeConstraint::Enum;
# spent 1.38ms making 1 call to Moose::Util::TypeConstraints::BEGIN@30
31275µs11.22ms
# spent 1.22ms (546µs+675µs) within Moose::Util::TypeConstraints::BEGIN@31 which was called: # once (546µs+675µs) by Moose::Meta::Attribute::BEGIN@16 at line 31
use Moose::Meta::TypeConstraint::DuckType;
# spent 1.22ms making 1 call to Moose::Util::TypeConstraints::BEGIN@31
32216µs16µs
# spent 6µs within Moose::Util::TypeConstraints::BEGIN@32 which was called: # once (6µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 32
use Moose::Meta::TypeCoercion;
# spent 6µs making 1 call to Moose::Util::TypeConstraints::BEGIN@32
33212µs13µs
# spent 3µs within Moose::Util::TypeConstraints::BEGIN@33 which was called: # once (3µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 33
use Moose::Meta::TypeCoercion::Union;
# spent 3µs making 1 call to Moose::Util::TypeConstraints::BEGIN@33
34283µs15.92ms
# spent 5.92ms (439µs+5.48) within Moose::Util::TypeConstraints::BEGIN@34 which was called: # once (439µs+5.48ms) by Moose::Meta::Attribute::BEGIN@16 at line 34
use Moose::Meta::TypeConstraint::Registry;
# spent 5.92ms making 1 call to Moose::Util::TypeConstraints::BEGIN@34
35
36277µs2243µs
# spent 124µs (6+119) within Moose::Util::TypeConstraints::BEGIN@36 which was called: # once (6µs+119µs) by Moose::Meta::Attribute::BEGIN@16 at line 36
use Moose::Util 'throw_exception';
# spent 124µs making 1 call to Moose::Util::TypeConstraints::BEGIN@36 # spent 119µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337]
37
3815µs1622µsMoose::Exporter->setup_import_methods(
# spent 622µs making 1 call to 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
5512µs1223µsmy $REGISTRY = Moose::Meta::TypeConstraint::Registry->new;
# spent 223µs making 1 call to Moose::Meta::TypeConstraint::Registry::new
56
57sub get_type_constraint_registry {$REGISTRY}
5814µs1300ns
# spent 6µs (6+300ns) within Moose::Util::TypeConstraints::list_all_type_constraints which was called: # once (6µs+300ns) by Moose::Meta::Attribute::BEGIN@16 at line 753
sub list_all_type_constraints { keys %{ $REGISTRY->type_constraints } }
59
60sub export_type_constraints_as_functions {
61 my $pkg = caller();
6221.47ms228µs
# spent 17µs (7+10) within Moose::Util::TypeConstraints::BEGIN@62 which was called: # once (7µs+10µs) by Moose::Meta::Attribute::BEGIN@16 at line 62
no strict 'refs';
# spent 17µs making 1 call to Moose::Util::TypeConstraints::BEGIN@62 # spent 10µs making 1 call to strict::unimport
63 foreach my $constraint ( keys %{ $REGISTRY->type_constraints } ) {
64 my $tc = $REGISTRY->get_type_constraint($constraint)
65 ->_compiled_type_constraint;
66 *{"${pkg}::${constraint}"}
67 = sub { $tc->( $_[0] ) ? 1 : undef }; # the undef is for compat
68 }
69}
70
71sub create_type_constraint_union {
72 _create_type_constraint_union(\@_);
73}
74
75sub create_named_type_constraint_union {
76 my $name = shift;
77 _create_type_constraint_union($name, \@_);
78}
79
80sub _create_type_constraint_union {
81 my $name;
82 $name = shift if @_ > 1;
83 my @tcs = @{ shift() };
84
85 my @type_constraint_names;
86
87 if ( scalar @tcs == 1 && _detect_type_constraint_union( $tcs[0] ) ) {
88 @type_constraint_names = _parse_type_constraint_union( $tcs[0] );
89 }
90 else {
91 @type_constraint_names = @tcs;
92 }
93
94 ( scalar @type_constraint_names >= 2 )
95 || throw_exception("UnionTakesAtleastTwoTypeNames");
96
97 my @type_constraints = map {
98 find_or_parse_type_constraint($_)
99 || throw_exception( CouldNotLocateTypeConstraintForUnion => type_name => $_ );
100 } @type_constraint_names;
101
102 my %options = (
103 type_constraints => \@type_constraints
104 );
105 $options{name} = $name if defined $name;
106
107 return Moose::Meta::TypeConstraint::Union->new(%options);
108}
109
110
111
# spent 1.63ms (20µs+1.61) within Moose::Util::TypeConstraints::create_parameterized_type_constraint which was called 2 times, avg 813µs/call: # 2 times (20µs+1.61ms) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 260, avg 813µs/call
sub create_parameterized_type_constraint {
1122500ns my $type_constraint_name = shift;
11323µs2163µs my ( $base_type, $type_parameter )
# spent 163µs making 2 calls to Moose::Util::TypeConstraints::_parse_parameterized_type_constraint, avg 81µs/call
114 = _parse_parameterized_type_constraint($type_constraint_name);
115
1162900ns ( defined $base_type && defined $type_parameter )
117 || throw_exception( InvalidTypeGivenToCreateParameterizedTypeConstraint => type_name => $type_constraint_name );
118
11922µs26µs if ( $REGISTRY->has_type_constraint($base_type) ) {
# spent 6µs making 2 calls to Moose::Meta::TypeConstraint::Registry::has_type_constraint, avg 3µs/call
12022µs26µs my $base_type_tc = $REGISTRY->get_type_constraint($base_type);
# spent 6µs making 2 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 3µs/call
12126µs21.45ms return _create_parameterized_type_constraint(
# spent 2.21ms making 2 calls to Moose::Util::TypeConstraints::_create_parameterized_type_constraint, avg 1.11ms/call, recursion: max depth 1, sum of overlapping time 763µs
122 $base_type_tc,
123 $type_parameter
124 );
125 }
126 else {
127 throw_exception( InvalidBaseTypeGivenToCreateParameterizedTypeConstraint => type_name => $base_type );
128 }
129}
130
131
# spent 1.45ms (12µs+1.44) within Moose::Util::TypeConstraints::_create_parameterized_type_constraint which was called 2 times, avg 725µs/call: # 2 times (12µs+1.44ms) by Moose::Util::TypeConstraints::create_parameterized_type_constraint at line 121, avg 725µs/call
sub _create_parameterized_type_constraint {
1322500ns my ( $base_type_tc, $type_parameter ) = @_;
133214µs41.44ms if ( $base_type_tc->can('parameterize') ) {
# spent 2.20ms making 2 calls to Moose::Meta::TypeConstraint::Parameterizable::parameterize, avg 1.10ms/call, recursion: max depth 1, sum of overlapping time 758µs # spent 1µs making 2 calls to UNIVERSAL::can, avg 700ns/call
134 return $base_type_tc->parameterize($type_parameter);
135 }
136 else {
137 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
# spent 14.8ms (251µs+14.6) within Moose::Util::TypeConstraints::create_class_type_constraint which was called 15 times, avg 987µs/call: # 14 times (234µs+14.1ms) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 246, avg 1.02ms/call # once (17µs+440µs) by Moose::Util::TypeConstraints::class_type at line 352
sub create_class_type_constraint {
148158µs 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
1541514µs my $pkg_defined_in = $options->{package_defined_in} || scalar( caller(1) );
155
1561525µs1560µs if (my $type = $REGISTRY->get_type_constraint($class)) {
# spent 60µs making 15 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 4µs/call
157 if (!($type->isa('Moose::Meta::TypeConstraint::Class') && $type->class eq $class)) {
158 throw_exception( TypeConstraintIsAlreadyCreated => package_defined_in => $pkg_defined_in,
159 type_name => $type->name,
160 );
161 }
162 else {
163 return $type;
164 }
165 }
166
167 my %options = (
168 class => $class,
169 name => $class,
170 package_defined_in => $pkg_defined_in,
1711544µs %{ $options || {} }, # overrides options from above
172 );
173
174158µs $options{name} ||= "__ANON__";
175
1761552µs1514.2ms my $tc = Moose::Meta::TypeConstraint::Class->new(%options);
# spent 14.2ms making 15 calls to Moose::Meta::TypeConstraint::Class::new, avg 950µs/call
1771526µs15249µs $REGISTRY->add_type_constraint($tc);
# spent 249µs making 15 calls to Moose::Meta::TypeConstraint::Registry::add_type_constraint, avg 17µs/call
1781541µs return $tc;
179}
180
181
# spent 9.22ms (173µs+9.05) within Moose::Util::TypeConstraints::create_role_type_constraint which was called 12 times, avg 768µs/call: # 12 times (173µs+9.05ms) by Moose::Util::TypeConstraints::find_or_create_does_type_constraint at line 252, avg 768µs/call
sub create_role_type_constraint {
182125µs 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
1881213µs my $pkg_defined_in = $options->{package_defined_in} || scalar( caller(1) );
189
1901218µs1241µs if (my $type = $REGISTRY->get_type_constraint($role)) {
# spent 41µs making 12 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 3µs/call
191 if (!($type->isa('Moose::Meta::TypeConstraint::Role') && $type->role eq $role)) {
192 throw_exception( TypeConstraintIsAlreadyCreated => type_name => $type->name,
193 package_defined_in => $pkg_defined_in
194 );
195 }
196 else {
197 return $type;
198 }
199 }
200
201 my %options = (
202 role => $role,
203 name => $role,
204 package_defined_in => $pkg_defined_in,
2051231µs %{ $options || {} },
206 );
207
208125µs $options{name} ||= "__ANON__";
209
2101236µs128.83ms my $tc = Moose::Meta::TypeConstraint::Role->new(%options);
# spent 8.83ms making 12 calls to Moose::Meta::TypeConstraint::Role::new, avg 736µs/call
2111216µs12178µs $REGISTRY->add_type_constraint($tc);
# spent 178µs making 12 calls to Moose::Meta::TypeConstraint::Registry::add_type_constraint, avg 15µs/call
2121232µs return $tc;
213}
214
215sub find_or_create_type_constraint {
216 my ( $type_constraint_name, $options_for_anon_type ) = @_;
217
218 if ( my $constraint
219 = find_or_parse_type_constraint($type_constraint_name) ) {
220 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 %{$options_for_anon_type}
238 );
239 }
240
241 return;
242}
243
244
# spent 17.8ms (146µs+17.7) within Moose::Util::TypeConstraints::find_or_create_isa_type_constraint which was called 34 times, avg 523µs/call: # 16 times (51µs+254µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 572, avg 19µs/call # 12 times (64µs+14.1ms) by Moo::HandleMoose::inject_fake_metaclass_for at line 47 of Moo/HandleMoose.pm, avg 1.18ms/call # 4 times (20µs+3.31ms) by Moose::Meta::Attribute::_process_isa_option at line 349 of Moose/Meta/Attribute.pm, avg 833µs/call # 2 times (10µs+-10µs) by Moose::Meta::TypeConstraint::Parameterizable::_parse_type_parameter at line 67 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 0s/call
sub find_or_create_isa_type_constraint {
2453410µs my ($type_constraint_name, $options) = @_;
24634111µs6817.7ms find_or_parse_type_constraint($type_constraint_name)
# spent 14.3ms making 14 calls to Moose::Util::TypeConstraints::create_class_type_constraint, avg 1.02ms/call # spent 4.16ms making 34 calls to Moose::Util::TypeConstraints::find_or_parse_type_constraint, avg 122µs/call, recursion: max depth 2, sum of overlapping time 850µs # spent 4µs making 20 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 210ns/call
247 || create_class_type_constraint($type_constraint_name, $options);
248}
249
250
# spent 9.75ms (64µs+9.69) within Moose::Util::TypeConstraints::find_or_create_does_type_constraint which was called 12 times, avg 813µs/call: # 12 times (64µs+9.69ms) by Moo::HandleMoose::inject_fake_metaclass_for at line 44 of Moo/HandleMoose.pm, avg 813µs/call
sub find_or_create_does_type_constraint {
251125µs my ($type_constraint_name, $options) = @_;
2521252µs249.69ms find_or_parse_type_constraint($type_constraint_name)
# spent 9.22ms making 12 calls to Moose::Util::TypeConstraints::create_role_type_constraint, avg 768µs/call # spent 470µs making 12 calls to Moose::Util::TypeConstraints::find_or_parse_type_constraint, avg 39µs/call
253 || create_role_type_constraint($type_constraint_name, $options);
254}
255
256
# spent 3.78ms (328µs+3.45) within Moose::Util::TypeConstraints::find_or_parse_type_constraint which was called 46 times, avg 82µs/call: # 34 times (232µs+3.08ms) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 246, avg 97µs/call # 12 times (96µs+374µs) by Moose::Util::TypeConstraints::find_or_create_does_type_constraint at line 252, avg 39µs/call
sub find_or_parse_type_constraint {
2574653µs46155µs my $type_constraint_name = normalize_type_constraint_name(shift);
# spent 155µs making 46 calls to Moose::Util::TypeConstraints::normalize_type_constraint_name, avg 3µs/call
258465µs my $constraint;
259
26046155µs1223.34ms if ( $constraint = find_type_constraint($type_constraint_name) ) {
# spent 2.41ms making 2 calls to Moose::Util::TypeConstraints::create_parameterized_type_constraint, avg 1.20ms/call, recursion: max depth 1, sum of overlapping time 783µs # spent 689µs making 28 calls to Moose::Util::TypeConstraints::_detect_type_constraint_union, avg 25µs/call # spent 567µs making 28 calls to Moose::Util::TypeConstraints::_detect_parameterized_type_constraint, avg 20µs/call # spent 451µs making 46 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 10µs/call # spent 8µs making 18 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 417ns/call
261 return $constraint;
262 }
263 elsif ( _detect_type_constraint_union($type_constraint_name) ) {
264 $constraint = create_type_constraint_union($type_constraint_name);
265 }
266 elsif ( _detect_parameterized_type_constraint($type_constraint_name) ) {
267 $constraint
268 = create_parameterized_type_constraint($type_constraint_name);
269 }
270 else {
2712646µs return;
272 }
273
27422µs226µs $REGISTRY->add_type_constraint($constraint);
# spent 26µs making 2 calls to Moose::Meta::TypeConstraint::Registry::add_type_constraint, avg 13µs/call
27523µs return $constraint;
276}
277
278
# spent 155µs (118+37) within Moose::Util::TypeConstraints::normalize_type_constraint_name which was called 46 times, avg 3µs/call: # 46 times (118µs+37µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 257, avg 3µs/call
sub normalize_type_constraint_name {
2794612µs my $type_constraint_name = shift;
28046101µs4637µs $type_constraint_name =~ s/\s//g;
# spent 37µs making 46 calls to Moose::Util::TypeConstraints::CORE:subst, avg 811ns/call
2814664µs return $type_constraint_name;
282}
283
284sub _confess {
285 my $error = shift;
286
287 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
288 Carp::confess($error);
289}
290
291## --------------------------------------------------------
292## exported functions ...
293## --------------------------------------------------------
294
295
# spent 878µs (419+459) within Moose::Util::TypeConstraints::find_type_constraint which was called 107 times, avg 8µs/call: # 46 times (200µs+251µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 260, avg 10µs/call # 21 times (46µs+13µs) by Moose::Meta::TypeConstraint::equals at line 234 of Moose/Meta/TypeConstraint.pm, avg 3µs/call # 15 times (69µs+75µs) by Moose::Meta::TypeConstraint::Class::new at line 31 of Moose/Meta/TypeConstraint/Class.pm, avg 10µs/call # 12 times (50µs+55µs) by Moose::Meta::TypeConstraint::Role::new at line 32 of Moose/Meta/TypeConstraint/Role.pm, avg 9µs/call # 7 times (27µs+35µs) by Moose::Meta::TypeConstraint::is_subtype_of at line 263 of Moose/Meta/TypeConstraint.pm, avg 9µs/call # once (7µs+8µs) by Moose::init_meta at line 161 of Moose.pm # once (4µs+5µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 198 of Moose/Util/TypeConstraints/Builtins.pm # once (4µs+5µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 79 of Moose/Util/TypeConstraints/Builtins.pm # once (4µs+4µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 233 of Moose/Util/TypeConstraints/Builtins.pm # once (4µs+4µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 294 of Moose/Util/TypeConstraints/Builtins.pm # once (4µs+4µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 268 of Moose/Util/TypeConstraints/Builtins.pm
sub find_type_constraint {
29610719µs my $type = shift;
297
298107194µs12836µs if ( blessed $type and $type->isa("Moose::Meta::TypeConstraint") ) {
# spent 30µs making 107 calls to Scalar::Util::blessed, avg 279ns/call # spent 6µs making 21 calls to UNIVERSAL::isa, avg 310ns/call
299 return $type;
300 }
301 else {
30286126µs86305µs return unless $REGISTRY->has_type_constraint($type);
# spent 305µs making 86 calls to Moose::Meta::TypeConstraint::Registry::has_type_constraint, avg 4µs/call
30357104µs57117µs return $REGISTRY->get_type_constraint($type);
# spent 117µs making 57 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 2µs/call
304 }
305}
306
307sub register_type_constraint {
308 my $constraint = shift;
309 throw_exception( CannotRegisterUnnamedTypeConstraint => type => $constraint )
310 unless defined $constraint->name;
311 $REGISTRY->add_type_constraint($constraint);
312 return $constraint;
313}
314
315# type constructors
316
317
# spent 700µs (8+692) within Moose::Util::TypeConstraints::type which was called: # once (8µs+692µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 11 of Moose/Util/TypeConstraints/Builtins.pm
sub type {
3181400ns my $name = shift;
319
32013µs my %p = map { %{$_} } @_;
321
322 return _create_type_constraint(
323 $name, undef, $p{where}, $p{message},
324 $p{inline_as},
32514µs1692µs );
326}
327
328
# spent 7.30ms (94µs+7.20) within Moose::Util::TypeConstraints::subtype which was called 16 times, avg 456µs/call: # 16 times (94µs+7.20ms) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 12 of Moose/Util/TypeConstraints/Builtins.pm, avg 456µs/call
sub subtype {
329165µs if ( @_ == 1 && !ref $_[0] ) {
330 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.
335166µs my $name = ref $_[0] && !blessed $_[0] ? undef : shift;
336
3371645µs my %p = map { %{$_} } @_;
338
339 # subtype Str => where { ... };
340164µs if ( !exists $p{as} ) {
341 $p{as} = $name;
342 $name = undef;
343 }
344
345 return _create_type_constraint(
346 $name, $p{as}, $p{where}, $p{message},
347 $p{inline_as},
3481638µs167.20ms );
# spent 7.20ms making 16 calls to Moose::Util::TypeConstraints::_create_type_constraint, avg 450µs/call
349}
350
351
# spent 461µs (4+458) within Moose::Util::TypeConstraints::class_type which was called: # once (4µs+458µs) by Moose::init_meta at line 161 of Moose.pm
sub class_type {
35213µs1458µs create_class_type_constraint(@_);
353}
354
355sub role_type ($;$) {
356 create_role_type_constraint(@_);
357}
358
359sub maybe_type {
360 my ($type_parameter) = @_;
361
362 register_type_constraint(
363 $REGISTRY->get_type_constraint('Maybe')->parameterize($type_parameter)
364 );
365}
366
367sub duck_type {
368 my ( $type_name, @methods ) = @_;
369 if ( ref $type_name eq 'ARRAY' && !@methods ) {
370 @methods = ($type_name);
371 $type_name = undef;
372 }
373 if ( @methods == 1 && ref $methods[0] eq 'ARRAY' ) {
374 @methods = @{ $methods[0] };
375 }
376 else {
377 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 register_type_constraint(
385 create_duck_type_constraint(
386 $type_name,
387 \@methods,
388 )
389 );
390}
391
392sub coerce {
393 my ( $type_name, @coercion_map ) = @_;
394 _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.
4101636µs
# spent 26µs within Moose::Util::TypeConstraints::as which was called 16 times, avg 2µs/call: # 16 times (26µs+0s) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 13 of Moose/Util/TypeConstraints/Builtins.pm, avg 2µs/call
sub as { { as => shift }, @_ }
4111624µs
# spent 15µs within Moose::Util::TypeConstraints::where which was called 16 times, avg 944ns/call: # 16 times (15µs+0s) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 14 of Moose/Util/TypeConstraints/Builtins.pm, avg 944ns/call
sub where (&) { { where => $_[0] } }
412sub message (&) { { message => $_[0] } }
4131722µs
# spent 10µs within Moose::Util::TypeConstraints::inline_as which was called 17 times, avg 612ns/call: # 17 times (10µs+0s) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 15 of Moose/Util/TypeConstraints/Builtins.pm, avg 612ns/call
sub inline_as (&) { { inline_as => $_[0] } }
414
415sub from {@_}
416sub via (&) { $_[0] }
417
418sub enum {
419 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 if ( ref $type_name eq 'ARRAY' ) {
426 @values == 0
427 || throw_exception( EnumCalledWithAnArrayRefAndAdditionalArgs => array => $type_name,
428 args => \@values
429 );
430 @values = ($type_name);
431 $type_name = undef;
432 }
433 if ( @values == 1 && ref $values[0] eq 'ARRAY' ) {
434 @values = @{ $values[0] };
435 }
436 else {
437 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 register_type_constraint(
445 create_enum_type_constraint(
446 $type_name,
447 \@values,
448 )
449 );
450}
451
452sub union {
453 my ( $type_name, @constraints ) = @_;
454 if ( ref $type_name eq 'ARRAY' ) {
455 @constraints == 0
456 || throw_exception( UnionCalledWithAnArrayRefAndAdditionalArgs => array => $type_name,
457 args => \@constraints
458 );
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 || throw_exception( DefaultToMatchOnTypeMustBeCodeRef => to_match => $to_match,
498 default_action => $default,
499 cases_to_be_matched => \@cases
500 );
501 }
502 while (@cases) {
503 my ($type, $action) = splice @cases, 0, 2;
504
505 unless (blessed $type && $type->isa('Moose::Meta::TypeConstraint')) {
506 $type = find_or_parse_type_constraint($type)
507 || throw_exception( CannotFindTypeGivenToMatchOnType => type => $type,
508 to_match => $to_match,
509 action => $action
510 );
511 }
512
513 (ref $action eq 'CODE')
514 || throw_exception( MatchActionMustBeACodeRef => type_name => $type->name,
515 action => $action,
516 to_match => $to_match
517 );
518
519 if ($type->check($to_match)) {
520 local $_ = $to_match;
521 return $action->($to_match);
522 }
523 }
524 (defined $default)
525 || throw_exception( NoCasesMatched => to_match => $to_match,
526 cases_to_be_matched => \@cases
527 );
528 {
529 local $_ = $to_match;
530 return $default->($to_match);
531 }
532}
533
534
535## --------------------------------------------------------
536## desugaring functions ...
537## --------------------------------------------------------
538
539
# spent 7.90ms (234µs+7.66) within Moose::Util::TypeConstraints::_create_type_constraint which was called 17 times, avg 464µs/call: # 16 times (211µs+6.99ms) by Moose::Util::TypeConstraints::subtype at line 348, avg 450µs/call # once (23µs+670µs) by Moose::Util::TypeConstraints::type at line 325
sub _create_type_constraint ($$$;$) {
540173µs my $name = shift;
541171µs my $parent = shift;
542172µs my $check = shift;
543177µs my $message = shift;
544172µs my $inlined = shift;
545
546178µs my $pkg_defined_in = scalar( caller(1) );
547
548175µs if ( defined $name ) {
5491714µs1750µs my $type = $REGISTRY->get_type_constraint($name);
# spent 50µs making 17 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 3µs/call
550
551172µs ( $type->_package_defined_in eq $pkg_defined_in )
552 || throw_exception( TypeConstraintIsAlreadyCreated => package_defined_in => $pkg_defined_in,
553 type_name => $type->name,
554 )
555 if defined $type;
556
5571747µs1724µs if( $name !~ /^[\w:\.]+$/ ) {
# spent 24µs making 17 calls to Moose::Util::TypeConstraints::CORE:match, avg 1µs/call
558 throw_exception( InvalidNameForType => name => $name );
559 }
560 }
561
5621722µs my %opts = (
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
571171µs my $constraint;
5721760µs646.77ms if (
# spent 6.46ms making 16 calls to Moose::Meta::TypeConstraint::create_child_type, avg 404µs/call # spent 305µs making 16 calls to Moose::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 19µs/call # spent 4µs making 16 calls to Scalar::Util::blessed, avg 256ns/call # spent 3µs making 16 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 200ns/call
573 defined $parent
574 and $parent
575 = blessed $parent
576 ? $parent
577 : find_or_create_isa_type_constraint($parent)
578 ) {
579 $constraint = $parent->create_child_type(%opts);
580 }
581 else {
58213µs1638µs $constraint = Moose::Meta::TypeConstraint->new(%opts);
# spent 638µs making 1 call to Moose::Meta::TypeConstraint::new
583 }
584
5851714µs17177µs $REGISTRY->add_type_constraint($constraint)
# spent 177µs making 17 calls to Moose::Meta::TypeConstraint::Registry::add_type_constraint, avg 10µs/call
586 if defined $name;
587
5881728µs return $constraint;
589}
590
591sub _install_type_coercions ($$) {
592 my ( $type_name, $coercion_map ) = @_;
593 my $type = find_type_constraint($type_name);
594 ( defined $type )
595 || throw_exception( CannotFindType => type_name => $type_name );
596
597 if ( $type->has_coercion ) {
598 $type->coercion->add_type_coercions(@$coercion_map);
599 }
600 else {
601 my $type_coercion = Moose::Meta::TypeCoercion->new(
602 type_coercion_map => $coercion_map,
603 type_constraint => $type
604 );
605 $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
6212241µs21.07ms
# spent 1.06ms (880µs+180µs) within Moose::Util::TypeConstraints::BEGIN@621 which was called: # once (880µs+180µs) by Moose::Meta::Attribute::BEGIN@16 at line 621
use re "eval";
# spent 1.06ms making 1 call to Moose::Util::TypeConstraints::BEGIN@621 # spent 10µs making 1 call to re::import
622
62315µs12µs my $valid_chars = qr{[\w:\.]};
# spent 2µs making 1 call to Moose::Util::TypeConstraints::CORE:qr
624180µs273µs my $type_atom = qr{ (?>$valid_chars+) }x;
# spent 72µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 600ns making 1 call to Moose::Util::TypeConstraints::CORE:qr
62512µs1600ns my $ws = qr{ (?>\s*) }x;
# spent 600ns making 1 call to Moose::Util::TypeConstraints::CORE:qr
626112µs29µs my $op_union = qr{ $ws \| $ws }x;
# spent 9µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 500ns making 1 call to Moose::Util::TypeConstraints::CORE:qr
627
6281200ns my ($type, $type_capture_parts, $type_with_parameter, $union, $any);
62912µs if (Class::MOP::IS_RUNNING_ON_5_10) {
6301200ns my $type_pattern
631 = q{ (?&type_atom) (?: \[ (?&ws) (?&any) (?&ws) \] )? };
6321100ns my $type_capture_parts_pattern
633 = q{ ((?&type_atom)) (?: \[ (?&ws) ((?&any)) (?&ws) \] )? };
6341100ns my $type_with_parameter_pattern
635 = q{ (?&type_atom) \[ (?&ws) (?&any) (?&ws) \] };
6361100ns my $union_pattern
637 = q{ (?&type) (?> (?: (?&op_union) (?&type) )+ ) };
6381200ns my $any_pattern
639 = q{ (?&type) | (?&union) };
640
641151µs247µs my $defines = qr{(?(DEFINE)
# spent 47µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 400ns making 1 call to Moose::Util::TypeConstraints::CORE:qr
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
6531104µs297µs $type = qr{ $type_pattern $defines }x;
# spent 97µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 500ns making 1 call to Moose::Util::TypeConstraints::CORE:qr
654191µs284µs $type_capture_parts = qr{ $type_capture_parts_pattern $defines }x;
# spent 83µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 400ns making 1 call to Moose::Util::TypeConstraints::CORE:qr
6551107µs290µs $type_with_parameter = qr{ $type_with_parameter_pattern $defines }x;
# spent 89µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 1µs making 1 call to Moose::Util::TypeConstraints::CORE:qr
6561100µs284µs $union = qr{ $union_pattern $defines }x;
# spent 84µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 500ns making 1 call to Moose::Util::TypeConstraints::CORE:qr
6571293µs2286µs $any = qr{ $any_pattern $defines }x;
# spent 286µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 600ns making 1 call to Moose::Util::TypeConstraints::CORE:qr
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
# spent 163µs (16+147) within Moose::Util::TypeConstraints::_parse_parameterized_type_constraint which was called 2 times, avg 81µs/call: # 2 times (16µs+147µs) by Moose::Util::TypeConstraints::create_parameterized_type_constraint at line 113, avg 81µs/call
sub _parse_parameterized_type_constraint {
674646µs236µs
# spent 23µs (9+14) within Moose::Util::TypeConstraints::BEGIN@674 which was called: # once (9µs+14µs) by Moose::Meta::Attribute::BEGIN@16 at line 674
{ no warnings 'void'; $any; } # force capture of interpolated lexical
# spent 23µs making 1 call to Moose::Util::TypeConstraints::BEGIN@674 # spent 14µs making 1 call to warnings::unimport
6752157µs4147µs $_[0] =~ m{ $type_capture_parts }x;
# spent 140µs making 2 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 70µs/call # spent 7µs making 2 calls to Moose::Util::TypeConstraints::CORE:match, avg 4µs/call
67626µs return ( $1, $2 );
677 }
678
679
# spent 567µs (110+457) within Moose::Util::TypeConstraints::_detect_parameterized_type_constraint which was called 28 times, avg 20µs/call: # 28 times (110µs+457µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 260, avg 20µs/call
sub _detect_parameterized_type_constraint {
6805848µs217µs
# spent 12µs (6+6) within Moose::Util::TypeConstraints::BEGIN@680 which was called: # once (6µs+6µs) by Moose::Meta::Attribute::BEGIN@16 at line 680
{ no warnings 'void'; $any; } # force capture of interpolated lexical
# spent 12µs making 1 call to Moose::Util::TypeConstraints::BEGIN@680 # spent 6µs making 1 call to warnings::unimport
68128572µs56457µs $_[0] =~ m{ ^ $type_with_parameter $ }x;
# spent 438µs making 28 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 16µs/call # spent 19µs making 28 calls to Moose::Util::TypeConstraints::CORE:match, avg 679ns/call
682 }
683
684 sub _parse_type_constraint_union {
685259µs218µs
# spent 12µs (8+5) within Moose::Util::TypeConstraints::BEGIN@685 which was called: # once (8µs+5µs) by Moose::Meta::Attribute::BEGIN@16 at line 685
{ no warnings 'void'; $any; } # force capture of interpolated lexical
# spent 12µs making 1 call to Moose::Util::TypeConstraints::BEGIN@685 # spent 5µs making 1 call to warnings::unimport
686 my $given = shift;
687 my @rv;
688 while ( $given =~ m{ \G (?: $op_union )? ($type) }gcx ) {
689 push @rv => $1;
690 }
691 ( pos($given) eq length($given) )
692 || throw_exception( CouldNotParseType => type => $given,
693 position => pos($given)
694 );
695 @rv;
696 }
697
698
# spent 689µs (174+514) within Moose::Util::TypeConstraints::_detect_type_constraint_union which was called 28 times, avg 25µs/call: # 28 times (174µs+514µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 260, avg 25µs/call
sub _detect_type_constraint_union {
69958172µs215µs
# spent 10µs (5+5) within Moose::Util::TypeConstraints::BEGIN@699 which was called: # once (5µs+5µs) by Moose::Meta::Attribute::BEGIN@16 at line 699
{ no warnings 'void'; $any; } # force capture of interpolated lexical
# spent 10µs making 1 call to Moose::Util::TypeConstraints::BEGIN@699 # spent 5µs making 1 call to warnings::unimport
70028683µs56514µs $_[0] =~ m{^ $type $op_union $type ( $op_union .* )? $}x;
# spent 501µs making 28 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 18µs/call # spent 13µs making 28 calls to Moose::Util::TypeConstraints::CORE:match, avg 464ns/call
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.
711181µs$_->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
7171022µs1828.2ms ) for grep { $_->is_mutable }
# spent 28.2ms making 9 calls to Class::MOP::Class::make_immutable, avg 3.13ms/call # spent 2µs making 9 calls to Class::MOP::Class::is_mutable, avg 244ns/call
71894µs917µs map { Class::MOP::class_of($_) }
# spent 17µs making 9 calls to Class::MOP::class_of, avg 2µs/call
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
731179µsrequire Moose::Util::TypeConstraints::Builtins;
73212µs19.04msMoose::Util::TypeConstraints::Builtins::define_builtins($REGISTRY);
733
734my @PARAMETERIZABLE_TYPES
73554µs48µs = map { $REGISTRY->get_type_constraint($_) } qw[ScalarRef ArrayRef HashRef Maybe];
# spent 8µs making 4 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 2µs/call
736
73724µs
# spent 2µs within Moose::Util::TypeConstraints::get_all_parameterizable_types which was called 2 times, avg 1µs/call: # 2 times (2µs+0s) by Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint at line 54 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 1µs/call
sub get_all_parameterizable_types {@PARAMETERIZABLE_TYPES}
738
739sub add_parameterizable_type {
740 my $type = shift;
741 ( blessed $type
742 && $type->isa('Moose::Meta::TypeConstraint::Parameterizable') )
743 || throw_exception( AddParameterizableTypeTakesParameterizableType => type_name => $type );
744
745 push @PARAMETERIZABLE_TYPES => $type;
746}
747
748## --------------------------------------------------------
749# end of built-in types ...
750## --------------------------------------------------------
751
752{
75313µs16µs my @BUILTINS = list_all_type_constraints();
754 sub list_all_builtin_type_constraints {@BUILTINS}
755}
756
757237µs1;
758
759# ABSTRACT: Type constraint system for Moose
760
761__END__
 
# spent 63µs within Moose::Util::TypeConstraints::CORE:match which was called 75 times, avg 845ns/call: # 28 times (19µs+0s) by Moose::Util::TypeConstraints::_detect_parameterized_type_constraint at line 681, avg 679ns/call # 28 times (13µs+0s) by Moose::Util::TypeConstraints::_detect_type_constraint_union at line 700, avg 464ns/call # 17 times (24µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint at line 557, avg 1µs/call # 2 times (7µs+0s) by Moose::Util::TypeConstraints::_parse_parameterized_type_constraint at line 675, avg 4µs/call
sub Moose::Util::TypeConstraints::CORE:match; # opcode
# spent 8µs within Moose::Util::TypeConstraints::CORE:qr which was called 10 times, avg 750ns/call: # once (2µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 623 # once (1µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 655 # once (600ns+0s) by Moose::Meta::Attribute::BEGIN@16 at line 624 # once (600ns+0s) by Moose::Meta::Attribute::BEGIN@16 at line 625 # once (600ns+0s) by Moose::Meta::Attribute::BEGIN@16 at line 657 # once (500ns+0s) by Moose::Meta::Attribute::BEGIN@16 at line 626 # once (500ns+0s) by Moose::Meta::Attribute::BEGIN@16 at line 656 # once (500ns+0s) by Moose::Meta::Attribute::BEGIN@16 at line 653 # once (400ns+0s) by Moose::Meta::Attribute::BEGIN@16 at line 641 # once (400ns+0s) by Moose::Meta::Attribute::BEGIN@16 at line 654
sub Moose::Util::TypeConstraints::CORE:qr; # opcode
# spent 1.85ms within Moose::Util::TypeConstraints::CORE:regcomp which was called 66 times, avg 28µs/call: # 28 times (501µs+0s) by Moose::Util::TypeConstraints::_detect_type_constraint_union at line 700, avg 18µs/call # 28 times (438µs+0s) by Moose::Util::TypeConstraints::_detect_parameterized_type_constraint at line 681, avg 16µs/call # 2 times (140µs+0s) by Moose::Util::TypeConstraints::_parse_parameterized_type_constraint at line 675, avg 70µs/call # once (286µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 657 # once (97µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 653 # once (89µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 655 # once (84µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 656 # once (83µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 654 # once (72µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 624 # once (47µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 641 # once (9µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 626
sub Moose::Util::TypeConstraints::CORE:regcomp; # opcode
# spent 37µs within Moose::Util::TypeConstraints::CORE:subst which was called 46 times, avg 811ns/call: # 46 times (37µs+0s) by Moose::Util::TypeConstraints::normalize_type_constraint_name at line 280, avg 811ns/call
sub Moose::Util::TypeConstraints::CORE:subst; # opcode