Filename | /home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/x86_64-linux/Mouse/Meta/TypeConstraint.pm |
Statements | Executed 1063 statements in 4.11ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
47 | 4 | 2 | 1.72ms | 1.80ms | new | Mouse::Meta::TypeConstraint::
14 | 2 | 1 | 457µs | 624µs | is_a_type_of | Mouse::Meta::TypeConstraint::
181 | 7 | 4 | 283µs | 283µs | _identity (xsub) | Mouse::Meta::TypeConstraint::
16 | 1 | 1 | 267µs | 345µs | __ANON__[:119] | Mouse::Meta::TypeConstraint::
17 | 1 | 1 | 224µs | 604µs | coerce | Mouse::Meta::TypeConstraint::
98 | 5 | 3 | 164µs | 164µs | name (xsub) | Mouse::Meta::TypeConstraint::
43 | 14 | 7 | 72µs | 72µs | _compiled_type_constraint (xsub) | Mouse::Meta::TypeConstraint::
33 | 2 | 1 | 62µs | 62µs | check (xsub) | Mouse::Meta::TypeConstraint::
42 | 2 | 1 | 55µs | 55µs | parent (xsub) | Mouse::Meta::TypeConstraint::
6 | 1 | 1 | 42µs | 42µs | compile_type_constraint (xsub) | Mouse::Meta::TypeConstraint::
1 | 1 | 1 | 41µs | 73µs | _add_type_coercions | Mouse::Meta::TypeConstraint::
2 | 1 | 1 | 28µs | 206µs | parameterize | Mouse::Meta::TypeConstraint::
1 | 1 | 1 | 24µs | 102µs | BEGIN@2 | Mouse::Meta::TypeConstraint::
14 | 1 | 1 | 19µs | 19µs | CORE:subst (opcode) | Mouse::Meta::TypeConstraint::
1 | 1 | 1 | 12µs | 12µs | _compile_type_coercion | Mouse::Meta::TypeConstraint::
2 | 1 | 1 | 3µs | 3µs | has_coercion (xsub) | Mouse::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:140] | Mouse::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | _as_string | Mouse::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | _compile_union_type_coercion | Mouse::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | _unite | Mouse::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | assert_valid | Mouse::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | create_child_type | Mouse::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | get_message | Mouse::Meta::TypeConstraint::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Mouse::Meta::TypeConstraint; | ||||
2 | 2 | 1.02ms | 2 | 179µs | # spent 102µs (24+77) within Mouse::Meta::TypeConstraint::BEGIN@2 which was called:
# once (24µs+77µs) by Mouse::Meta::Attribute::BEGIN@6 at line 2 # spent 102µs making 1 call to Mouse::Meta::TypeConstraint::BEGIN@2
# spent 77µs making 1 call to Mouse::Exporter::do_import |
3 | |||||
4 | # spent 1.80ms (1.72+74µs) within Mouse::Meta::TypeConstraint::new which was called 47 times, avg 38µs/call:
# 24 times (944µs+15µs) by Mouse::Util::TypeConstraints::_define_type at line 168 of Mouse/Util/TypeConstraints.pm, avg 40µs/call
# 20 times (590µs+8µs) by Mouse::BEGIN@18 at line 69 of Mouse/Util/TypeConstraints.pm, avg 30µs/call
# 2 times (135µs+43µs) by Mouse::Meta::TypeConstraint::parameterize at line 204, avg 89µs/call
# once (55µs+9µs) by Mouse::BEGIN@18 at line 29 of Mouse/Util/TypeConstraints.pm | ||||
5 | 517 | 1.20ms | my $class = shift; | ||
6 | my %args = @_ == 1 ? %{$_[0]} : @_; | ||||
7 | |||||
8 | $args{name} = '__ANON__' if !defined $args{name}; | ||||
9 | |||||
10 | 184 | 509µs | if(defined $args{parent}) { | ||
11 | %args = (%{$args{parent}}, %args); | ||||
12 | # a child type must not inherit 'compiled_type_constraint' | ||||
13 | # and 'hand_optimized_type_constraint' from the parent | ||||
14 | delete $args{compiled_type_constraint}; | ||||
15 | delete $args{hand_optimized_type_constraint}; | ||||
16 | if(defined(my $parent_tp = $args{parent}{type_parameter})) { | ||||
17 | delete $args{type_parameter} if $parent_tp == $args{type_parameter}; | ||||
18 | } | ||||
19 | } | ||||
20 | |||||
21 | my $check; | ||||
22 | |||||
23 | 90 | 142µs | 2 | 3µs | if($check = delete $args{optimized}) { # spent 3µs making 2 calls to Mouse::Meta::TypeConstraint::_identity, avg 2µs/call |
24 | $args{hand_optimized_type_constraint} = $check; | ||||
25 | $args{compiled_type_constraint} = $check; | ||||
26 | } | ||||
27 | elsif(my $param = $args{type_parameter}) { | ||||
28 | my $generator = $args{constraint_generator} | ||||
29 | || $class->throw_error("The $args{name} constraint cannot be used," | ||||
30 | . " because $param doesn't subtype from a parameterizable type"); | ||||
31 | # it must be 'constraint' | ||||
32 | 4 | 35µs | $check = $args{constraint} = $generator->($param); # spent 29µs making 2 calls to Mouse::Util::TypeConstraints::_parameterize_HashRef_for, avg 15µs/call
# spent 6µs making 2 calls to Mouse::Meta::TypeConstraint::_compiled_type_constraint, avg 3µs/call | ||
33 | } | ||||
34 | else { | ||||
35 | $check = $args{constraint}; | ||||
36 | } | ||||
37 | |||||
38 | if(defined($check) && ref($check) ne 'CODE'){ | ||||
39 | $class->throw_error( | ||||
40 | "Constraint for $args{name} is not a CODE reference"); | ||||
41 | } | ||||
42 | |||||
43 | my $self = bless \%args, $class; | ||||
44 | 6 | 42µs | $self->compile_type_constraint() # spent 42µs making 6 calls to Mouse::Meta::TypeConstraint::compile_type_constraint, avg 7µs/call | ||
45 | if !$args{hand_optimized_type_constraint}; | ||||
46 | |||||
47 | if($args{type_constraints}) { | ||||
48 | $self->_compile_union_type_coercion(); | ||||
49 | } | ||||
50 | return $self; | ||||
51 | } | ||||
52 | |||||
53 | sub create_child_type { | ||||
54 | my $self = shift; | ||||
55 | return ref($self)->new(@_, parent => $self); | ||||
56 | } | ||||
57 | |||||
58 | sub name; | ||||
59 | sub parent; | ||||
60 | sub message; | ||||
61 | sub has_coercion; | ||||
62 | |||||
63 | sub check; | ||||
64 | |||||
65 | sub type_parameter; | ||||
66 | sub __is_parameterized; | ||||
67 | |||||
68 | sub _compiled_type_constraint; | ||||
69 | sub _compiled_type_coercion; | ||||
70 | |||||
71 | sub compile_type_constraint; | ||||
72 | |||||
73 | |||||
74 | # spent 73µs (41+32) within Mouse::Meta::TypeConstraint::_add_type_coercions which was called:
# once (41µs+32µs) by Mouse::Util::TypeConstraints::coerce at line 191 of Mouse/Util/TypeConstraints.pm | ||||
75 | 8 | 23µs | my $self = shift; | ||
76 | |||||
77 | if(exists $self->{type_constraints}){ # union type | ||||
78 | $self->throw_error( | ||||
79 | "Cannot add additional type coercions to Union types '$self'"); | ||||
80 | } | ||||
81 | |||||
82 | my $coercions = ($self->{coercion_map} ||= []); | ||||
83 | my %has = map{ $_->[0] => undef } @{$coercions}; | ||||
84 | |||||
85 | 5 | 16µs | for(my $i = 0; $i < @_; $i++){ | ||
86 | my $from = $_[ $i]; | ||||
87 | my $action = $_[++$i]; | ||||
88 | |||||
89 | if(exists $has{$from}){ | ||||
90 | $self->throw_error("A coercion action already exists for '$from'"); | ||||
91 | } | ||||
92 | |||||
93 | 2 | 20µs | my $type = Mouse::Util::TypeConstraints::find_or_parse_type_constraint($from) # spent 18µs making 1 call to Mouse::Util::TypeConstraints::find_or_parse_type_constraint
# spent 2µs making 1 call to Mouse::Meta::TypeConstraint::_identity | ||
94 | or $self->throw_error( | ||||
95 | "Could not find the type constraint ($from) to coerce from"); | ||||
96 | |||||
97 | push @{$coercions}, [ $type => $action ]; | ||||
98 | } | ||||
99 | |||||
100 | 1 | 12µs | $self->_compile_type_coercion(); # spent 12µs making 1 call to Mouse::Meta::TypeConstraint::_compile_type_coercion | ||
101 | return; | ||||
102 | } | ||||
103 | |||||
104 | # spent 12µs within Mouse::Meta::TypeConstraint::_compile_type_coercion which was called:
# once (12µs+0s) by Mouse::Meta::TypeConstraint::_add_type_coercions at line 100 | ||||
105 | 4 | 14µs | my($self) = @_; | ||
106 | |||||
107 | my @coercions = @{$self->{coercion_map}}; | ||||
108 | |||||
109 | # spent 345µs (267+77) within Mouse::Meta::TypeConstraint::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/x86_64-linux/Mouse/Meta/TypeConstraint.pm:119] which was called 16 times, avg 22µs/call:
# 16 times (267µs+77µs) by Mouse::Meta::TypeConstraint::coerce at line 151, avg 22µs/call | ||||
110 | 32 | 42µs | my($thing) = @_; | ||
111 | foreach my $pair (@coercions) { | ||||
112 | #my ($constraint, $converter) = @$pair; | ||||
113 | 48 | 236µs | 16 | 27µs | if ($pair->[0]->check($thing)) { # spent 27µs making 16 calls to Mouse::Meta::TypeConstraint::check, avg 2µs/call |
114 | local $_ = $thing; | ||||
115 | 16 | 50µs | return $pair->[1]->($thing); # spent 50µs making 16 calls to MouseX::Getopt::Meta::Attribute::Trait::__ANON__[MouseX/Getopt/Meta/Attribute/Trait.pm:25], avg 3µs/call | ||
116 | } | ||||
117 | } | ||||
118 | return $thing; | ||||
119 | }; | ||||
120 | return; | ||||
121 | } | ||||
122 | |||||
123 | sub _compile_union_type_coercion { | ||||
124 | my($self) = @_; | ||||
125 | |||||
126 | my @coercions; | ||||
127 | foreach my $type(@{$self->{type_constraints}}){ | ||||
128 | if($type->has_coercion){ | ||||
129 | push @coercions, $type; | ||||
130 | } | ||||
131 | } | ||||
132 | if(@coercions){ | ||||
133 | $self->{_compiled_type_coercion} = sub { | ||||
134 | my($thing) = @_; | ||||
135 | foreach my $type(@coercions){ | ||||
136 | my $value = $type->coerce($thing); | ||||
137 | return $value if $self->check($value); | ||||
138 | } | ||||
139 | return $thing; | ||||
140 | }; | ||||
141 | } | ||||
142 | return; | ||||
143 | } | ||||
144 | |||||
145 | # spent 604µs (224+380) within Mouse::Meta::TypeConstraint::coerce which was called 17 times, avg 36µs/call:
# 17 times (224µs+380µs) by Mouse::Meta::Class::_initialize_object at line 83 of Mouse/Meta/Attribute.pm, avg 36µs/call | ||||
146 | 66 | 252µs | my $self = shift; | ||
147 | 17 | 35µs | return $_[0] if $self->check(@_); # spent 35µs making 17 calls to Mouse::Meta::TypeConstraint::check, avg 2µs/call | ||
148 | |||||
149 | my $coercion = $self->{_compiled_type_coercion} | ||||
150 | or $self->throw_error("Cannot coerce without a type coercion"); | ||||
151 | 16 | 345µs | return $coercion->(@_); # spent 345µs making 16 calls to Mouse::Meta::TypeConstraint::__ANON__[Mouse/Meta/TypeConstraint.pm:119], avg 22µs/call | ||
152 | } | ||||
153 | |||||
154 | sub get_message { | ||||
155 | my ($self, $value) = @_; | ||||
156 | if ( my $msg = $self->message ) { | ||||
157 | local $_ = $value; | ||||
158 | return $msg->($value); | ||||
159 | } | ||||
160 | else { | ||||
161 | if(not defined $value) { | ||||
162 | $value = 'undef'; | ||||
163 | } | ||||
164 | elsif( ref($value) && defined(&overload::StrVal) ) { | ||||
165 | $value = overload::StrVal($value); | ||||
166 | } | ||||
167 | return "Validation failed for '$self' with value $value"; | ||||
168 | } | ||||
169 | } | ||||
170 | |||||
171 | # spent 624µs (457+167) within Mouse::Meta::TypeConstraint::is_a_type_of which was called 14 times, avg 45µs/call:
# 7 times (247µs+76µs) by Mouse::Meta::Attribute::_process_options at line 56 of Mouse/Meta/Attribute.pm, avg 46µs/call
# 7 times (209µs+91µs) by Mouse::Meta::Method::Accessor::XS::_generate_reader at line 257 of Mouse/Meta/Attribute.pm, avg 43µs/call | ||||
172 | 98 | 634µs | my($self, $other) = @_; | ||
173 | |||||
174 | # ->is_a_type_of('__ANON__') is always false | ||||
175 | return 0 if !ref($other) && $other eq '__ANON__'; | ||||
176 | |||||
177 | 14 | 19µs | (my $other_name = $other) =~ s/\s+//g; # spent 19µs making 14 calls to Mouse::Meta::TypeConstraint::CORE:subst, avg 1µs/call | ||
178 | |||||
179 | 14 | 22µs | return 1 if $self->name eq $other_name; # spent 22µs making 14 calls to Mouse::Meta::TypeConstraint::name, avg 2µs/call | ||
180 | |||||
181 | if(exists $self->{type_constraints}){ # union | ||||
182 | foreach my $type(@{$self->{type_constraints}}) { | ||||
183 | return 1 if $type->name eq $other_name; | ||||
184 | } | ||||
185 | } | ||||
186 | |||||
187 | 66 | 109µs | for(my $p = $self->parent; defined $p; $p = $p->parent) { # spent 71µs making 36 calls to Mouse::Meta::TypeConstraint::name, avg 2µs/call
# spent 38µs making 30 calls to Mouse::Meta::TypeConstraint::parent, avg 1µs/call | ||
188 | return 1 if $p->name eq $other_name; | ||||
189 | 12 | 17µs | } # spent 17µs making 12 calls to Mouse::Meta::TypeConstraint::parent, avg 1µs/call | ||
190 | |||||
191 | return 0; | ||||
192 | } | ||||
193 | |||||
194 | # See also Moose::Meta::TypeConstraint::Parameterizable | ||||
195 | # spent 206µs (28+177) within Mouse::Meta::TypeConstraint::parameterize which was called 2 times, avg 103µs/call:
# 2 times (28µs+177µs) by Mouse::Util::TypeConstraints::_find_or_create_parameterized_type at line 289 of Mouse/Util/TypeConstraints.pm, avg 103µs/call | ||||
196 | 8 | 28µs | my($self, $param, $name) = @_; | ||
197 | |||||
198 | if(!ref $param){ | ||||
199 | require Mouse::Util::TypeConstraints; | ||||
200 | $param = Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint($param); | ||||
201 | } | ||||
202 | |||||
203 | $name ||= sprintf '%s[%s]', $self->name, $param->name; | ||||
204 | 2 | 177µs | return Mouse::Meta::TypeConstraint->new( # spent 177µs making 2 calls to Mouse::Meta::TypeConstraint::new, avg 89µs/call | ||
205 | name => $name, | ||||
206 | parent => $self, | ||||
207 | type_parameter => $param, | ||||
208 | ); | ||||
209 | } | ||||
210 | |||||
211 | sub assert_valid { | ||||
212 | my ($self, $value) = @_; | ||||
213 | |||||
214 | if(!$self->check($value)){ | ||||
215 | $self->throw_error($self->get_message($value)); | ||||
216 | } | ||||
217 | return 1; | ||||
218 | } | ||||
219 | |||||
220 | sub _as_string { $_[0]->name } # overload "" | ||||
221 | sub _identity; # overload 0+ | ||||
222 | |||||
223 | sub _unite { # overload infix:<|> | ||||
224 | my($lhs, $rhs) = @_; | ||||
225 | require Mouse::Util::TypeConstraints; | ||||
226 | return Mouse::Util::TypeConstraints::find_or_parse_type_constraint( | ||||
227 | " $lhs | $rhs", | ||||
228 | ); | ||||
229 | } | ||||
230 | |||||
231 | 1 | 2µs | 1; | ||
232 | __END__ | ||||
# spent 19µs within Mouse::Meta::TypeConstraint::CORE:subst which was called 14 times, avg 1µs/call:
# 14 times (19µs+0s) by Mouse::Meta::TypeConstraint::is_a_type_of at line 177, avg 1µs/call | |||||
# spent 72µs within Mouse::Meta::TypeConstraint::_compiled_type_constraint which was called 43 times, avg 2µs/call:
# 19 times (29µs+0s) by Mouse::Object::new at line 78 of MouseX/Getopt/Basic.pm, avg 2µs/call
# 10 times (15µs+0s) by Mouse::Object::new at line 201 of lib/Hailo.pm, avg 2µs/call
# 2 times (6µs+0s) by Mouse::Util::TypeConstraints::_parameterize_HashRef_for at line 32, avg 3µs/call
# 2 times (4µs+0s) by Mouse::Meta::Class::_initialize_object at line 83 of Mouse/Meta/Attribute.pm, avg 2µs/call
# once (3µs+0s) by Hailo::Storage::dbh at line 62 of lib/Hailo/Storage/SQLite.pm
# once (2µs+0s) by Hailo::Storage::sth at line 116 of lib/Hailo/Storage.pm
# once (2µs+0s) by Hailo::_tokenizer at line 288 of lib/Hailo.pm
# once (2µs+0s) by Hailo::Storage::dbd_options at line 55 of lib/Hailo/Storage.pm
# once (2µs+0s) by Hailo::_engine at line 286 of lib/Hailo.pm
# once (2µs+0s) by Hailo::Storage::dbi_options at line 39 of lib/Hailo/Storage.pm
# once (2µs+0s) by Hailo::Storage::_boundary_token_id at line 126 of lib/Hailo/Storage.pm
# once (2µs+0s) by Hailo::_storage at line 221 of lib/Hailo/Command.pm
# once (1µs+0s) by Hailo::Command::brain at line 153 of lib/Hailo/Command.pm
# once (1µs+0s) by Hailo::Storage::dbd at line 54 of lib/Hailo/Storage.pm | |||||
# spent 283µs within Mouse::Meta::TypeConstraint::_identity which was called 181 times, avg 2µs/call:
# 85 times (124µs+0s) by Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint at line 418 of Mouse/Util/TypeConstraints.pm, avg 1µs/call
# 84 times (140µs+0s) by Mouse::Util::TypeConstraints::find_or_parse_type_constraint at line 397 of Mouse/Util/TypeConstraints.pm, avg 2µs/call
# 5 times (8µs+0s) by Mouse::init_meta at line 143 of Mouse.pm, avg 2µs/call
# 3 times (6µs+0s) by Mouse::Role::init_meta at line 124 of Mouse/Role.pm, avg 2µs/call
# 2 times (3µs+0s) by Mouse::Meta::TypeConstraint::new at line 23, avg 2µs/call
# once (2µs+0s) by Mouse::Util::TypeConstraints::coerce at line 188 of Mouse/Util/TypeConstraints.pm
# once (2µs+0s) by Mouse::Meta::TypeConstraint::_add_type_coercions at line 93 | |||||
# spent 62µs within Mouse::Meta::TypeConstraint::check which was called 33 times, avg 2µs/call:
# 17 times (35µs+0s) by Mouse::Meta::TypeConstraint::coerce at line 147, avg 2µs/call
# 16 times (27µs+0s) by Mouse::Meta::TypeConstraint::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/x86_64-linux/Mouse/Meta/TypeConstraint.pm:119] at line 113, avg 2µs/call | |||||
# spent 42µs within Mouse::Meta::TypeConstraint::compile_type_constraint which was called 6 times, avg 7µs/call:
# 6 times (42µs+0s) by Mouse::Meta::TypeConstraint::new at line 44, avg 7µs/call | |||||
# spent 3µs within Mouse::Meta::TypeConstraint::has_coercion which was called 2 times, avg 2µs/call:
# 2 times (3µs+0s) by Mouse::Meta::Method::Accessor::XS::_generate_accessor at line 257 of Mouse/Meta/Attribute.pm, avg 2µs/call | |||||
# spent 164µs within Mouse::Meta::TypeConstraint::name which was called 98 times, avg 2µs/call:
# 36 times (71µs+0s) by Mouse::Meta::TypeConstraint::is_a_type_of at line 187, avg 2µs/call
# 22 times (32µs+0s) by MouseX::Getopt::OptionTypeMap::has_option_type at line 25 of MouseX/Getopt/OptionTypeMap.pm, avg 1µs/call
# 22 times (29µs+0s) by MouseX::Getopt::OptionTypeMap::get_option_type at line 43 of MouseX/Getopt/OptionTypeMap.pm, avg 1µs/call
# 14 times (22µs+0s) by Mouse::Meta::TypeConstraint::is_a_type_of at line 179, avg 2µs/call
# 4 times (10µs+0s) by Mouse::Util::TypeConstraints::_find_or_create_parameterized_type at line 287 of Mouse/Util/TypeConstraints.pm, avg 2µs/call | |||||
sub Mouse::Meta::TypeConstraint::parent; # xsub |