Filename | /Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Util/TypeConstraints.pm |
Statements | Executed 3353 statements in 12.9ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
272 | 12 | 7 | 2.28ms | 5.64ms | find_type_constraint | Moose::Util::TypeConstraints::
194 | 1 | 1 | 2.12ms | 11.0ms | find_or_parse_type_constraint (recurses: max depth 1, inclusive time 63µs) | Moose::Util::TypeConstraints::
194 | 3 | 3 | 1.41ms | 15.8ms | find_or_create_isa_type_constraint (recurses: max depth 1, inclusive time 81µs) | Moose::Util::TypeConstraints::
1 | 1 | 1 | 1.17ms | 3.45ms | BEGIN@25 | Moose::Util::TypeConstraints::
1 | 1 | 1 | 1.12ms | 1.52ms | BEGIN@621 | Moose::Util::TypeConstraints::
194 | 1 | 1 | 923µs | 1.14ms | normalize_type_constraint_name | Moose::Util::TypeConstraints::
1 | 1 | 1 | 795µs | 1.78ms | BEGIN@28 | Moose::Util::TypeConstraints::
1 | 1 | 1 | 760µs | 1.97ms | BEGIN@31 | Moose::Util::TypeConstraints::
1 | 1 | 1 | 697µs | 2.10ms | BEGIN@30 | Moose::Util::TypeConstraints::
1 | 1 | 1 | 694µs | 5.10ms | BEGIN@26 | Moose::Util::TypeConstraints::
24 | 11 | 1 | 664µs | 664µs | CORE:regcomp (opcode) | Moose::Util::TypeConstraints::
1 | 1 | 1 | 637µs | 1.62ms | BEGIN@29 | Moose::Util::TypeConstraints::
22 | 2 | 1 | 564µs | 15.2ms | create_class_type_constraint | Moose::Util::TypeConstraints::
1 | 1 | 1 | 527µs | 2.28ms | BEGIN@34 | Moose::Util::TypeConstraints::
17 | 2 | 1 | 379µs | 5.98ms | _create_type_constraint | Moose::Util::TypeConstraints::
194 | 1 | 1 | 222µs | 222µs | CORE:subst (opcode) | Moose::Util::TypeConstraints::
16 | 1 | 1 | 154µs | 5.71ms | subtype | Moose::Util::TypeConstraints::
17 | 1 | 1 | 79µs | 12.1ms | class_type | Moose::Util::TypeConstraints::
3 | 1 | 1 | 76µs | 2.12ms | create_role_type_constraint | Moose::Util::TypeConstraints::
33 | 4 | 1 | 73µs | 73µs | CORE:match (opcode) | Moose::Util::TypeConstraints::
7 | 1 | 1 | 69µs | 197µs | _detect_type_constraint_union | Moose::Util::TypeConstraints::
7 | 1 | 1 | 53µs | 125µs | _detect_parameterized_type_constraint | Moose::Util::TypeConstraints::
2 | 1 | 1 | 36µs | 2.83ms | create_parameterized_type_constraint | Moose::Util::TypeConstraints::
16 | 1 | 1 | 29µs | 29µs | as | Moose::Util::TypeConstraints::
2 | 1 | 1 | 27µs | 83µs | _parse_parameterized_type_constraint | Moose::Util::TypeConstraints::
10 | 10 | 1 | 25µs | 25µs | CORE:qr (opcode) | Moose::Util::TypeConstraints::
2 | 1 | 1 | 24µs | 2.69ms | _create_parameterized_type_constraint | Moose::Util::TypeConstraints::
16 | 1 | 1 | 24µs | 24µs | where | Moose::Util::TypeConstraints::
17 | 1 | 1 | 22µs | 22µs | inline_as | Moose::Util::TypeConstraints::
3 | 1 | 1 | 14µs | 2.13ms | role_type | Moose::Util::TypeConstraints::
1 | 1 | 1 | 13µs | 442µs | type | Moose::Util::TypeConstraints::
1 | 1 | 1 | 11µs | 26µs | BEGIN@674 | Moose::Util::TypeConstraints::
1 | 1 | 1 | 9µs | 9µs | BEGIN@4 | Moose::Util::TypeConstraints::
1 | 1 | 1 | 9µs | 18µs | BEGIN@680 | Moose::Util::TypeConstraints::
1 | 1 | 1 | 9µs | 14µs | BEGIN@7 | Moose::Util::TypeConstraints::
1 | 1 | 1 | 9µs | 34µs | BEGIN@6 | Moose::Util::TypeConstraints::
1 | 1 | 1 | 8µs | 8µs | BEGIN@32 | Moose::Util::TypeConstraints::
1 | 1 | 1 | 8µs | 17µs | BEGIN@699 | Moose::Util::TypeConstraints::
1 | 1 | 1 | 8µs | 17µs | BEGIN@685 | Moose::Util::TypeConstraints::
1 | 1 | 1 | 8µs | 136µs | BEGIN@36 | Moose::Util::TypeConstraints::
1 | 1 | 1 | 8µs | 20µs | BEGIN@62 | Moose::Util::TypeConstraints::
1 | 1 | 1 | 8µs | 33µs | BEGIN@5 | Moose::Util::TypeConstraints::
1 | 1 | 1 | 8µs | 9µs | list_all_type_constraints | Moose::Util::TypeConstraints::
1 | 1 | 1 | 6µs | 6µs | BEGIN@24 | Moose::Util::TypeConstraints::
1 | 1 | 1 | 6µs | 6µs | BEGIN@27 | Moose::Util::TypeConstraints::
1 | 1 | 1 | 6µs | 6µs | BEGIN@33 | Moose::Util::TypeConstraints::
2 | 1 | 1 | 4µs | 4µs | get_all_parameterizable_types | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | __ANON__[:67] | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | _confess | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | _create_type_constraint_union | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | _install_type_coercions | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | _parse_type_constraint_union | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | add_parameterizable_type | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | coerce | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | create_duck_type_constraint | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | create_enum_type_constraint | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | create_named_type_constraint_union | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | create_type_constraint_union | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | duck_type | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | enum | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | export_type_constraints_as_functions | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | find_or_create_does_type_constraint | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | find_or_create_type_constraint | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | from | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | get_type_constraint_registry | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | list_all_builtin_type_constraints | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | match_on_type | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | maybe_type | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | message | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | register_type_constraint | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | union | Moose::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | via | Moose::Util::TypeConstraints::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Moose::Util::TypeConstraints; | ||||
2 | 1 | 900ns | our $VERSION = '2.1403'; | ||
3 | |||||
4 | 2 | 25µs | 1 | 9µs | # spent 9µs within Moose::Util::TypeConstraints::BEGIN@4 which was called:
# once (9µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 4 # spent 9µs making 1 call to Moose::Util::TypeConstraints::BEGIN@4 |
5 | 2 | 25µs | 2 | 57µs | # spent 33µs (8+24) within Moose::Util::TypeConstraints::BEGIN@5 which was called:
# once (8µs+24µs) by Moose::Meta::Attribute::BEGIN@16 at line 5 # spent 33µs making 1 call to Moose::Util::TypeConstraints::BEGIN@5
# spent 24µs making 1 call to Exporter::import |
6 | 2 | 25µs | 2 | 58µs | # spent 34µs (9+25) within Moose::Util::TypeConstraints::BEGIN@6 which was called:
# once (9µs+25µs) by Moose::Meta::Attribute::BEGIN@16 at line 6 # spent 34µs making 1 call to Moose::Util::TypeConstraints::BEGIN@6
# spent 25µs making 1 call to Moose::Exporter::import |
7 | 2 | 53µs | 2 | 19µs | # spent 14µs (9+5) within Moose::Util::TypeConstraints::BEGIN@7 which was called:
# once (9µs+5µs) by Moose::Meta::Attribute::BEGIN@16 at line 7 # spent 14µs making 1 call to Moose::Util::TypeConstraints::BEGIN@7
# spent 5µs making 1 call to Package::DeprecationManager::__ANON__[Package/DeprecationManager.pm:61] |
8 | |||||
9 | ## -------------------------------------------------------- | ||||
10 | # Prototyped subs must be predeclared because we have a | ||||
11 | # circular dependency with Moose::Meta::Attribute et. al. | ||||
12 | # so in case of us being use'd first the predeclaration | ||||
13 | # ensures the prototypes are in scope when consumers are | ||||
14 | # compiled. | ||||
15 | |||||
16 | # dah sugah! | ||||
17 | sub where (&); | ||||
18 | sub via (&); | ||||
19 | sub message (&); | ||||
20 | sub inline_as (&); | ||||
21 | |||||
22 | ## -------------------------------------------------------- | ||||
23 | |||||
24 | 2 | 24µs | 1 | 6µs | # spent 6µs within Moose::Util::TypeConstraints::BEGIN@24 which was called:
# once (6µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 24 # spent 6µs making 1 call to Moose::Util::TypeConstraints::BEGIN@24 |
25 | 2 | 135µs | 1 | 3.45ms | # spent 3.45ms (1.17+2.28) within Moose::Util::TypeConstraints::BEGIN@25 which was called:
# once (1.17ms+2.28ms) by Moose::Meta::Attribute::BEGIN@16 at line 25 # spent 3.45ms making 1 call to Moose::Util::TypeConstraints::BEGIN@25 |
26 | 2 | 137µs | 1 | 5.10ms | # spent 5.10ms (694µs+4.41) within Moose::Util::TypeConstraints::BEGIN@26 which was called:
# once (694µs+4.41ms) by Moose::Meta::Attribute::BEGIN@16 at line 26 # spent 5.10ms making 1 call to Moose::Util::TypeConstraints::BEGIN@26 |
27 | 2 | 21µs | 1 | 6µs | # spent 6µs within Moose::Util::TypeConstraints::BEGIN@27 which was called:
# once (6µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 27 # spent 6µs making 1 call to Moose::Util::TypeConstraints::BEGIN@27 |
28 | 2 | 141µs | 1 | 1.78ms | # spent 1.78ms (795µs+988µs) within Moose::Util::TypeConstraints::BEGIN@28 which was called:
# once (795µs+988µs) by Moose::Meta::Attribute::BEGIN@16 at line 28 # spent 1.78ms making 1 call to Moose::Util::TypeConstraints::BEGIN@28 |
29 | 2 | 116µs | 1 | 1.62ms | # spent 1.62ms (637µs+985µs) within Moose::Util::TypeConstraints::BEGIN@29 which was called:
# once (637µs+985µs) by Moose::Meta::Attribute::BEGIN@16 at line 29 # spent 1.62ms making 1 call to Moose::Util::TypeConstraints::BEGIN@29 |
30 | 2 | 117µs | 1 | 2.10ms | # spent 2.10ms (697µs+1.40) within Moose::Util::TypeConstraints::BEGIN@30 which was called:
# once (697µs+1.40ms) by Moose::Meta::Attribute::BEGIN@16 at line 30 # spent 2.10ms making 1 call to Moose::Util::TypeConstraints::BEGIN@30 |
31 | 2 | 130µs | 1 | 1.97ms | # spent 1.97ms (760µs+1.21) within Moose::Util::TypeConstraints::BEGIN@31 which was called:
# once (760µs+1.21ms) by Moose::Meta::Attribute::BEGIN@16 at line 31 # spent 1.97ms making 1 call to Moose::Util::TypeConstraints::BEGIN@31 |
32 | 2 | 24µs | 1 | 8µ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 # spent 8µs making 1 call to Moose::Util::TypeConstraints::BEGIN@32 |
33 | 2 | 21µs | 1 | 6µs | # spent 6µs within Moose::Util::TypeConstraints::BEGIN@33 which was called:
# once (6µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 33 # spent 6µs making 1 call to Moose::Util::TypeConstraints::BEGIN@33 |
34 | 2 | 140µs | 1 | 2.28ms | # spent 2.28ms (527µs+1.75) within Moose::Util::TypeConstraints::BEGIN@34 which was called:
# once (527µs+1.75ms) by Moose::Meta::Attribute::BEGIN@16 at line 34 # spent 2.28ms making 1 call to Moose::Util::TypeConstraints::BEGIN@34 |
35 | |||||
36 | 2 | 102µs | 2 | 264µs | # spent 136µs (8+128) within Moose::Util::TypeConstraints::BEGIN@36 which was called:
# once (8µs+128µs) by Moose::Meta::Attribute::BEGIN@16 at line 36 # spent 136µs making 1 call to Moose::Util::TypeConstraints::BEGIN@36
# spent 128µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
37 | |||||
38 | 1 | 11µs | 1 | 1.18ms | Moose::Exporter->setup_import_methods( # spent 1.18ms 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 | |||||
55 | 1 | 7µs | 1 | 330µs | my $REGISTRY = Moose::Meta::TypeConstraint::Registry->new; # spent 330µs making 1 call to Moose::Meta::TypeConstraint::Registry::new |
56 | |||||
57 | sub get_type_constraint_registry {$REGISTRY} | ||||
58 | 1 | 6µs | 1 | 1µs | # spent 9µs (8+1000ns) within Moose::Util::TypeConstraints::list_all_type_constraints which was called:
# once (8µs+1000ns) by Moose::Meta::Attribute::BEGIN@16 at line 753 # spent 1µs making 1 call to Moose::Meta::TypeConstraint::Registry::type_constraints |
59 | |||||
60 | sub export_type_constraints_as_functions { | ||||
61 | my $pkg = caller(); | ||||
62 | 2 | 2.04ms | 2 | 33µs | # spent 20µs (8+12) within Moose::Util::TypeConstraints::BEGIN@62 which was called:
# once (8µs+12µs) by Moose::Meta::Attribute::BEGIN@16 at line 62 # spent 20µs making 1 call to Moose::Util::TypeConstraints::BEGIN@62
# spent 12µ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 | sub create_type_constraint_union { | ||||
72 | _create_type_constraint_union(\@_); | ||||
73 | } | ||||
74 | |||||
75 | sub create_named_type_constraint_union { | ||||
76 | my $name = shift; | ||||
77 | _create_type_constraint_union($name, \@_); | ||||
78 | } | ||||
79 | |||||
80 | sub _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 2.83ms (36µs+2.80) within Moose::Util::TypeConstraints::create_parameterized_type_constraint which was called 2 times, avg 1.42ms/call:
# 2 times (36µs+2.80ms) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 260, avg 1.42ms/call | ||||
112 | 2 | 1µs | my $type_constraint_name = shift; | ||
113 | 2 | 6µs | 2 | 83µs | my ( $base_type, $type_parameter ) # spent 83µs making 2 calls to Moose::Util::TypeConstraints::_parse_parameterized_type_constraint, avg 42µs/call |
114 | = _parse_parameterized_type_constraint($type_constraint_name); | ||||
115 | |||||
116 | 2 | 900ns | ( defined $base_type && defined $type_parameter ) | ||
117 | || throw_exception( InvalidTypeGivenToCreateParameterizedTypeConstraint => type_name => $type_constraint_name ); | ||||
118 | |||||
119 | 2 | 3µs | 2 | 12µs | if ( $REGISTRY->has_type_constraint($base_type) ) { # spent 12µs making 2 calls to Moose::Meta::TypeConstraint::Registry::has_type_constraint, avg 6µs/call |
120 | 2 | 3µs | 2 | 12µs | my $base_type_tc = $REGISTRY->get_type_constraint($base_type); # spent 12µs making 2 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 6µs/call |
121 | 2 | 9µs | 2 | 2.69ms | return _create_parameterized_type_constraint( # spent 2.69ms making 2 calls to Moose::Util::TypeConstraints::_create_parameterized_type_constraint, avg 1.34ms/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 2.69ms (24µs+2.67) within Moose::Util::TypeConstraints::_create_parameterized_type_constraint which was called 2 times, avg 1.34ms/call:
# 2 times (24µs+2.67ms) by Moose::Util::TypeConstraints::create_parameterized_type_constraint at line 121, avg 1.34ms/call | ||||
132 | 2 | 2µs | my ( $base_type_tc, $type_parameter ) = @_; | ||
133 | 2 | 24µs | 4 | 2.67ms | if ( $base_type_tc->can('parameterize') ) { # spent 2.66ms making 2 calls to Moose::Meta::TypeConstraint::Parameterizable::parameterize, avg 1.33ms/call
# spent 2µs making 2 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 15.2ms (564µs+14.7) within Moose::Util::TypeConstraints::create_class_type_constraint which was called 22 times, avg 692µs/call:
# 17 times (445µs+11.5ms) by Moose::Util::TypeConstraints::class_type at line 352, avg 705µs/call
# 5 times (119µs+3.11ms) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 246, avg 647µs/call | ||||
148 | 22 | 26µ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 | |||||
154 | 22 | 31µs | my $pkg_defined_in = $options->{package_defined_in} || scalar( caller(1) ); | ||
155 | |||||
156 | 22 | 51µs | 22 | 161µs | if (my $type = $REGISTRY->get_type_constraint($class)) { # spent 161µs making 22 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 7µ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, | ||||
171 | 22 | 76µs | %{ $options || {} }, # overrides options from above | ||
172 | ); | ||||
173 | |||||
174 | 22 | 6µs | $options{name} ||= "__ANON__"; | ||
175 | |||||
176 | 22 | 155µs | 22 | 13.9ms | my $tc = Moose::Meta::TypeConstraint::Class->new(%options); # spent 13.9ms making 22 calls to Moose::Meta::TypeConstraint::Class::new, avg 634µs/call |
177 | 22 | 54µs | 22 | 563µs | $REGISTRY->add_type_constraint($tc); # spent 563µs making 22 calls to Moose::Meta::TypeConstraint::Registry::add_type_constraint, avg 26µs/call |
178 | 22 | 93µs | return $tc; | ||
179 | } | ||||
180 | |||||
181 | # spent 2.12ms (76µs+2.04) within Moose::Util::TypeConstraints::create_role_type_constraint which was called 3 times, avg 705µs/call:
# 3 times (76µs+2.04ms) by Moose::Util::TypeConstraints::role_type at line 356, avg 705µs/call | ||||
182 | 3 | 3µ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 | |||||
188 | 3 | 5µs | my $pkg_defined_in = $options->{package_defined_in} || scalar( caller(1) ); | ||
189 | |||||
190 | 3 | 7µs | 3 | 20µs | if (my $type = $REGISTRY->get_type_constraint($role)) { # spent 20µs making 3 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 7µ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, | ||||
205 | 3 | 8µs | %{ $options || {} }, | ||
206 | ); | ||||
207 | |||||
208 | 3 | 1µs | $options{name} ||= "__ANON__"; | ||
209 | |||||
210 | 3 | 20µs | 3 | 1.95ms | my $tc = Moose::Meta::TypeConstraint::Role->new(%options); # spent 1.95ms making 3 calls to Moose::Meta::TypeConstraint::Role::new, avg 649µs/call |
211 | 3 | 7µs | 3 | 72µs | $REGISTRY->add_type_constraint($tc); # spent 72µs making 3 calls to Moose::Meta::TypeConstraint::Registry::add_type_constraint, avg 24µs/call |
212 | 3 | 13µs | return $tc; | ||
213 | } | ||||
214 | |||||
215 | sub 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 15.8ms (1.41+14.4) within Moose::Util::TypeConstraints::find_or_create_isa_type_constraint which was called 194 times, avg 82µs/call:
# 176 times (1.30ms+13.9ms) by Moose::Meta::Attribute::_process_isa_option at line 345 of Moose/Meta/Attribute.pm, avg 86µs/call
# 16 times (90µs+573µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 572, avg 41µs/call
# 2 times (17µs+-17µs) by Moose::Meta::TypeConstraint::Parameterizable::_parse_type_parameter at line 67 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 0s/call | ||||
245 | 194 | 129µs | my ($type_constraint_name, $options) = @_; | ||
246 | 194 | 951µs | 388 | 14.4ms | find_or_parse_type_constraint($type_constraint_name) # spent 11.1ms making 194 calls to Moose::Util::TypeConstraints::find_or_parse_type_constraint, avg 57µs/call, recursion: max depth 1, sum of overlapping time 63µs
# spent 3.23ms making 5 calls to Moose::Util::TypeConstraints::create_class_type_constraint, avg 647µs/call
# spent 166µs making 189 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 878ns/call |
247 | || create_class_type_constraint($type_constraint_name, $options); | ||||
248 | } | ||||
249 | |||||
250 | sub find_or_create_does_type_constraint { | ||||
251 | my ($type_constraint_name, $options) = @_; | ||||
252 | find_or_parse_type_constraint($type_constraint_name) | ||||
253 | || create_role_type_constraint($type_constraint_name, $options); | ||||
254 | } | ||||
255 | |||||
256 | # spent 11.0ms (2.12+8.90) within Moose::Util::TypeConstraints::find_or_parse_type_constraint which was called 194 times, avg 57µs/call:
# 194 times (2.12ms+8.90ms) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 246, avg 57µs/call | ||||
257 | 194 | 365µs | 194 | 1.14ms | my $type_constraint_name = normalize_type_constraint_name(shift); # spent 1.14ms making 194 calls to Moose::Util::TypeConstraints::normalize_type_constraint_name, avg 6µs/call |
258 | 194 | 26µs | my $constraint; | ||
259 | |||||
260 | 194 | 1.25ms | 397 | 7.78ms | if ( $constraint = find_type_constraint($type_constraint_name) ) { # spent 4.36ms making 194 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 22µs/call
# spent 2.83ms making 2 calls to Moose::Util::TypeConstraints::create_parameterized_type_constraint, avg 1.42ms/call
# spent 266µs making 187 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 1µs/call
# spent 197µs making 7 calls to Moose::Util::TypeConstraints::_detect_type_constraint_union, avg 28µs/call
# spent 125µs making 7 calls to Moose::Util::TypeConstraints::_detect_parameterized_type_constraint, avg 18µ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 { | ||||
271 | 5 | 13µs | return; | ||
272 | } | ||||
273 | |||||
274 | 2 | 5µs | 2 | 46µs | $REGISTRY->add_type_constraint($constraint); # spent 46µs making 2 calls to Moose::Meta::TypeConstraint::Registry::add_type_constraint, avg 23µs/call |
275 | 2 | 4µs | return $constraint; | ||
276 | } | ||||
277 | |||||
278 | # spent 1.14ms (923µs+221µs) within Moose::Util::TypeConstraints::normalize_type_constraint_name which was called 194 times, avg 6µs/call:
# 194 times (923µs+221µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 257, avg 6µs/call | ||||
279 | 194 | 67µs | my $type_constraint_name = shift; | ||
280 | 194 | 701µs | 194 | 222µs | $type_constraint_name =~ s/\s//g; # spent 222µs making 194 calls to Moose::Util::TypeConstraints::CORE:subst, avg 1µs/call |
281 | 194 | 457µs | return $type_constraint_name; | ||
282 | } | ||||
283 | |||||
284 | sub _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.64ms (2.28+3.36) within Moose::Util::TypeConstraints::find_type_constraint which was called 272 times, avg 21µs/call:
# 194 times (1.69ms+2.67ms) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 260, avg 22µs/call
# 22 times (172µs+240µs) by Moose::Meta::TypeConstraint::Class::new at line 30 of Moose/Meta/TypeConstraint/Class.pm, avg 19µs/call
# 20 times (89µs+27µs) by Moose::Meta::TypeConstraint::equals at line 234 of Moose/Meta/TypeConstraint.pm, avg 6µs/call
# 17 times (188µs+225µs) by Moose::init_meta at line 161 of Moose.pm, avg 24µs/call
# 8 times (58µs+84µs) by Moose::Meta::TypeConstraint::is_subtype_of at line 261 of Moose/Meta/TypeConstraint.pm, avg 18µs/call
# 3 times (30µs+37µs) by Moose::Role::init_meta at line 126 of Moose/Role.pm, avg 22µs/call
# 3 times (23µs+31µs) by Moose::Meta::TypeConstraint::Role::new at line 32 of Moose/Meta/TypeConstraint/Role.pm, avg 18µs/call
# once (7µs+9µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 198 of Moose/Util/TypeConstraints/Builtins.pm
# once (7µs+9µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 233 of Moose/Util/TypeConstraints/Builtins.pm
# once (7µs+9µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 79 of Moose/Util/TypeConstraints/Builtins.pm
# once (6µs+9µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 294 of Moose/Util/TypeConstraints/Builtins.pm
# once (6µs+9µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 268 of Moose/Util/TypeConstraints/Builtins.pm | ||||
296 | 272 | 95µs | my $type = shift; | ||
297 | |||||
298 | 272 | 739µs | 292 | 172µs | if ( blessed $type and $type->isa("Moose::Meta::TypeConstraint") ) { # spent 158µs making 272 calls to Scalar::Util::blessed, avg 583ns/call
# spent 13µs making 20 calls to UNIVERSAL::isa, avg 660ns/call |
299 | return $type; | ||||
300 | } | ||||
301 | else { | ||||
302 | 252 | 544µs | 252 | 1.94ms | return unless $REGISTRY->has_type_constraint($type); # spent 1.94ms making 252 calls to Moose::Meta::TypeConstraint::Registry::has_type_constraint, avg 8µs/call |
303 | 225 | 783µs | 225 | 1.25ms | return $REGISTRY->get_type_constraint($type); # spent 1.25ms making 225 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 6µs/call |
304 | } | ||||
305 | } | ||||
306 | |||||
307 | sub 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 442µs (13+429) within Moose::Util::TypeConstraints::type which was called:
# once (13µs+429µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 11 of Moose/Util/TypeConstraints/Builtins.pm | ||||
318 | 1 | 700ns | my $name = shift; | ||
319 | |||||
320 | 1 | 6µs | my %p = map { %{$_} } @_; | ||
321 | |||||
322 | 1 | 6µs | 1 | 429µs | return _create_type_constraint( # spent 429µs making 1 call to Moose::Util::TypeConstraints::_create_type_constraint |
323 | $name, undef, $p{where}, $p{message}, | ||||
324 | $p{inline_as}, | ||||
325 | ); | ||||
326 | } | ||||
327 | |||||
328 | # spent 5.71ms (154µs+5.55) within Moose::Util::TypeConstraints::subtype which was called 16 times, avg 357µs/call:
# 16 times (154µs+5.55ms) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 12 of Moose/Util/TypeConstraints/Builtins.pm, avg 357µs/call | ||||
329 | 16 | 4µ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. | ||||
335 | 16 | 7µs | my $name = ref $_[0] && !blessed $_[0] ? undef : shift; | ||
336 | |||||
337 | 16 | 71µs | my %p = map { %{$_} } @_; | ||
338 | |||||
339 | # subtype Str => where { ... }; | ||||
340 | 16 | 5µs | if ( !exists $p{as} ) { | ||
341 | $p{as} = $name; | ||||
342 | $name = undef; | ||||
343 | } | ||||
344 | |||||
345 | 16 | 59µs | 16 | 5.55ms | return _create_type_constraint( # spent 5.55ms making 16 calls to Moose::Util::TypeConstraints::_create_type_constraint, avg 347µs/call |
346 | $name, $p{as}, $p{where}, $p{message}, | ||||
347 | $p{inline_as}, | ||||
348 | ); | ||||
349 | } | ||||
350 | |||||
351 | # spent 12.1ms (79µs+12.0) within Moose::Util::TypeConstraints::class_type which was called 17 times, avg 710µs/call:
# 17 times (79µs+12.0ms) by Moose::init_meta at line 161 of Moose.pm, avg 710µs/call | ||||
352 | 17 | 70µs | 17 | 12.0ms | create_class_type_constraint(@_); # spent 12.0ms making 17 calls to Moose::Util::TypeConstraints::create_class_type_constraint, avg 705µs/call |
353 | } | ||||
354 | |||||
355 | # spent 2.13ms (14µs+2.12) within Moose::Util::TypeConstraints::role_type which was called 3 times, avg 710µs/call:
# 3 times (14µs+2.12ms) by Moose::Role::init_meta at line 126 of Moose/Role.pm, avg 710µs/call | ||||
356 | 3 | 13µs | 3 | 2.12ms | create_role_type_constraint(@_); # spent 2.12ms making 3 calls to Moose::Util::TypeConstraints::create_role_type_constraint, avg 705µs/call |
357 | } | ||||
358 | |||||
359 | sub maybe_type { | ||||
360 | my ($type_parameter) = @_; | ||||
361 | |||||
362 | register_type_constraint( | ||||
363 | $REGISTRY->get_type_constraint('Maybe')->parameterize($type_parameter) | ||||
364 | ); | ||||
365 | } | ||||
366 | |||||
367 | sub 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 | sub 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. | ||||
410 | 16 | 41µs | # spent 29µs within Moose::Util::TypeConstraints::as which was called 16 times, avg 2µs/call:
# 16 times (29µs+0s) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 13 of Moose/Util/TypeConstraints/Builtins.pm, avg 2µs/call | ||
411 | 16 | 38µs | # spent 24µs within Moose::Util::TypeConstraints::where which was called 16 times, avg 2µs/call:
# 16 times (24µs+0s) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 14 of Moose/Util/TypeConstraints/Builtins.pm, avg 2µs/call | ||
412 | sub message (&) { { message => $_[0] } } | ||||
413 | 17 | 37µs | # spent 22µs within Moose::Util::TypeConstraints::inline_as which was called 17 times, avg 1µs/call:
# 17 times (22µs+0s) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 15 of Moose/Util/TypeConstraints/Builtins.pm, avg 1µs/call | ||
414 | |||||
415 | sub from {@_} | ||||
416 | sub via (&) { $_[0] } | ||||
417 | |||||
418 | sub 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 | |||||
452 | sub 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 | |||||
473 | sub 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 | |||||
482 | sub 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 | |||||
491 | sub 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 | sub _create_type_constraint ($$$;$) { | ||||
540 | 17 | 4µs | my $name = shift; | ||
541 | 17 | 4µs | my $parent = shift; | ||
542 | 17 | 2µs | my $check = shift; | ||
543 | 17 | 7µs | my $message = shift; | ||
544 | 17 | 2µs | my $inlined = shift; | ||
545 | |||||
546 | 17 | 9µs | my $pkg_defined_in = scalar( caller(1) ); | ||
547 | |||||
548 | 17 | 5µs | if ( defined $name ) { | ||
549 | 17 | 20µs | 17 | 91µs | my $type = $REGISTRY->get_type_constraint($name); # spent 91µs making 17 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 5µs/call |
550 | |||||
551 | 17 | 2µ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 | |||||
557 | 17 | 69µs | 17 | 36µs | if( $name !~ /^[\w:\.]+$/ ) { # spent 36µs making 17 calls to Moose::Util::TypeConstraints::CORE:match, avg 2µs/call |
558 | throw_exception( InvalidNameForType => name => $name ); | ||||
559 | } | ||||
560 | } | ||||
561 | |||||
562 | 17 | 32µ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 | |||||
571 | 17 | 1µs | my $constraint; | ||
572 | 17 | 110µs | 64 | 4.83ms | if ( # spent 4.15ms making 16 calls to Moose::Meta::TypeConstraint::create_child_type, avg 259µs/call
# spent 662µs making 16 calls to Moose::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 41µs/call
# spent 12µs making 16 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 756ns/call
# spent 10µs making 16 calls to Scalar::Util::blessed, avg 612ns/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 { | ||||
582 | 1 | 6µs | 1 | 347µs | $constraint = Moose::Meta::TypeConstraint->new(%opts); # spent 347µs making 1 call to Moose::Meta::TypeConstraint::new |
583 | } | ||||
584 | |||||
585 | 17 | 23µs | 17 | 297µs | $REGISTRY->add_type_constraint($constraint) # spent 297µs making 17 calls to Moose::Meta::TypeConstraint::Registry::add_type_constraint, avg 17µs/call |
586 | if defined $name; | ||||
587 | |||||
588 | 17 | 45µs | return $constraint; | ||
589 | } | ||||
590 | |||||
591 | sub _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 | |||||
621 | 3 | 352µs | 2 | 1.53ms | # spent 1.52ms (1.12+405µs) within Moose::Util::TypeConstraints::BEGIN@621 which was called:
# once (1.12ms+405µs) by Moose::Meta::Attribute::BEGIN@16 at line 621 # spent 1.52ms making 1 call to Moose::Util::TypeConstraints::BEGIN@621
# spent 13µs making 1 call to re::import |
622 | |||||
623 | 1 | 10µs | 1 | 6µs | my $valid_chars = qr{[\w:\.]}; # spent 6µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
624 | 1 | 27µs | 2 | 20µs | my $type_atom = qr{ (?>$valid_chars+) }x; # spent 19µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp
# spent 1µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
625 | 1 | 3µs | 1 | 1µs | my $ws = qr{ (?>\s*) }x; # spent 1µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
626 | 1 | 18µs | 2 | 14µs | my $op_union = qr{ $ws \| $ws }x; # spent 13µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp
# spent 1µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
627 | |||||
628 | 1 | 400ns | my ($type, $type_capture_parts, $type_with_parameter, $union, $any); | ||
629 | 1 | 3µs | if (Class::MOP::IS_RUNNING_ON_5_10) { | ||
630 | 1 | 500ns | my $type_pattern | ||
631 | = q{ (?&type_atom) (?: \[ (?&ws) (?&any) (?&ws) \] )? }; | ||||
632 | 1 | 300ns | my $type_capture_parts_pattern | ||
633 | = q{ ((?&type_atom)) (?: \[ (?&ws) ((?&any)) (?&ws) \] )? }; | ||||
634 | 1 | 700ns | my $type_with_parameter_pattern | ||
635 | = q{ (?&type_atom) \[ (?&ws) (?&any) (?&ws) \] }; | ||||
636 | 1 | 400ns | my $union_pattern | ||
637 | = q{ (?&type) (?> (?: (?&op_union) (?&type) )+ ) }; | ||||
638 | 1 | 200ns | my $any_pattern | ||
639 | = q{ (?&type) | (?&union) }; | ||||
640 | |||||
641 | 1 | 64µs | 2 | 56µs | my $defines = qr{(?(DEFINE) # spent 55µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp
# spent 1µs 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 | |||||
653 | 1 | 74µs | 2 | 65µs | $type = qr{ $type_pattern $defines }x; # spent 64µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp
# spent 1µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
654 | 1 | 123µs | 2 | 104µs | $type_capture_parts = qr{ $type_capture_parts_pattern $defines }x; # spent 101µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp
# spent 4µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
655 | 1 | 102µs | 2 | 88µs | $type_with_parameter = qr{ $type_with_parameter_pattern $defines }x; # spent 81µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp
# spent 7µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
656 | 1 | 70µs | 2 | 59µs | $union = qr{ $union_pattern $defines }x; # spent 57µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp
# spent 2µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
657 | 1 | 86µs | 2 | 59µs | $any = qr{ $any_pattern $defines }x; # spent 57µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp
# spent 2µ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 83µs (27+56) within Moose::Util::TypeConstraints::_parse_parameterized_type_constraint which was called 2 times, avg 42µs/call:
# 2 times (27µs+56µs) by Moose::Util::TypeConstraints::create_parameterized_type_constraint at line 113, avg 42µs/call | ||||
674 | 6 | 71µs | 2 | 41µs | # spent 26µs (11+15) within Moose::Util::TypeConstraints::BEGIN@674 which was called:
# once (11µs+15µs) by Moose::Meta::Attribute::BEGIN@16 at line 674 # spent 26µs making 1 call to Moose::Util::TypeConstraints::BEGIN@674
# spent 15µs making 1 call to warnings::unimport |
675 | 2 | 70µs | 4 | 56µs | $_[0] =~ m{ $type_capture_parts }x; # spent 47µs making 2 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 24µs/call
# spent 9µs making 2 calls to Moose::Util::TypeConstraints::CORE:match, avg 5µs/call |
676 | 2 | 14µs | return ( $1, $2 ); | ||
677 | } | ||||
678 | |||||
679 | # spent 125µs (53+72) within Moose::Util::TypeConstraints::_detect_parameterized_type_constraint which was called 7 times, avg 18µs/call:
# 7 times (53µs+72µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 260, avg 18µs/call | ||||
680 | 16 | 62µs | 2 | 28µs | # spent 18µs (9+9) within Moose::Util::TypeConstraints::BEGIN@680 which was called:
# once (9µs+9µs) by Moose::Meta::Attribute::BEGIN@16 at line 680 # spent 18µs making 1 call to Moose::Util::TypeConstraints::BEGIN@680
# spent 9µs making 1 call to warnings::unimport |
681 | 7 | 117µs | 14 | 72µs | $_[0] =~ m{ ^ $type_with_parameter $ }x; # spent 50µs making 7 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 7µs/call
# spent 22µs making 7 calls to Moose::Util::TypeConstraints::CORE:match, avg 3µs/call |
682 | } | ||||
683 | |||||
684 | sub _parse_type_constraint_union { | ||||
685 | 2 | 98µs | 2 | 25µs | # spent 17µs (8+9) within Moose::Util::TypeConstraints::BEGIN@685 which was called:
# once (8µs+9µs) by Moose::Meta::Attribute::BEGIN@16 at line 685 # spent 17µs making 1 call to Moose::Util::TypeConstraints::BEGIN@685
# spent 8µ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 197µs (69+127) within Moose::Util::TypeConstraints::_detect_type_constraint_union which was called 7 times, avg 28µs/call:
# 7 times (69µs+127µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 260, avg 28µs/call | ||||
699 | 16 | 269µs | 2 | 25µs | # spent 17µs (8+8) within Moose::Util::TypeConstraints::BEGIN@699 which was called:
# once (8µs+8µs) by Moose::Meta::Attribute::BEGIN@16 at line 699 # spent 17µs making 1 call to Moose::Util::TypeConstraints::BEGIN@699
# spent 8µs making 1 call to warnings::unimport |
700 | 7 | 190µs | 14 | 127µs | $_[0] =~ m{^ $type $op_union $type ( $op_union .* )? $}x; # spent 121µs making 7 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 17µs/call
# spent 6µs making 7 calls to Moose::Util::TypeConstraints::CORE:match, avg 857ns/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( | ||||
712 | 9 | 12µs | 9 | 9µs | inline_constructor => 1, # spent 9µs making 9 calls to Class::MOP::Class::is_mutable, avg 956ns/call |
713 | constructor_name => "_new", | ||||
714 | |||||
715 | # these are Class::MOP accessors, so they need inlining | ||||
716 | inline_accessors => 1 | ||||
717 | 10 | 46µs | 18 | 41.2ms | ) for grep { $_->is_mutable } # spent 41.1ms making 9 calls to Class::MOP::Class::make_immutable, avg 4.57ms/call
# spent 47µs making 9 calls to Class::MOP::class_of, avg 5µ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 | |||||
731 | 1 | 173µs | require Moose::Util::TypeConstraints::Builtins; | ||
732 | 1 | 3µs | 1 | 7.98ms | Moose::Util::TypeConstraints::Builtins::define_builtins($REGISTRY); # spent 7.98ms making 1 call to Moose::Util::TypeConstraints::Builtins::define_builtins |
733 | |||||
734 | my @PARAMETERIZABLE_TYPES | ||||
735 | 5 | 8µs | 4 | 18µs | = map { $REGISTRY->get_type_constraint($_) } qw[ScalarRef ArrayRef HashRef Maybe]; # spent 18µs making 4 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 4µs/call |
736 | |||||
737 | 2 | 9µs | # spent 4µs within Moose::Util::TypeConstraints::get_all_parameterizable_types which was called 2 times, avg 2µs/call:
# 2 times (4µs+0s) by Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint at line 54 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 2µs/call | ||
738 | |||||
739 | sub 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 | { | ||||
753 | 2 | 5µs | 1 | 9µs | my @BUILTINS = list_all_type_constraints(); # spent 9µs making 1 call to Moose::Util::TypeConstraints::list_all_type_constraints |
754 | sub list_all_builtin_type_constraints {@BUILTINS} | ||||
755 | } | ||||
756 | |||||
757 | 1 | 80µs | 1; | ||
758 | |||||
759 | # ABSTRACT: Type constraint system for Moose | ||||
760 | |||||
761 | __END__ | ||||
# spent 73µs within Moose::Util::TypeConstraints::CORE:match which was called 33 times, avg 2µs/call:
# 17 times (36µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint at line 557, avg 2µs/call
# 7 times (22µs+0s) by Moose::Util::TypeConstraints::_detect_parameterized_type_constraint at line 681, avg 3µs/call
# 7 times (6µs+0s) by Moose::Util::TypeConstraints::_detect_type_constraint_union at line 700, avg 857ns/call
# 2 times (9µs+0s) by Moose::Util::TypeConstraints::_parse_parameterized_type_constraint at line 675, avg 5µs/call | |||||
# spent 25µs within Moose::Util::TypeConstraints::CORE:qr which was called 10 times, avg 2µs/call:
# once (7µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 655
# once (6µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 623
# once (4µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 654
# once (2µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 657
# 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 653
# once (1µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 641
# once (1µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 624
# once (1µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 625
# once (1µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 626 | |||||
# spent 664µs within Moose::Util::TypeConstraints::CORE:regcomp which was called 24 times, avg 28µs/call:
# 7 times (121µs+0s) by Moose::Util::TypeConstraints::_detect_type_constraint_union at line 700, avg 17µs/call
# 7 times (50µs+0s) by Moose::Util::TypeConstraints::_detect_parameterized_type_constraint at line 681, avg 7µs/call
# 2 times (47µs+0s) by Moose::Util::TypeConstraints::_parse_parameterized_type_constraint at line 675, avg 24µs/call
# once (101µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 654
# once (81µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 655
# once (64µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 653
# once (57µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 656
# once (57µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 657
# once (55µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 641
# once (19µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 624
# once (13µs+0s) by Moose::Meta::Attribute::BEGIN@16 at line 626 | |||||
# spent 222µs within Moose::Util::TypeConstraints::CORE:subst which was called 194 times, avg 1µs/call:
# 194 times (222µs+0s) by Moose::Util::TypeConstraints::normalize_type_constraint_name at line 280, avg 1µs/call |