← Index
NYTProf Performance Profile   « line view »
For script/ponapi
  Run on Wed Feb 10 15:51:26 2016
Reported on Thu Feb 11 09:43:10 2016

Filename/usr/local/lib/perl/5.18.2/Moose/Util/TypeConstraints.pm
StatementsExecuted 4180 statements in 13.3ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
4511582.75ms5.78msMoose::Util::TypeConstraints::::find_type_constraintMoose::Util::TypeConstraints::find_type_constraint
168521.43ms16.6msMoose::Util::TypeConstraints::::find_or_parse_type_constraintMoose::Util::TypeConstraints::find_or_parse_type_constraint (recurses: max depth 2, inclusive time 970µs)
1111.11ms1.36msMoose::Util::TypeConstraints::::BEGIN@621Moose::Util::TypeConstraints::BEGIN@621
111968µs2.80msMoose::Util::TypeConstraints::::BEGIN@25Moose::Util::TypeConstraints::BEGIN@25
111751µs1.88msMoose::Util::TypeConstraints::::BEGIN@31Moose::Util::TypeConstraints::BEGIN@31
111746µs7.18msMoose::Util::TypeConstraints::::BEGIN@30Moose::Util::TypeConstraints::BEGIN@30
45131738µs738µsMoose::Util::TypeConstraints::::CORE:regcompMoose::Util::TypeConstraints::CORE:regcomp (opcode)
111677µs1.46msMoose::Util::TypeConstraints::::BEGIN@28Moose::Util::TypeConstraints::BEGIN@28
12233641µs7.91msMoose::Util::TypeConstraints::::find_or_create_isa_type_constraintMoose::Util::TypeConstraints::find_or_create_isa_type_constraint (recurses: max depth 1, inclusive time 318µs)
111623µs1.34msMoose::Util::TypeConstraints::::BEGIN@29Moose::Util::TypeConstraints::BEGIN@29
3521601µs23.0msMoose::Util::TypeConstraints::::create_role_type_constraintMoose::Util::TypeConstraints::create_role_type_constraint
111596µs4.27msMoose::Util::TypeConstraints::::BEGIN@26Moose::Util::TypeConstraints::BEGIN@26
3121582µs24.0msMoose::Util::TypeConstraints::::create_class_type_constraintMoose::Util::TypeConstraints::create_class_type_constraint
16811536µs712µsMoose::Util::TypeConstraints::::normalize_type_constraint_nameMoose::Util::TypeConstraints::normalize_type_constraint_name
111451µs2.08msMoose::Util::TypeConstraints::::BEGIN@34Moose::Util::TypeConstraints::BEGIN@34
1721308µs4.66msMoose::Util::TypeConstraints::::_create_type_constraintMoose::Util::TypeConstraints::_create_type_constraint
3211202µs10.8msMoose::Util::TypeConstraints::::find_or_create_type_constraintMoose::Util::TypeConstraints::find_or_create_type_constraint
16811176µs176µsMoose::Util::TypeConstraints::::CORE:substMoose::Util::TypeConstraints::CORE:subst (opcode)
5461159µs159µsMoose::Util::TypeConstraints::::CORE:matchMoose::Util::TypeConstraints::CORE:match (opcode)
3411120µs22.6msMoose::Util::TypeConstraints::::role_typeMoose::Util::TypeConstraints::role_type
1611105µs4.38msMoose::Util::TypeConstraints::::subtypeMoose::Util::TypeConstraints::subtype
1421103µs369µsMoose::Util::TypeConstraints::::_detect_type_constraint_unionMoose::Util::TypeConstraints::_detect_type_constraint_union
2922103µs23.1msMoose::Util::TypeConstraints::::class_typeMoose::Util::TypeConstraints::class_type
71196µs11.2msMoose::Util::TypeConstraints::::create_parameterized_type_constraintMoose::Util::TypeConstraints::create_parameterized_type_constraint
101178µs197µsMoose::Util::TypeConstraints::::_detect_parameterized_type_constraintMoose::Util::TypeConstraints::_detect_parameterized_type_constraint
71160µs157µsMoose::Util::TypeConstraints::::_parse_parameterized_type_constraintMoose::Util::TypeConstraints::_parse_parameterized_type_constraint
91157µs884µsMoose::Util::TypeConstraints::::find_or_create_does_type_constraintMoose::Util::TypeConstraints::find_or_create_does_type_constraint
21157µs638µsMoose::Util::TypeConstraints::::_create_type_constraint_unionMoose::Util::TypeConstraints::_create_type_constraint_union
71149µs10.9msMoose::Util::TypeConstraints::::_create_parameterized_type_constraintMoose::Util::TypeConstraints::_create_parameterized_type_constraint
21140µs132µsMoose::Util::TypeConstraints::::_parse_type_constraint_unionMoose::Util::TypeConstraints::_parse_type_constraint_union
161123µs23µsMoose::Util::TypeConstraints::::asMoose::Util::TypeConstraints::as
11120µs374µsMoose::Util::TypeConstraints::::_install_type_coercionsMoose::Util::TypeConstraints::_install_type_coercions
161117µs17µsMoose::Util::TypeConstraints::::whereMoose::Util::TypeConstraints::where
171115µs15µsMoose::Util::TypeConstraints::::inline_asMoose::Util::TypeConstraints::inline_as
1010114µs14µsMoose::Util::TypeConstraints::::CORE:qrMoose::Util::TypeConstraints::CORE:qr (opcode)
71113µs13µsMoose::Util::TypeConstraints::::get_all_parameterizable_typesMoose::Util::TypeConstraints::get_all_parameterizable_types
11113µs32µsMoose::Util::TypeConstraints::::BEGIN@62Moose::Util::TypeConstraints::BEGIN@62
11111µs28µsMoose::Util::TypeConstraints::::BEGIN@674Moose::Util::TypeConstraints::BEGIN@674
11111µs396µsMoose::Util::TypeConstraints::::typeMoose::Util::TypeConstraints::type
11110µs196µsMoose::Util::TypeConstraints::::BEGIN@36Moose::Util::TypeConstraints::BEGIN@36
2119µs646µsMoose::Util::TypeConstraints::::create_type_constraint_unionMoose::Util::TypeConstraints::create_type_constraint_union
1118µs8µsMoose::Util::TypeConstraints::::BEGIN@32Moose::Util::TypeConstraints::BEGIN@32
1117µs7µsMoose::Util::TypeConstraints::::BEGIN@4Moose::Util::TypeConstraints::BEGIN@4
1117µs15µsMoose::Util::TypeConstraints::::BEGIN@680Moose::Util::TypeConstraints::BEGIN@680
1117µs14µsMoose::Util::TypeConstraints::::BEGIN@685Moose::Util::TypeConstraints::BEGIN@685
1117µs14µsMoose::Util::TypeConstraints::::BEGIN@699Moose::Util::TypeConstraints::BEGIN@699
1116µs25µsMoose::Util::TypeConstraints::::BEGIN@6Moose::Util::TypeConstraints::BEGIN@6
1116µs6µsMoose::Util::TypeConstraints::::list_all_type_constraintsMoose::Util::TypeConstraints::list_all_type_constraints
1116µs10µsMoose::Util::TypeConstraints::::BEGIN@7Moose::Util::TypeConstraints::BEGIN@7
1116µs26µsMoose::Util::TypeConstraints::::BEGIN@5Moose::Util::TypeConstraints::BEGIN@5
1115µs5µsMoose::Util::TypeConstraints::::BEGIN@27Moose::Util::TypeConstraints::BEGIN@27
1114µs4µsMoose::Util::TypeConstraints::::BEGIN@33Moose::Util::TypeConstraints::BEGIN@33
1114µs378µsMoose::Util::TypeConstraints::::coerceMoose::Util::TypeConstraints::coerce
1114µs4µsMoose::Util::TypeConstraints::::BEGIN@24Moose::Util::TypeConstraints::BEGIN@24
1111µs1µsMoose::Util::TypeConstraints::::fromMoose::Util::TypeConstraints::from
1111µs1µsMoose::Util::TypeConstraints::::viaMoose::Util::TypeConstraints::via
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::::add_parameterizable_typeMoose::Util::TypeConstraints::add_parameterizable_type
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::::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::::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::::unionMoose::Util::TypeConstraints::union
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;
21700nsour $VERSION = '2.1604';
3
4222µs17µs
# spent 7µs within Moose::Util::TypeConstraints::BEGIN@4 which was called: # once (7µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 4
use Carp ();
# spent 7µs making 1 call to Moose::Util::TypeConstraints::BEGIN@4
5220µs245µs
# spent 26µs (6+20) within Moose::Util::TypeConstraints::BEGIN@5 which was called: # once (6µs+20µs) by Moose::Meta::Attribute::BEGIN@16 at line 5
use Scalar::Util qw( blessed );
# spent 26µs making 1 call to Moose::Util::TypeConstraints::BEGIN@5 # spent 20µs making 1 call to Exporter::import
6220µs245µs
# spent 25µs (6+20) within Moose::Util::TypeConstraints::BEGIN@6 which was called: # once (6µs+20µs) by Moose::Meta::Attribute::BEGIN@16 at line 6
use Moose::Exporter;
# spent 25µs making 1 call to Moose::Util::TypeConstraints::BEGIN@6 # spent 20µs making 1 call to Moose::Exporter::import
7244µs214µs
# spent 10µs (6+4) within Moose::Util::TypeConstraints::BEGIN@7 which was called: # once (6µs+4µ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
24218µs14µs
# spent 4µs within Moose::Util::TypeConstraints::BEGIN@24 which was called: # once (4µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 24
use Moose::Meta::TypeConstraint;
# spent 4µs making 1 call to Moose::Util::TypeConstraints::BEGIN@24
252104µs12.80ms
# spent 2.80ms (968µs+1.83) within Moose::Util::TypeConstraints::BEGIN@25 which was called: # once (968µs+1.83ms) by Moose::Meta::Attribute::BEGIN@16 at line 25
use Moose::Meta::TypeConstraint::Union;
# spent 2.80ms making 1 call to Moose::Util::TypeConstraints::BEGIN@25
262109µs14.27ms
# spent 4.27ms (596µs+3.67) within Moose::Util::TypeConstraints::BEGIN@26 which was called: # once (596µs+3.67ms) by Moose::Meta::Attribute::BEGIN@16 at line 26
use Moose::Meta::TypeConstraint::Parameterized;
# spent 4.27ms making 1 call to Moose::Util::TypeConstraints::BEGIN@26
27218µs15µs
# spent 5µs within Moose::Util::TypeConstraints::BEGIN@27 which was called: # once (5µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 27
use Moose::Meta::TypeConstraint::Parameterizable;
# spent 5µs making 1 call to Moose::Util::TypeConstraints::BEGIN@27
28296µs11.46ms
# spent 1.46ms (677µs+786µs) within Moose::Util::TypeConstraints::BEGIN@28 which was called: # once (677µs+786µs) by Moose::Meta::Attribute::BEGIN@16 at line 28
use Moose::Meta::TypeConstraint::Class;
# spent 1.46ms making 1 call to Moose::Util::TypeConstraints::BEGIN@28
29290µs11.34ms
# spent 1.34ms (623µs+720µs) within Moose::Util::TypeConstraints::BEGIN@29 which was called: # once (623µs+720µs) by Moose::Meta::Attribute::BEGIN@16 at line 29
use Moose::Meta::TypeConstraint::Role;
# spent 1.34ms making 1 call to Moose::Util::TypeConstraints::BEGIN@29
302106µs17.18ms
# spent 7.18ms (746µs+6.43) within Moose::Util::TypeConstraints::BEGIN@30 which was called: # once (746µs+6.43ms) by Moose::Meta::Attribute::BEGIN@16 at line 30
use Moose::Meta::TypeConstraint::Enum;
# spent 7.18ms making 1 call to Moose::Util::TypeConstraints::BEGIN@30
312127µs11.88ms
# spent 1.88ms (751µs+1.13) within Moose::Util::TypeConstraints::BEGIN@31 which was called: # once (751µs+1.13ms) by Moose::Meta::Attribute::BEGIN@16 at line 31
use Moose::Meta::TypeConstraint::DuckType;
# spent 1.88ms making 1 call to Moose::Util::TypeConstraints::BEGIN@31
32222µs18µs
# spent 8µs within Moose::Util::TypeConstraints::BEGIN@32 which was called: # once (8µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 32
use Moose::Meta::TypeCoercion;
# spent 8µs making 1 call to Moose::Util::TypeConstraints::BEGIN@32
33219µs14µs
# spent 4µs within Moose::Util::TypeConstraints::BEGIN@33 which was called: # once (4µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 33
use Moose::Meta::TypeCoercion::Union;
# spent 4µs making 1 call to Moose::Util::TypeConstraints::BEGIN@33
342112µs12.08ms
# spent 2.08ms (451µs+1.63) within Moose::Util::TypeConstraints::BEGIN@34 which was called: # once (451µs+1.63ms) by Moose::Meta::Attribute::BEGIN@16 at line 34
use Moose::Meta::TypeConstraint::Registry;
# spent 2.08ms making 1 call to Moose::Util::TypeConstraints::BEGIN@34
35
362165µs2382µs
# spent 196µs (10+186) within Moose::Util::TypeConstraints::BEGIN@36 which was called: # once (10µs+186µs) by Moose::Meta::Attribute::BEGIN@16 at line 36
use Moose::Util 'throw_exception';
# spent 196µs making 1 call to Moose::Util::TypeConstraints::BEGIN@36 # spent 186µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337]
37
3818µs1959µsMoose::Exporter->setup_import_methods(
# spent 959µ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
5513µs1275µsmy $REGISTRY = Moose::Meta::TypeConstraint::Registry->new;
# spent 275µs making 1 call to Moose::Meta::TypeConstraint::Registry::new
56
57sub get_type_constraint_registry {$REGISTRY}
5816µs1500ns
# spent 6µs (6+500ns) within Moose::Util::TypeConstraints::list_all_type_constraints which was called: # once (6µs+500ns) 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();
6222.42ms252µs
# spent 32µs (13+20) within Moose::Util::TypeConstraints::BEGIN@62 which was called: # once (13µs+20µs) by Moose::Meta::Attribute::BEGIN@16 at line 62
no strict 'refs';
# spent 32µs making 1 call to Moose::Util::TypeConstraints::BEGIN@62 # spent 20µ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
71
# spent 646µs (9+638) within Moose::Util::TypeConstraints::create_type_constraint_union which was called 2 times, avg 323µs/call: # 2 times (9µs+638µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 260, avg 323µs/call
sub create_type_constraint_union {
72210µs2638µs _create_type_constraint_union(\@_);
# spent 638µs making 2 calls to Moose::Util::TypeConstraints::_create_type_constraint_union, avg 319µs/call
73}
74
75sub create_named_type_constraint_union {
76 my $name = shift;
77 _create_type_constraint_union($name, \@_);
78}
79
80
# spent 638µs (57+580) within Moose::Util::TypeConstraints::_create_type_constraint_union which was called 2 times, avg 319µs/call: # 2 times (57µs+580µs) by Moose::Util::TypeConstraints::create_type_constraint_union at line 72, avg 319µs/call
sub _create_type_constraint_union {
812300ns my $name;
822700ns $name = shift if @_ > 1;
8322µs my @tcs = @{ shift() };
84
852400ns my @type_constraint_names;
86
8727µs4153µs if ( scalar @tcs == 1 && _detect_type_constraint_union( $tcs[0] ) ) {
# spent 132µs making 2 calls to Moose::Util::TypeConstraints::_parse_type_constraint_union, avg 66µs/call # spent 21µs making 2 calls to Moose::Util::TypeConstraints::_detect_type_constraint_union, avg 11µs/call
88 @type_constraint_names = _parse_type_constraint_union( $tcs[0] );
89 }
90 else {
91 @type_constraint_names = @tcs;
92 }
93
9422µs ( scalar @type_constraint_names >= 2 )
95 || throw_exception("UnionTakesAtleastTwoTypeNames");
96
9748µs82µs my @type_constraints = map {
# spent 2µs making 4 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 450ns/call # spent 91µs making 4 calls to Moose::Util::TypeConstraints::find_or_parse_type_constraint, avg 23µs/call, recursion: max depth 2, sum of overlapping time 91µs
9825µs find_or_parse_type_constraint($_)
99 || throw_exception( CouldNotLocateTypeConstraintForUnion => type_name => $_ );
100 } @type_constraint_names;
101
10223µs my %options = (
103 type_constraints => \@type_constraints
104 );
1052300ns $options{name} = $name if defined $name;
106
107213µs2335µs return Moose::Meta::TypeConstraint::Union->new(%options);
# spent 335µs making 2 calls to Moose::Meta::TypeConstraint::Union::new, avg 167µs/call
108}
109
110
111
# spent 11.2ms (96µs+11.1) within Moose::Util::TypeConstraints::create_parameterized_type_constraint which was called 7 times, avg 1.60ms/call: # 7 times (96µs+11.1ms) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 260, avg 1.60ms/call
sub create_parameterized_type_constraint {
11275µs my $type_constraint_name = shift;
113715µs7157µs my ( $base_type, $type_parameter )
# spent 157µs making 7 calls to Moose::Util::TypeConstraints::_parse_parameterized_type_constraint, avg 22µs/call
114 = _parse_parameterized_type_constraint($type_constraint_name);
115
11674µs ( defined $base_type && defined $type_parameter )
117 || throw_exception( InvalidTypeGivenToCreateParameterizedTypeConstraint => type_name => $type_constraint_name );
118
11978µs730µs if ( $REGISTRY->has_type_constraint($base_type) ) {
# spent 30µs making 7 calls to Moose::Meta::TypeConstraint::Registry::has_type_constraint, avg 4µs/call
120711µs729µs my $base_type_tc = $REGISTRY->get_type_constraint($base_type);
# spent 29µs making 7 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 4µs/call
121724µs710.9ms return _create_parameterized_type_constraint(
# spent 10.9ms making 7 calls to Moose::Util::TypeConstraints::_create_parameterized_type_constraint, avg 1.55ms/call
122 $base_type_tc,
123 $type_parameter
124 );
125 }
126 else {
127 throw_exception( InvalidBaseTypeGivenToCreateParameterizedTypeConstraint => type_name => $base_type );
128 }
129}
130
131
# spent 10.9ms (49µs+10.8) within Moose::Util::TypeConstraints::_create_parameterized_type_constraint which was called 7 times, avg 1.55ms/call: # 7 times (49µs+10.8ms) by Moose::Util::TypeConstraints::create_parameterized_type_constraint at line 121, avg 1.55ms/call
sub _create_parameterized_type_constraint {
13274µs my ( $base_type_tc, $type_parameter ) = @_;
133755µs1410.8ms if ( $base_type_tc->can('parameterize') ) {
# spent 10.8ms making 7 calls to Moose::Meta::TypeConstraint::Parameterizable::parameterize, avg 1.54ms/call # spent 9µs making 7 calls to UNIVERSAL::can, avg 1µs/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 24.0ms (582µs+23.4) within Moose::Util::TypeConstraints::create_class_type_constraint which was called 31 times, avg 774µs/call: # 29 times (528µs+22.4ms) by Moose::Util::TypeConstraints::class_type at line 352, avg 791µs/call # 2 times (54µs+977µs) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 246, avg 515µs/call
sub create_class_type_constraint {
1483127µ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
1543138µs my $pkg_defined_in = $options->{package_defined_in} || scalar( caller(1) );
155
1563161µs31155µs if (my $type = $REGISTRY->get_type_constraint($class)) {
# spent 155µs making 31 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 5µ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,
1713188µs %{ $options || {} }, # overrides options from above
172 );
173
1743121µs $options{name} ||= "__ANON__";
175
17631112µs3122.7ms my $tc = Moose::Meta::TypeConstraint::Class->new(%options);
# spent 22.7ms making 31 calls to Moose::Meta::TypeConstraint::Class::new, avg 731µs/call
1773161µs31588µs $REGISTRY->add_type_constraint($tc);
# spent 588µs making 31 calls to Moose::Meta::TypeConstraint::Registry::add_type_constraint, avg 19µs/call
17831102µs return $tc;
179}
180
181
# spent 23.0ms (601µs+22.4) within Moose::Util::TypeConstraints::create_role_type_constraint which was called 35 times, avg 657µs/call: # 34 times (580µs+21.9ms) by Moose::Util::TypeConstraints::role_type at line 356, avg 662µs/call # once (20µs+460µs) by Moose::Util::TypeConstraints::find_or_create_does_type_constraint at line 252
sub create_role_type_constraint {
1823517µ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
1883541µs my $pkg_defined_in = $options->{package_defined_in} || scalar( caller(1) );
189
1903569µs35174µs if (my $type = $REGISTRY->get_type_constraint($role)) {
# spent 174µs making 35 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 5µ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,
2053590µs %{ $options || {} },
206 );
207
2083520µs $options{name} ||= "__ANON__";
209
21035118µs3521.5ms my $tc = Moose::Meta::TypeConstraint::Role->new(%options);
# spent 21.5ms making 35 calls to Moose::Meta::TypeConstraint::Role::new, avg 615µs/call
2113572µs35682µs $REGISTRY->add_type_constraint($tc);
# spent 682µs making 35 calls to Moose::Meta::TypeConstraint::Registry::add_type_constraint, avg 19µs/call
21235108µs return $tc;
213}
214
215
# spent 10.8ms (202µs+10.6) within Moose::Util::TypeConstraints::find_or_create_type_constraint which was called 32 times, avg 338µs/call: # 32 times (202µs+10.6ms) by Moose::Meta::Attribute::Native::Trait::_check_helper_type at line 39 of Moose/Meta/Attribute/Native/Trait.pm, avg 338µs/call
sub find_or_create_type_constraint {
2163215µs my ( $type_constraint_name, $options_for_anon_type ) = @_;
217
21832143µs6410.6ms if ( my $constraint
# spent 10.6ms making 32 calls to Moose::Util::TypeConstraints::find_or_parse_type_constraint, avg 331µs/call # spent 15µs making 32 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 466ns/call
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 7.91ms (641µs+7.27) within Moose::Util::TypeConstraints::find_or_create_isa_type_constraint which was called 122 times, avg 65µs/call: # 99 times (538µs+6.36ms) by Moose::Meta::Attribute::_process_isa_option at line 345 of Moose/Meta/Attribute.pm, avg 70µs/call # 16 times (62µs+350µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 572, avg 26µs/call # 7 times (40µs+564µs) by Moose::Meta::TypeConstraint::Parameterizable::_parse_type_parameter at line 67 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 86µs/call
sub find_or_create_isa_type_constraint {
24512246µs my ($type_constraint_name, $options) = @_;
246122416µs2446.71ms find_or_parse_type_constraint($type_constraint_name)
# spent 6.51ms making 122 calls to Moose::Util::TypeConstraints::find_or_parse_type_constraint, avg 53µs/call, recursion: max depth 1, sum of overlapping time 879µs # spent 1.03ms making 2 calls to Moose::Util::TypeConstraints::create_class_type_constraint, avg 515µs/call # spent 54µs making 120 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 450ns/call
247 || create_class_type_constraint($type_constraint_name, $options);
248}
249
250
# spent 884µs (57+827) within Moose::Util::TypeConstraints::find_or_create_does_type_constraint which was called 9 times, avg 98µs/call: # 9 times (57µs+827µs) by Moose::Meta::Attribute::_process_does_option at line 364 of Moose/Meta/Attribute.pm, avg 98µs/call
sub find_or_create_does_type_constraint {
25195µs my ($type_constraint_name, $options) = @_;
252938µs18827µs find_or_parse_type_constraint($type_constraint_name)
# spent 480µs making 1 call to Moose::Util::TypeConstraints::create_role_type_constraint # spent 343µs making 9 calls to Moose::Util::TypeConstraints::find_or_parse_type_constraint, avg 38µs/call # spent 4µs making 8 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 450ns/call
253 || create_role_type_constraint($type_constraint_name, $options);
254}
255
256
# spent 16.6ms (1.43+15.2) within Moose::Util::TypeConstraints::find_or_parse_type_constraint which was called 168 times, avg 99µs/call: # 122 times (966µs+4.66ms) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 246, avg 46µs/call # 32 times (346µs+10.3ms) by Moose::Util::TypeConstraints::find_or_create_type_constraint at line 218, avg 331µs/call # 9 times (85µs+258µs) by Moose::Util::TypeConstraints::find_or_create_does_type_constraint at line 252, avg 38µs/call # 4 times (28µs+-28µs) by Moose::Util::TypeConstraints::_create_type_constraint_union at line 97, avg 0s/call # once (9µs+18µs) by Moose::Meta::TypeCoercion::compile_type_coercion at line 46 of Moose/Meta/TypeCoercion.pm
sub find_or_parse_type_constraint {
257168214µs168712µs my $type_constraint_name = normalize_type_constraint_name(shift);
# spent 712µs making 168 calls to Moose::Util::TypeConstraints::normalize_type_constraint_name, avg 4µs/call
25816818µs my $constraint;
259
260168868µs35515.3ms if ( $constraint = find_type_constraint($type_constraint_name) ) {
# spent 11.2ms making 7 calls to Moose::Util::TypeConstraints::create_parameterized_type_constraint, avg 1.60ms/call # spent 2.73ms making 168 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 16µs/call # spent 646µs making 2 calls to Moose::Util::TypeConstraints::create_type_constraint_union, avg 323µs/call # spent 347µs making 12 calls to Moose::Util::TypeConstraints::_detect_type_constraint_union, avg 29µs/call # spent 197µs making 10 calls to Moose::Util::TypeConstraints::_detect_parameterized_type_constraint, avg 20µs/call # spent 176µs making 156 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 1µs/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 {
27137µs return;
272 }
273
274918µs9154µs $REGISTRY->add_type_constraint($constraint);
# spent 154µs making 9 calls to Moose::Meta::TypeConstraint::Registry::add_type_constraint, avg 17µs/call
275918µs return $constraint;
276}
277
278
# spent 712µs (536+176) within Moose::Util::TypeConstraints::normalize_type_constraint_name which was called 168 times, avg 4µs/call: # 168 times (536µs+176µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 257, avg 4µs/call
sub normalize_type_constraint_name {
27916854µs my $type_constraint_name = shift;
280168468µs168176µs $type_constraint_name =~ s/\s//g;
# spent 176µs making 168 calls to Moose::Util::TypeConstraints::CORE:subst, avg 1µs/call
281168312µ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 5.78ms (2.75+3.03) within Moose::Util::TypeConstraints::find_type_constraint which was called 451 times, avg 13µs/call: # 168 times (1.18ms+1.54ms) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 260, avg 16µs/call # 88 times (293µs+98µs) by Moose::Meta::TypeConstraint::equals at line 234 of Moose/Meta/TypeConstraint.pm, avg 4µs/call # 35 times (305µs+291µs) by Moose::Role::init_meta at line 126 of Moose/Role.pm, avg 17µs/call # 35 times (225µs+268µs) by Moose::Meta::TypeConstraint::Role::new at line 32 of Moose/Meta/TypeConstraint/Role.pm, avg 14µs/call # 32 times (155µs+197µs) by Moose::Meta::TypeConstraint::is_a_type_of at line 254 of Moose/Meta/TypeConstraint.pm, avg 11µs/call # 31 times (206µs+221µs) by Moose::Meta::TypeConstraint::Class::new at line 30 of Moose/Meta/TypeConstraint/Class.pm, avg 14µs/call # 28 times (222µs+249µs) by Moose::init_meta at line 161 of Moose.pm, avg 17µs/call # 23 times (108µs+125µs) by Moose::Meta::TypeConstraint::is_subtype_of at line 263 of Moose/Meta/TypeConstraint.pm, avg 10µs/call # 5 times (17µs+5µs) by Moose::Meta::TypeConstraint::Parameterized::equals at line 30 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 4µs/call # once (6µs+7µs) by Moose::Util::TypeConstraints::_install_type_coercions at line 593 # once (5µs+7µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 233 of Moose/Util/TypeConstraints/Builtins.pm # once (5µs+6µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 198 of Moose/Util/TypeConstraints/Builtins.pm # once (5µs+7µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 268 of Moose/Util/TypeConstraints/Builtins.pm # once (6µs+6µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 294 of Moose/Util/TypeConstraints/Builtins.pm # once (6µs+6µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 79 of Moose/Util/TypeConstraints/Builtins.pm
sub find_type_constraint {
296451127µs my $type = shift;
297
2984511.27ms549240µs if ( blessed $type and $type->isa("Moose::Meta::TypeConstraint") ) {
# spent 182µs making 451 calls to Scalar::Util::blessed, avg 403ns/call # spent 58µs making 98 calls to UNIVERSAL::isa, avg 594ns/call
299 return $type;
300 }
301 else {
302353676µs3531.82ms return unless $REGISTRY->has_type_constraint($type);
# spent 1.82ms making 353 calls to Moose::Meta::TypeConstraint::Registry::has_type_constraint, avg 5µs/call
303279798µs279975µs return $REGISTRY->get_type_constraint($type);
# spent 975µs making 279 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 3µ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 396µs (11+386) within Moose::Util::TypeConstraints::type which was called: # once (11µs+386µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 11 of Moose/Util/TypeConstraints/Builtins.pm
sub type {
3181600ns my $name = shift;
319
32014µs my %p = map { %{$_} } @_;
321
32216µs1386µs return _create_type_constraint(
323 $name, undef, $p{where}, $p{message},
324 $p{inline_as},
325 );
326}
327
328
# spent 4.38ms (105µs+4.28) within Moose::Util::TypeConstraints::subtype which was called 16 times, avg 274µs/call: # 16 times (105µs+4.28ms) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 12 of Moose/Util/TypeConstraints/Builtins.pm, avg 274µs/call
sub subtype {
329164µ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
3371647µs my %p = map { %{$_} } @_;
338
339 # subtype Str => where { ... };
340165µs if ( !exists $p{as} ) {
341 $p{as} = $name;
342 $name = undef;
343 }
344
3451647µs164.28ms return _create_type_constraint(
# spent 4.28ms making 16 calls to Moose::Util::TypeConstraints::_create_type_constraint, avg 267µs/call
346 $name, $p{as}, $p{where}, $p{message},
347 $p{inline_as},
348 );
349}
350
351
# spent 23.1ms (103µs+23.0) within Moose::Util::TypeConstraints::class_type which was called 29 times, avg 795µs/call: # 28 times (98µs+22.4ms) by Moose::init_meta at line 161 of Moose.pm, avg 804µs/call # once (4µs+553µs) by PONAPI::Server::BEGIN@17 at line 12 of lib/PONAPI/Server/ConfigReader.pm
sub class_type {
3522997µs2923.0ms create_class_type_constraint(@_);
# spent 23.0ms making 29 calls to Moose::Util::TypeConstraints::create_class_type_constraint, avg 791µs/call
353}
354
355
# spent 22.6ms (120µs+22.5) within Moose::Util::TypeConstraints::role_type which was called 34 times, avg 665µs/call: # 34 times (120µs+22.5ms) by Moose::Role::init_meta at line 126 of Moose/Role.pm, avg 665µs/call
sub role_type ($;$) {
35634105µs3422.5ms create_role_type_constraint(@_);
# spent 22.5ms making 34 calls to Moose::Util::TypeConstraints::create_role_type_constraint, avg 662µs/call
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
392
# spent 378µs (4+374) within Moose::Util::TypeConstraints::coerce which was called: # once (4µs+374µs) by PONAPI::Server::BEGIN@17 at line 15 of lib/PONAPI/Server/ConfigReader.pm
sub coerce {
3931900ns my ( $type_name, @coercion_map ) = @_;
39413µs1374µs _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.
4101637µs
# spent 23µs within Moose::Util::TypeConstraints::as which was called 16 times, avg 1µs/call: # 16 times (23µs+0s) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 13 of Moose/Util/TypeConstraints/Builtins.pm, avg 1µs/call
sub as { { as => shift }, @_ }
4111633µs
# spent 17µs within Moose::Util::TypeConstraints::where which was called 16 times, avg 1µs/call: # 16 times (17µs+0s) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 14 of Moose/Util/TypeConstraints/Builtins.pm, avg 1µs/call
sub where (&) { { where => $_[0] } }
412sub message (&) { { message => $_[0] } }
4131740µs
# spent 15µs within Moose::Util::TypeConstraints::inline_as which was called 17 times, avg 865ns/call: # 17 times (15µs+0s) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 15 of Moose/Util/TypeConstraints/Builtins.pm, avg 865ns/call
sub inline_as (&) { { inline_as => $_[0] } }
414
41512µs
# spent 1µs within Moose::Util::TypeConstraints::from which was called: # once (1µs+0s) by PONAPI::Server::BEGIN@17 at line 15 of lib/PONAPI/Server/ConfigReader.pm
sub from {@_}
41613µs
# spent 1µs within Moose::Util::TypeConstraints::via which was called: # once (1µs+0s) by PONAPI::Server::BEGIN@17 at line 15 of lib/PONAPI/Server/ConfigReader.pm
sub 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 4.66ms (308µs+4.35) within Moose::Util::TypeConstraints::_create_type_constraint which was called 17 times, avg 274µs/call: # 16 times (278µs+4.00ms) by Moose::Util::TypeConstraints::subtype at line 345, avg 267µs/call # once (30µs+356µs) by Moose::Util::TypeConstraints::type at line 322
sub _create_type_constraint ($$$;$) {
540173µs my $name = shift;
541173µs my $parent = shift;
542172µs my $check = shift;
543178µs my $message = shift;
544172µs my $inlined = shift;
545
546179µs my $pkg_defined_in = scalar( caller(1) );
547
548175µs if ( defined $name ) {
5491716µs1772µs my $type = $REGISTRY->get_type_constraint($name);
# spent 72µs making 17 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 4µ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
5571763µs1730µs if( $name !~ /^[\w:\.]+$/ ) {
# spent 30µs making 17 calls to Moose::Util::TypeConstraints::CORE:match, avg 2µs/call
558 throw_exception( InvalidNameForType => name => $name );
559 }
560 }
561
5621733µ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;
5721784µs643.70ms if (
# spent 3.27ms making 16 calls to Moose::Meta::TypeConstraint::create_child_type, avg 205µs/call # spent 412µs making 16 calls to Moose::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 26µs/call # spent 7µs making 16 calls to Scalar::Util::blessed, avg 456ns/call # spent 7µs making 16 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 419ns/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 {
58214µs1311µs $constraint = Moose::Meta::TypeConstraint->new(%opts);
# spent 311µs making 1 call to Moose::Meta::TypeConstraint::new
583 }
584
5851719µs17239µs $REGISTRY->add_type_constraint($constraint)
# spent 239µs making 17 calls to Moose::Meta::TypeConstraint::Registry::add_type_constraint, avg 14µs/call
586 if defined $name;
587
5881736µs return $constraint;
589}
590
591
# spent 374µs (20+354) within Moose::Util::TypeConstraints::_install_type_coercions which was called: # once (20µs+354µs) by Moose::Util::TypeConstraints::coerce at line 394
sub _install_type_coercions ($$) {
5921400ns my ( $type_name, $coercion_map ) = @_;
59311µs113µs my $type = find_type_constraint($type_name);
# spent 13µs making 1 call to Moose::Util::TypeConstraints::find_type_constraint
5941300ns ( defined $type )
595 || throw_exception( CannotFindType => type_name => $type_name );
596
59714µs12µs if ( $type->has_coercion ) {
# spent 2µs making 1 call to Moose::Meta::TypeConstraint::has_coercion
598 $type->coercion->add_type_coercions(@$coercion_map);
599 }
600 else {
60113µs1335µs my $type_coercion = Moose::Meta::TypeCoercion->new(
# spent 335µs making 1 call to Moose::Meta::TypeCoercion::new
602 type_coercion_map => $coercion_map,
603 type_constraint => $type
604 );
60514µs13µs $type->coercion($type_coercion);
# spent 3µs making 1 call to Moose::Meta::TypeConstraint::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
6213373µs21.37ms
# spent 1.36ms (1.11+244µs) within Moose::Util::TypeConstraints::BEGIN@621 which was called: # once (1.11ms+244µs) by Moose::Meta::Attribute::BEGIN@16 at line 621
use re "eval";
# spent 1.36ms making 1 call to Moose::Util::TypeConstraints::BEGIN@621 # spent 14µs making 1 call to re::import
622
62318µs13µs my $valid_chars = qr{[\w:\.]};
# spent 3µs making 1 call to Moose::Util::TypeConstraints::CORE:qr
624133µs227µs my $type_atom = qr{ (?>$valid_chars+) }x;
# spent 26µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 900ns making 1 call to Moose::Util::TypeConstraints::CORE:qr
62516µs13µs my $ws = qr{ (?>\s*) }x;
# spent 3µs making 1 call to Moose::Util::TypeConstraints::CORE:qr
626115µs211µs my $op_union = qr{ $ws \| $ws }x;
# spent 10µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 800ns making 1 call to Moose::Util::TypeConstraints::CORE:qr
627
6281300ns my ($type, $type_capture_parts, $type_with_parameter, $union, $any);
62912µs if (Class::MOP::IS_RUNNING_ON_5_10) {
63011µs my $type_pattern
631 = q{ (?&type_atom) (?: \[ (?&ws) (?&any) (?&ws) \] )? };
6321500ns my $type_capture_parts_pattern
633 = q{ ((?&type_atom)) (?: \[ (?&ws) ((?&any)) (?&ws) \] )? };
6341200ns my $type_with_parameter_pattern
635 = q{ (?&type_atom) \[ (?&ws) (?&any) (?&ws) \] };
6361200ns my $union_pattern
637 = q{ (?&type) (?> (?: (?&op_union) (?&type) )+ ) };
6381200ns my $any_pattern
639 = q{ (?&type) | (?&union) };
640
641166µs260µs my $defines = qr{(?(DEFINE)
# spent 59µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 800ns 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
653150µs244µs $type = qr{ $type_pattern $defines }x;
# spent 43µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 800ns making 1 call to Moose::Util::TypeConstraints::CORE:qr
654149µs240µs $type_capture_parts = qr{ $type_capture_parts_pattern $defines }x;
# spent 40µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 800ns making 1 call to Moose::Util::TypeConstraints::CORE:qr
655149µs243µs $type_with_parameter = qr{ $type_with_parameter_pattern $defines }x;
# spent 42µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 800ns making 1 call to Moose::Util::TypeConstraints::CORE:qr
656146µs240µs $union = qr{ $union_pattern $defines }x;
# spent 38µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 2µs making 1 call to Moose::Util::TypeConstraints::CORE:qr
657146µs238µs $any = qr{ $any_pattern $defines }x;
# spent 37µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp # spent 1µs 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 157µs (60+97) within Moose::Util::TypeConstraints::_parse_parameterized_type_constraint which was called 7 times, avg 22µs/call: # 7 times (60µs+97µs) by Moose::Util::TypeConstraints::create_parameterized_type_constraint at line 113, avg 22µs/call
sub _parse_parameterized_type_constraint {
6741666µs246µs
# spent 28µs (11+17) within Moose::Util::TypeConstraints::BEGIN@674 which was called: # once (11µs+17µs) by Moose::Meta::Attribute::BEGIN@16 at line 674
{ no warnings 'void'; $any; } # force capture of interpolated lexical
# spent 28µs making 1 call to Moose::Util::TypeConstraints::BEGIN@674 # spent 17µs making 1 call to warnings::unimport
6757124µs1497µs $_[0] =~ m{ $type_capture_parts }x;
# spent 65µs making 7 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 9µs/call # spent 32µs making 7 calls to Moose::Util::TypeConstraints::CORE:match, avg 4µs/call
676740µs return ( $1, $2 );
677 }
678
679
# spent 197µs (78+118) within Moose::Util::TypeConstraints::_detect_parameterized_type_constraint which was called 10 times, avg 20µs/call: # 10 times (78µs+118µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 260, avg 20µs/call
sub _detect_parameterized_type_constraint {
6802253µs223µs
# spent 15µs (7+8) within Moose::Util::TypeConstraints::BEGIN@680 which was called: # once (7µs+8µs) by Moose::Meta::Attribute::BEGIN@16 at line 680
{ no warnings 'void'; $any; } # force capture of interpolated lexical
# spent 15µs making 1 call to Moose::Util::TypeConstraints::BEGIN@680 # spent 8µs making 1 call to warnings::unimport
68110195µs20118µs $_[0] =~ m{ ^ $type_with_parameter $ }x;
# spent 72µs making 10 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 7µs/call # spent 46µs making 10 calls to Moose::Util::TypeConstraints::CORE:match, avg 5µs/call
682 }
683
684
# spent 132µs (40+92) within Moose::Util::TypeConstraints::_parse_type_constraint_union which was called 2 times, avg 66µs/call: # 2 times (40µs+92µs) by Moose::Util::TypeConstraints::_create_type_constraint_union at line 87, avg 66µs/call
sub _parse_type_constraint_union {
685693µs220µs
# spent 14µs (7+7) within Moose::Util::TypeConstraints::BEGIN@685 which was called: # once (7µs+7µs) by Moose::Meta::Attribute::BEGIN@16 at line 685
{ no warnings 'void'; $any; } # force capture of interpolated lexical
# spent 14µs making 1 call to Moose::Util::TypeConstraints::BEGIN@685 # spent 7µs making 1 call to warnings::unimport
68621µs my $given = shift;
6872300ns my @rv;
688288µs477µs while ( $given =~ m{ \G (?: $op_union )? ($type) }gcx ) {
# spent 72µs making 2 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 36µs/call # spent 5µs making 2 calls to Moose::Util::TypeConstraints::CORE:match, avg 3µs/call
689433µs815µs push @rv => $1;
# spent 10µs making 4 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 3µs/call # spent 4µs making 4 calls to Moose::Util::TypeConstraints::CORE:match, avg 1µs/call
690 }
69123µs ( pos($given) eq length($given) )
692 || throw_exception( CouldNotParseType => type => $given,
693 position => pos($given)
694 );
69528µs @rv;
696 }
697
698
# spent 369µs (103+265) within Moose::Util::TypeConstraints::_detect_type_constraint_union which was called 14 times, avg 26µs/call: # 12 times (96µs+252µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 260, avg 29µs/call # 2 times (8µs+14µs) by Moose::Util::TypeConstraints::_create_type_constraint_union at line 87, avg 11µs/call
sub _detect_type_constraint_union {
69930251µs221µs
# spent 14µs (7+7) within Moose::Util::TypeConstraints::BEGIN@699 which was called: # once (7µs+7µs) by Moose::Meta::Attribute::BEGIN@16 at line 699
{ no warnings 'void'; $any; } # force capture of interpolated lexical
# spent 14µs making 1 call to Moose::Util::TypeConstraints::BEGIN@699 # spent 7µs making 1 call to warnings::unimport
70014368µs28265µs $_[0] =~ m{^ $type $op_union $type ( $op_union .* )? $}x;
# spent 223µs making 14 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 16µs/call # spent 42µs making 14 calls to Moose::Util::TypeConstraints::CORE:match, avg 3µs/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.
711$_->make_immutable(
71298µs94µs inline_constructor => 1,
# spent 4µs making 9 calls to Class::MOP::Class::is_mutable, avg 422ns/call
713 constructor_name => "_new",
714
715 # these are Class::MOP accessors, so they need inlining
716 inline_accessors => 1
7171029µs1841.2ms ) for grep { $_->is_mutable }
# spent 41.1ms making 9 calls to Class::MOP::Class::make_immutable, avg 4.57ms/call # spent 26µs making 9 calls to Class::MOP::class_of, avg 3µs/call
718 map { Class::MOP::class_of($_) }
719 qw(
720 Moose::Meta::TypeConstraint
721 Moose::Meta::TypeConstraint::Union
722 Moose::Meta::TypeConstraint::Parameterized
723 Moose::Meta::TypeConstraint::Parameterizable
724 Moose::Meta::TypeConstraint::Class
725 Moose::Meta::TypeConstraint::Role
726 Moose::Meta::TypeConstraint::Enum
727 Moose::Meta::TypeConstraint::DuckType
728 Moose::Meta::TypeConstraint::Registry
729);
730
7311126µsrequire Moose::Util::TypeConstraints::Builtins;
73212µs16.24msMoose::Util::TypeConstraints::Builtins::define_builtins($REGISTRY);
733
734my @PARAMETERIZABLE_TYPES
73556µs412µs = map { $REGISTRY->get_type_constraint($_) } qw[ScalarRef ArrayRef HashRef Maybe];
# spent 12µs making 4 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 3µs/call
736
737718µs
# spent 13µs within Moose::Util::TypeConstraints::get_all_parameterizable_types which was called 7 times, avg 2µs/call: # 7 times (13µs+0s) by Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint at line 54 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 2µ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{
75326µs16µs my @BUILTINS = list_all_type_constraints();
754 sub list_all_builtin_type_constraints {@BUILTINS}
755}
756
757137µs1;
758
759# ABSTRACT: Type constraint system for Moose
760
761__END__
 
# spent 159µs within Moose::Util::TypeConstraints::CORE:match which was called 54 times, avg 3µs/call: # 17 times (30µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint at line 557, avg 2µs/call # 14 times (42µs+0s) by Moose::Util::TypeConstraints::_detect_type_constraint_union at line 700, avg 3µs/call # 10 times (46µs+0s) by Moose::Util::TypeConstraints::_detect_parameterized_type_constraint at line 681, avg 5µs/call # 7 times (32µs+0s) by Moose::Util::TypeConstraints::_parse_parameterized_type_constraint at line 675, avg 4µs/call # 4 times (4µs+0s) by Moose::Util::TypeConstraints::_parse_type_constraint_union at line 689, avg 1µs/call # 2 times (5µs+0s) by Moose::Util::TypeConstraints::_parse_type_constraint_union at line 688, avg 3µs/call
sub Moose::Util::TypeConstraints::CORE:match; # opcode
# spent 14µs within Moose::Util::TypeConstraints::CORE:qr which was called 10 times, avg 1µs/call: # once (3µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 625 # once (3µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 623 # once (2µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 656 # once (1µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 657 # once (900ns+0s) by Moose::Meta::Attribute::BEGIN@16 at line 624 # once (800ns+0s) by Moose::Meta::Attribute::BEGIN@16 at line 626 # once (800ns+0s) by Moose::Meta::Attribute::BEGIN@16 at line 653 # once (800ns+0s) by Moose::Meta::Attribute::BEGIN@16 at line 654 # once (800ns+0s) by Moose::Meta::Attribute::BEGIN@16 at line 641 # once (800ns+0s) by Moose::Meta::Attribute::BEGIN@16 at line 655
sub Moose::Util::TypeConstraints::CORE:qr; # opcode
# spent 738µs within Moose::Util::TypeConstraints::CORE:regcomp which was called 45 times, avg 16µs/call: # 14 times (223µs+0s) by Moose::Util::TypeConstraints::_detect_type_constraint_union at line 700, avg 16µs/call # 10 times (72µs+0s) by Moose::Util::TypeConstraints::_detect_parameterized_type_constraint at line 681, avg 7µs/call # 7 times (65µs+0s) by Moose::Util::TypeConstraints::_parse_parameterized_type_constraint at line 675, avg 9µs/call # 4 times (10µs+0s) by Moose::Util::TypeConstraints::_parse_type_constraint_union at line 689, avg 3µs/call # 2 times (72µs+0s) by Moose::Util::TypeConstraints::_parse_type_constraint_union at line 688, avg 36µs/call # once (59µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 641 # once (43µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 653 # once (42µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 655 # once (40µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 654 # once (38µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 656 # once (37µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 657 # once (26µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 624 # once (10µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 626
sub Moose::Util::TypeConstraints::CORE:regcomp; # opcode
# spent 176µs within Moose::Util::TypeConstraints::CORE:subst which was called 168 times, avg 1µs/call: # 168 times (176µs+0s) by Moose::Util::TypeConstraints::normalize_type_constraint_name at line 280, avg 1µs/call
sub Moose::Util::TypeConstraints::CORE:subst; # opcode