← Index
NYTProf Performance Profile   « block view • line view • sub view »
For 05.Domain_and_Item.t
  Run on Tue May 4 17:21:41 2010
Reported on Tue May 4 17:22:59 2010

File /usr/local/lib/perl5/site_perl/5.10.1/MooseX/AttributeHelpers/Trait/Base.pm
Statements Executed 155
Statement Execution Time 1.32ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
211132µs3.39msMooseX::AttributeHelpers::Trait::Base::::__ANON__[:51]MooseX::AttributeHelpers::Trait::Base::__ANON__[:51]
21151µs3.53msMooseX::AttributeHelpers::Trait::Base::::check_provides_valuesMooseX::AttributeHelpers::Trait::Base::check_provides_values
21148µs1.51msMooseX::AttributeHelpers::Trait::Base::::process_options_for_providesMooseX::AttributeHelpers::Trait::Base::process_options_for_provides
11118µs1.41msMooseX::AttributeHelpers::Trait::Base::::BEGIN@3MooseX::AttributeHelpers::Trait::Base::BEGIN@3
1118µs96µsMooseX::AttributeHelpers::Trait::Base::::BEGIN@219MooseX::AttributeHelpers::Trait::Base::BEGIN@219
1118µs1.17msMooseX::AttributeHelpers::Trait::Base::::BEGIN@4MooseX::AttributeHelpers::Trait::Base::BEGIN@4
1117µs93µsMooseX::AttributeHelpers::Trait::Base::::BEGIN@220MooseX::AttributeHelpers::Trait::Base::BEGIN@220
2115µs5µsMooseX::AttributeHelpers::Trait::Base::::__ANON__[:22]MooseX::AttributeHelpers::Trait::Base::__ANON__[:22]
0000s0sMooseX::AttributeHelpers::Trait::Base::::__ANON__[:105]MooseX::AttributeHelpers::Trait::Base::__ANON__[:105]
0000s0sMooseX::AttributeHelpers::Trait::Base::::__ANON__[:116]MooseX::AttributeHelpers::Trait::Base::__ANON__[:116]
0000s0sMooseX::AttributeHelpers::Trait::Base::::__ANON__[:16]MooseX::AttributeHelpers::Trait::Base::__ANON__[:16]
0000s0sMooseX::AttributeHelpers::Trait::Base::::__ANON__[:194]MooseX::AttributeHelpers::Trait::Base::__ANON__[:194]
0000s0sMooseX::AttributeHelpers::Trait::Base::::__ANON__[:217]MooseX::AttributeHelpers::Trait::Base::__ANON__[:217]
0000s0sMooseX::AttributeHelpers::Trait::Base::::__ANON__[:77]MooseX::AttributeHelpers::Trait::Base::__ANON__[:77]
0000s0sMooseX::AttributeHelpers::Trait::Base::::_curryMooseX::AttributeHelpers::Trait::Base::_curry
0000s0sMooseX::AttributeHelpers::Trait::Base::::_curry_subMooseX::AttributeHelpers::Trait::Base::_curry_sub
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1
2package MooseX::AttributeHelpers::Trait::Base;
3326µs22.81ms
# spent 1.41ms (18µs+1.39) within MooseX::AttributeHelpers::Trait::Base::BEGIN@3 which was called # once (18µs+1.39ms) by Class::MOP::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP.pm:103] at line 3
use Moose::Role;
# spent 1.41ms making 1 call to MooseX::AttributeHelpers::Trait::Base::BEGIN@3 # spent 1.39ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:389]
43780µs22.33ms
# spent 1.17ms (8µs+1.16) within MooseX::AttributeHelpers::Trait::Base::BEGIN@4 which was called # once (8µs+1.16ms) by Class::MOP::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP.pm:103] at line 4
use Moose::Util::TypeConstraints;
# spent 1.17ms making 1 call to MooseX::AttributeHelpers::Trait::Base::BEGIN@4 # spent 1.16ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:389]
5
61700nsour $VERSION = '0.23';
7114µs$VERSION = eval $VERSION;
81300nsour $AUTHORITY = 'cpan:STEVAN';
9
1012µs1114µsrequires 'helper_type';
# spent 114µs making 1 call to Moose::Role::requires
11
12# this is the method map you define ...
13has 'provides' => (
14 is => 'ro',
15 isa => 'HashRef',
16 default => sub {{}}
1713µs1194µs);
# spent 194µs making 1 call to Moose::Role::has
18
1925µshas 'curries' => (
20 is => 'ro',
21 isa => 'HashRef',
22
# spent 5µs within MooseX::AttributeHelpers::Trait::Base::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/MooseX/AttributeHelpers/Trait/Base.pm:22] which was called 2 times, avg 2µs/call: # 2 times (5µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 53 of Class/MOP/Mixin/AttributeCore.pm, avg 2µs/call
default => sub {{}}
2312µs193µs);
# spent 93µs making 1 call to Moose::Role::has
24
25# these next two are the possible methods
26# you can use in the 'provides' map.
27
28# provide a Class or Role which we can
29# collect the method providers from
30
31# requires_attr 'method_provider'
32
33# or you can provide a HASH ref of anon subs
34# yourself. This will also collect and store
35# the methods from a method_provider as well
36has 'method_constructors' => (
37 is => 'ro',
38 isa => 'HashRef',
39 lazy => 1,
40
# spent 3.39ms (132µs+3.26) within MooseX::AttributeHelpers::Trait::Base::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/MooseX/AttributeHelpers/Trait/Base.pm:51] which was called 2 times, avg 1.70ms/call: # 2 times (132µs+3.26ms) by Class::MOP::Mixin::AttributeCore::default at line 53 of Class/MOP/Mixin/AttributeCore.pm, avg 1.70ms/call
default => sub {
4121µs my $self = shift;
4226µs26µs return +{} unless $self->has_method_provider;
# spent 6µs making 2 calls to MooseX::AttributeHelpers::Collection::Hash::has_method_provider, avg 3µs/call
43 # or grab them from the role/class
44212µs434µs my $method_provider = $self->method_provider->meta;
# spent 26µs making 2 calls to MooseX::AttributeHelpers::MethodProvider::Hash::meta, avg 13µs/call # spent 8µs making 2 calls to MooseX::AttributeHelpers::Collection::Hash::method_provider, avg 4µs/call
45 return +{
462629µs26537µs map {
# spent 537µs making 26 calls to Class::MOP::Mixin::HasMethods::get_method, avg 21µs/call
47 $_ => $method_provider->get_method($_)
48 }
49244µs22.69ms grep { $_ ne 'meta' } $method_provider->get_method_list
# spent 2.69ms making 2 calls to Class::MOP::Mixin::HasMethods::get_method_list, avg 1.34ms/call
50 };
51 },
5214µs1108µs);
# spent 108µs making 1 call to Moose::Role::has
53
54## Methods called prior to instantiation
55
56
# spent 1.51ms (48µs+1.46) within MooseX::AttributeHelpers::Trait::Base::process_options_for_provides which was called 2 times, avg 754µs/call: # 2 times (48µs+1.46ms) by Class::MOP::Class:::before at line 76, avg 754µs/call
sub process_options_for_provides {
5722µs my ($self, $options) = @_;
58
59212µs24µs if (my $type = $self->helper_type) {
# spent 4µs making 2 calls to MooseX::AttributeHelpers::Trait::Collection::Hash::helper_type, avg 2µs/call
6021µs (exists $options->{isa})
61 || confess "You must define a type with the $type metaclass";
62
6322µs my $isa = $options->{isa};
64
65212µs41.29ms unless (blessed($isa) && $isa->isa('Moose::Meta::TypeConstraint')) {
# spent 1.29ms making 2 calls to Moose::Util::TypeConstraints::find_or_create_type_constraint, avg 646µs/call # spent 2µs making 2 calls to Scalar::Util::blessed, avg 800ns/call
66 $isa = Moose::Util::TypeConstraints::find_or_create_type_constraint($isa);
67 }
68
69213µs2164µs ($isa->is_a_type_of($type))
# spent 164µs making 2 calls to Moose::Meta::TypeConstraint::is_a_type_of, avg 82µs/call
70 || confess "The type constraint for a $type ($options->{isa}) must be a subtype of $type";
71 }
72}
73
74before '_process_options' => sub {
7522µs my ($self, $name, $options) = @_;
76210µs21.51ms $self->process_options_for_provides($options, $name);
# spent 1.51ms making 2 calls to MooseX::AttributeHelpers::Trait::Base::process_options_for_provides, avg 754µs/call
7713µs153µs};
# spent 53µs making 1 call to Moose::Role::before
78
79## methods called after instantiation
80
81
# spent 3.53ms (51µs+3.48) within MooseX::AttributeHelpers::Trait::Base::check_provides_values which was called 2 times, avg 1.77ms/call: # 2 times (51µs+3.48ms) by Class::MOP::Class:::after at line 132, avg 1.77ms/call
sub check_provides_values {
8221µs my $self = shift;
83
8426µs23.47ms my $method_constructors = $self->method_constructors;
# spent 3.47ms making 2 calls to MooseX::AttributeHelpers::Collection::Hash::method_constructors, avg 1.73ms/call
85
86213µs27µs foreach my $key (keys %{$self->provides}) {
# spent 7µs making 2 calls to MooseX::AttributeHelpers::Collection::Hash::provides, avg 4µs/call
8793µs (exists $method_constructors->{$key})
88 || confess "$key is an unsupported method type";
89 }
90
91213µs27µs foreach my $key (keys %{$self->curries}) {
# spent 7µs making 2 calls to MooseX::AttributeHelpers::Collection::Hash::curries, avg 4µs/call
92 (exists $method_constructors->{$key})
93 || confess "$key is an unsupported method type";
94 }
95}
96
97sub _curry {
98 my $self = shift;
99 my $code = shift;
100
101 my @args = @_;
102 return sub {
103 my $self = shift;
104 $code->($self, @args, @_)
105 };
106}
107
108sub _curry_sub {
109 my $self = shift;
110 my $body = shift;
111 my $code = shift;
112
113 return sub {
114 my $self = shift;
115 $code->($self, $body, @_)
116 };
117}
118
119after 'install_accessors' => sub {
12022µs my $attr = shift;
12124µs22µs my $class = $attr->associated_class;
# spent 2µs making 2 calls to Class::MOP::Attribute::associated_class, avg 1µs/call
122
123 # grab the reader and writer methods
124 # as well, this will be useful for
125 # our method provider constructors
12627µs299µs my $attr_reader = $attr->get_read_method_ref;
# spent 99µs making 2 calls to Class::MOP::Attribute::get_read_method_ref, avg 49µs/call
12728µs2137µs my $attr_writer = $attr->get_write_method_ref;
# spent 137µs making 2 calls to Class::MOP::Attribute::get_write_method_ref, avg 68µs/call
128
129
130 # before we install them, lets
131 # make sure they are valid
13225µs23.53ms $attr->check_provides_values;
# spent 3.53ms making 2 calls to MooseX::AttributeHelpers::Trait::Base::check_provides_values, avg 1.77ms/call
133
13423µs24µs my $method_constructors = $attr->method_constructors;
# spent 4µs making 2 calls to MooseX::AttributeHelpers::Collection::Hash::method_constructors, avg 2µs/call
135
13627µs22µs my $class_name = $class->name;
# spent 2µs making 2 calls to Class::MOP::Package::name, avg 750ns/call
137
13826µs22µs while (my ($constructor, $constructed) = each %{$attr->curries}) {
# spent 2µs making 2 calls to MooseX::AttributeHelpers::Collection::Hash::curries, avg 1µs/call
139 my $method_code;
140 while (my ($curried_name, $curried_arg) = each(%$constructed)) {
141 if ($class->has_method($curried_name)) {
142 confess
143 "The method ($curried_name) already ".
144 "exists in class (" . $class->name . ")";
145 }
146 my $body = $method_constructors->{$constructor}->(
147 $attr,
148 $attr_reader,
149 $attr_writer,
150 );
151
152 if (ref $curried_arg eq 'ARRAY') {
153 $method_code = $attr->_curry($body, @$curried_arg);
154 }
155 elsif (ref $curried_arg eq 'CODE') {
156 $method_code = $attr->_curry_sub($body, $curried_arg);
157 }
158 else {
159 confess "curries parameter must be ref type ARRAY or CODE";
160 }
161
162 my $method = MooseX::AttributeHelpers::Meta::Method::Curried->wrap(
163 $method_code,
164 package_name => $class_name,
165 name => $curried_name,
166 );
167
168 $attr->associate_method($method);
169 $class->add_method($curried_name => $method);
170 }
171 }
172
173218µs22µs foreach my $key (keys %{$attr->provides}) {
# spent 2µs making 2 calls to MooseX::AttributeHelpers::Collection::Hash::provides, avg 1µs/call
174
175916µs916µs my $method_name = $attr->provides->{$key};
# spent 16µs making 9 calls to MooseX::AttributeHelpers::Collection::Hash::provides, avg 2µs/call
176
177911µs9290µs if ($class->has_method($method_name)) {
# spent 290µs making 9 calls to Class::MOP::Mixin::HasMethods::has_method, avg 32µs/call
178 confess "The method ($method_name) already exists in class (" . $class->name . ")";
179 }
180
181972µs362.86ms my $method = MooseX::AttributeHelpers::Meta::Method::Provided->wrap(
# spent 2.57ms making 9 calls to Class::MOP::Method::wrap, avg 285µs/call # spent 93µs making 2 calls to MooseX::AttributeHelpers::MethodProvider::Hash::set, avg 46µs/call # spent 65µs making 18 calls to Class::MOP::Method::__ANON__[Class/MOP/Method.pm:19], avg 4µs/call # spent 46µs making 2 calls to MooseX::AttributeHelpers::MethodProvider::Hash::delete, avg 23µs/call # spent 38µs making 2 calls to MooseX::AttributeHelpers::MethodProvider::ImmutableHash::get, avg 19µs/call # spent 34µs making 2 calls to MooseX::AttributeHelpers::MethodProvider::ImmutableHash::exists, avg 17µs/call # spent 23µs making 1 call to MooseX::AttributeHelpers::MethodProvider::ImmutableHash::keys
182 $method_constructors->{$key}->(
183 $attr,
184 $attr_reader,
185 $attr_writer,
186 ),
187 package_name => $class_name,
188 name => $method_name,
189 );
190
191912µs919µs $attr->associate_method($method);
# spent 19µs making 9 calls to Class::MOP::Attribute::associate_method, avg 2µs/call
192925µs9420µs $class->add_method($method_name => $method);
# spent 420µs making 9 calls to Class::MOP::Mixin::HasMethods::add_method, avg 47µs/call
193 }
19414µs145µs};
# spent 45µs making 1 call to Moose::Role::after
195
196after 'remove_accessors' => sub {
197 my $attr = shift;
198 my $class = $attr->associated_class;
199
200 # provides accessors
201 foreach my $key (keys %{$attr->provides}) {
202 my $method_name = $attr->provides->{$key};
203 my $method = $class->get_method($method_name);
204 $class->remove_method($method_name)
205 if blessed($method) &&
206 $method->isa('MooseX::AttributeHelpers::Meta::Method::Provided');
207 }
208
209 # curries accessors
210 foreach my $key (keys %{$attr->curries}) {
211 my $method_name = $attr->curries->{$key};
212 my $method = $class->get_method($method_name);
213 $class->remove_method($method_name)
214 if blessed($method) &&
215 $method->isa('MooseX::AttributeHelpers::Meta::Method::Provided');
216 }
21718µs130µs};
# spent 30µs making 1 call to Moose::Role::after
218
219325µs2184µs
# spent 96µs (8+88) within MooseX::AttributeHelpers::Trait::Base::BEGIN@219 which was called # once (8µs+88µs) by Class::MOP::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP.pm:103] at line 219
no Moose::Role;
220335µs2178µs
# spent 93µs (7+86) within MooseX::AttributeHelpers::Trait::Base::BEGIN@220 which was called # once (7µs+86µs) by Class::MOP::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP.pm:103] at line 220
no Moose::Util::TypeConstraints;
221
222131µs1;
223
224__END__
225
226=head1 NAME
227
228MooseX::AttributeHelpers::Trait::Base - base role for helpers
229
230=head1 METHODS
231
232=head2 check_provides_values
233
234Confirms that provides (and curries) has all valid possibilities in it.
235
236=head2 process_options_for_provides
237
238Ensures that the type constraint (C<isa>) matches the helper type.
239
240=head1 BUGS
241
242All complex software has bugs lurking in it, and this module is no
243exception. If you find a bug please either email me, or add the bug
244to cpan-RT.
245
246=head1 AUTHORS
247
248Yuval Kogman
249
250Shawn M Moore
251
252Jesse Luehrs
253
254=head1 COPYRIGHT AND LICENSE
255
256Copyright 2007-2009 by Infinity Interactive, Inc.
257
258L<http://www.iinteractive.com>
259
260This library is free software; you can redistribute it and/or modify
261it under the same terms as Perl itself.
262
263=cut