← Index
NYTProf Performance Profile   « block view • line view • sub view »
For bin/hailo
  Run on Thu Oct 21 22:50:37 2010
Reported on Thu Oct 21 22:52:07 2010

Filename/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/x86_64-linux/Mouse/Meta/TypeConstraint.pm
StatementsExecuted 1063 statements in 4.11ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
47421.72ms1.80msMouse::Meta::TypeConstraint::::newMouse::Meta::TypeConstraint::new
1421457µs624µsMouse::Meta::TypeConstraint::::is_a_type_ofMouse::Meta::TypeConstraint::is_a_type_of
18174283µs283µsMouse::Meta::TypeConstraint::::_identityMouse::Meta::TypeConstraint::_identity (xsub)
1611267µs345µsMouse::Meta::TypeConstraint::::__ANON__[:119]Mouse::Meta::TypeConstraint::__ANON__[:119]
1711224µs604µsMouse::Meta::TypeConstraint::::coerceMouse::Meta::TypeConstraint::coerce
9853164µs164µsMouse::Meta::TypeConstraint::::nameMouse::Meta::TypeConstraint::name (xsub)
4314772µs72µsMouse::Meta::TypeConstraint::::_compiled_type_constraintMouse::Meta::TypeConstraint::_compiled_type_constraint (xsub)
332162µs62µsMouse::Meta::TypeConstraint::::checkMouse::Meta::TypeConstraint::check (xsub)
422155µs55µsMouse::Meta::TypeConstraint::::parentMouse::Meta::TypeConstraint::parent (xsub)
61142µs42µsMouse::Meta::TypeConstraint::::compile_type_constraintMouse::Meta::TypeConstraint::compile_type_constraint (xsub)
11141µs73µsMouse::Meta::TypeConstraint::::_add_type_coercionsMouse::Meta::TypeConstraint::_add_type_coercions
21128µs206µsMouse::Meta::TypeConstraint::::parameterizeMouse::Meta::TypeConstraint::parameterize
11124µs102µsMouse::Meta::TypeConstraint::::BEGIN@2Mouse::Meta::TypeConstraint::BEGIN@2
141119µs19µsMouse::Meta::TypeConstraint::::CORE:substMouse::Meta::TypeConstraint::CORE:subst (opcode)
11112µs12µsMouse::Meta::TypeConstraint::::_compile_type_coercionMouse::Meta::TypeConstraint::_compile_type_coercion
2113µs3µsMouse::Meta::TypeConstraint::::has_coercionMouse::Meta::TypeConstraint::has_coercion (xsub)
0000s0sMouse::Meta::TypeConstraint::::__ANON__[:140]Mouse::Meta::TypeConstraint::__ANON__[:140]
0000s0sMouse::Meta::TypeConstraint::::_as_stringMouse::Meta::TypeConstraint::_as_string
0000s0sMouse::Meta::TypeConstraint::::_compile_union_type_coercionMouse::Meta::TypeConstraint::_compile_union_type_coercion
0000s0sMouse::Meta::TypeConstraint::::_uniteMouse::Meta::TypeConstraint::_unite
0000s0sMouse::Meta::TypeConstraint::::assert_validMouse::Meta::TypeConstraint::assert_valid
0000s0sMouse::Meta::TypeConstraint::::create_child_typeMouse::Meta::TypeConstraint::create_child_type
0000s0sMouse::Meta::TypeConstraint::::get_messageMouse::Meta::TypeConstraint::get_message
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Mouse::Meta::TypeConstraint;
221.02ms2179µ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
use Mouse::Util qw(:meta); # enables strict and warnings
# 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
sub new {
55171.20ms my $class = shift;
6 my %args = @_ == 1 ? %{$_[0]} : @_;
7
8 $args{name} = '__ANON__' if !defined $args{name};
9
10184509µ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
2390142µs23µ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'
32435µ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;
44642µ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
53sub create_child_type {
54 my $self = shift;
55 return ref($self)->new(@_, parent => $self);
56}
57
58sub name;
59sub parent;
60sub message;
61sub has_coercion;
62
63sub check;
64
65sub type_parameter;
66sub __is_parameterized;
67
68sub _compiled_type_constraint;
69sub _compiled_type_coercion;
70
71sub 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
sub _add_type_coercions { # ($self, @pairs)
75823µ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
85516µ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
93220µs my $type = Mouse::Util::TypeConstraints::find_or_parse_type_constraint($from)
94 or $self->throw_error(
95 "Could not find the type constraint ($from) to coerce from");
96
97 push @{$coercions}, [ $type => $action ];
98 }
99
100112µs $self->_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
sub _compile_type_coercion {
105414µ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
$self->{_compiled_type_coercion} = sub {
1103242µs my($thing) = @_;
111 foreach my $pair (@coercions) {
112 #my ($constraint, $converter) = @$pair;
11348236µs1627µs if ($pair->[0]->check($thing)) {
# spent 27µs making 16 calls to Mouse::Meta::TypeConstraint::check, avg 2µs/call
114 local $_ = $thing;
1151650µs return $pair->[1]->($thing);
116 }
117 }
118 return $thing;
119 };
120 return;
121}
122
123sub _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
sub coerce {
14666252µs my $self = shift;
1471735µ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");
15116345µ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
154sub 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
sub is_a_type_of {
17298634µs my($self, $other) = @_;
173
174 # ->is_a_type_of('__ANON__') is always false
175 return 0 if !ref($other) && $other eq '__ANON__';
176
1771419µ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
1791422µ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
18766109µ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;
1891217µ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
sub parameterize {
196828µ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;
2042177µ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
211sub 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
220sub _as_string { $_[0]->name } # overload ""
221sub _identity; # overload 0+
222
223sub _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
23112µs1;
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
sub Mouse::Meta::TypeConstraint::CORE:subst; # opcode
# 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
sub Mouse::Meta::TypeConstraint::_compiled_type_constraint; # xsub
# 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
sub Mouse::Meta::TypeConstraint::_identity; # xsub
# 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
sub Mouse::Meta::TypeConstraint::check; # xsub
# 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
sub Mouse::Meta::TypeConstraint::compile_type_constraint; # xsub
# 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
sub Mouse::Meta::TypeConstraint::has_coercion; # xsub
# 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::name; # xsub
# spent 55µs within Mouse::Meta::TypeConstraint::parent which was called 42 times, avg 1µs/call: # 30 times (38µs+0s) by Mouse::Meta::TypeConstraint::is_a_type_of at line 187, avg 1µs/call # 12 times (17µs+0s) by Mouse::Meta::TypeConstraint::is_a_type_of at line 189, avg 1µs/call
sub Mouse::Meta::TypeConstraint::parent; # xsub