← 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:23:02 2010

File /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP/Method/Constructor.pm
Statements Executed 4396
Statement Execution Time 7.59ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
267114.33ms7.85msClass::MOP::Method::Constructor::::_generate_slot_initializerClass::MOP::Method::Constructor::_generate_slot_initializer
31111.52ms21.6msClass::MOP::Method::Constructor::::_generate_constructor_method_inlineClass::MOP::Method::Constructor::_generate_constructor_method_inline
42052689µs4.27msClass::MOP::Method::Constructor::::_meta_instanceClass::MOP::Method::Constructor::_meta_instance
3111502µs23.0msClass::MOP::Method::Constructor::::newClass::MOP::Method::Constructor::new
3111498µs498µsClass::MOP::Method::Constructor::::_newClass::MOP::Method::Constructor::_new
11362324µs2.13msClass::MOP::Method::Constructor::::_attributesClass::MOP::Method::Constructor::_attributes
3111214µs21.9msClass::MOP::Method::Constructor::::_initialize_bodyClass::MOP::Method::Constructor::_initialize_body
12442114µs114µsClass::MOP::Method::Constructor::::associated_metaclassClass::MOP::Method::Constructor::associated_metaclass
372257µs57µsClass::MOP::Method::Constructor::::optionsClass::MOP::Method::Constructor::options
11115µs18µsClass::MOP::Method::Constructor::::BEGIN@4Class::MOP::Method::Constructor::BEGIN@4
1117µs17µsClass::MOP::Method::Constructor::::BEGIN@5Class::MOP::Method::Constructor::BEGIN@5
1117µs39µsClass::MOP::Method::Constructor::::BEGIN@8Class::MOP::Method::Constructor::BEGIN@8
1117µs34µsClass::MOP::Method::Constructor::::BEGIN@7Class::MOP::Method::Constructor::BEGIN@7
1117µs758µsClass::MOP::Method::Constructor::::BEGIN@14Class::MOP::Method::Constructor::BEGIN@14
0000s0sClass::MOP::Method::Constructor::::__ANON__[:97]Class::MOP::Method::Constructor::__ANON__[:97]
0000s0sClass::MOP::Method::Constructor::::_generate_constructor_methodClass::MOP::Method::Constructor::_generate_constructor_method
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1
2package Class::MOP::Method::Constructor;
3
4321µs221µs
# spent 18µs (15+3) within Class::MOP::Method::Constructor::BEGIN@4 which was called # once (15µs+3µs) by Class::MOP::Class::BEGIN@10 at line 4
use strict;
# spent 18µs making 1 call to Class::MOP::Method::Constructor::BEGIN@4 # spent 3µs making 1 call to strict::import
5322µs227µs
# spent 17µs (7+10) within Class::MOP::Method::Constructor::BEGIN@5 which was called # once (7µs+10µs) by Class::MOP::Class::BEGIN@10 at line 5
use warnings;
# spent 17µs making 1 call to Class::MOP::Method::Constructor::BEGIN@5 # spent 10µs making 1 call to warnings::import
6
7325µs260µs
# spent 34µs (7+27) within Class::MOP::Method::Constructor::BEGIN@7 which was called # once (7µs+27µs) by Class::MOP::Class::BEGIN@10 at line 7
use Carp 'confess';
# spent 34µs making 1 call to Class::MOP::Method::Constructor::BEGIN@7 # spent 27µs making 1 call to Exporter::import
8347µs272µs
# spent 39µs (7+32) within Class::MOP::Method::Constructor::BEGIN@8 which was called # once (7µs+32µs) by Class::MOP::Class::BEGIN@10 at line 8
use Scalar::Util 'blessed', 'weaken', 'looks_like_number';
# spent 39µs making 1 call to Class::MOP::Method::Constructor::BEGIN@8 # spent 32µs making 1 call to Exporter::import
9
101700nsour $VERSION = '0.98';
11113µs$VERSION = eval $VERSION;
121300nsour $AUTHORITY = 'cpan:STEVAN';
13
143621µs21.51ms
# spent 758µs (7+751) within Class::MOP::Method::Constructor::BEGIN@14 which was called # once (7µs+751µs) by Class::MOP::Class::BEGIN@10 at line 14
use base 'Class::MOP::Method::Inlined';
# spent 758µs making 1 call to Class::MOP::Method::Constructor::BEGIN@14 # spent 751µs making 1 call to base::import
15
16
# spent 23.0ms (502µs+22.5) within Class::MOP::Method::Constructor::new which was called 31 times, avg 741µs/call: # 31 times (502µs+22.5ms) by Class::MOP::Class::_inline_constructor at line 1055 of Class/MOP/Class.pm, avg 741µs/call
sub new {
173112µs my $class = shift;
183158µs my %options = @_;
19
2031177µs6248µs (blessed $options{metaclass} && $options{metaclass}->isa('Class::MOP::Class'))
# spent 27µs making 31 calls to UNIVERSAL::isa, avg 874ns/call # spent 21µs making 31 calls to Scalar::Util::blessed, avg 668ns/call
21 || confess "You must pass a metaclass instance if you want to inline"
22 if $options{is_inline};
23
243111µs ($options{package_name} && $options{name})
25 || confess "You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT";
26
273144µs31498µs my $self = $class->_new(\%options);
# spent 498µs making 31 calls to Class::MOP::Method::Constructor::_new, avg 16µs/call
28
29 # we don't want this creating
30 # a cycle in the code, if not
31 # needed
323197µs3134µs weaken($self->{'associated_metaclass'});
# spent 34µs making 31 calls to Scalar::Util::weaken, avg 1µs/call
33
343135µs3121.9ms $self->_initialize_body;
# spent 21.9ms making 31 calls to Class::MOP::Method::Constructor::_initialize_body, avg 706µs/call
35
363181µs return $self;
37}
38
39
# spent 498µs within Class::MOP::Method::Constructor::_new which was called 31 times, avg 16µs/call: # 31 times (498µs+0s) by Class::MOP::Method::Constructor::new at line 27, avg 16µs/call
sub _new {
40318µs my $class = shift;
41
42319µs return Class::MOP::Class->initialize($class)->new_object(@_)
43 if $class ne __PACKAGE__;
44
453115µs my $params = @_ == 1 ? $_[0] : {@_};
46
4731493µs return bless {
48 # inherited from Class::MOP::Method
49 body => $params->{body},
50 # associated_metaclass => $params->{associated_metaclass}, # overriden
51 package_name => $params->{package_name},
52 name => $params->{name},
53 original_method => $params->{original_method},
54
55 # inherited from Class::MOP::Generated
56 is_inline => $params->{is_inline} || 0,
57 definition_context => $params->{definition_context},
58
59 # inherited from Class::MOP::Inlined
60 _expected_method_class => $params->{_expected_method_class},
61
62 # defined in this subclass
63 options => $params->{options} || {},
64 associated_metaclass => $params->{metaclass},
65 }, $class;
66}
67
68## accessors
69
703794µs
# spent 57µs within Class::MOP::Method::Constructor::options which was called 37 times, avg 2µs/call: # 31 times (38µs+0s) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 119, avg 1µs/call # 6 times (19µs+0s) by Moose::Meta::Method::Constructor::_initialize_body at line 75 of Moose/Meta/Method/Constructor.pm, avg 3µs/call
sub options { (shift)->{'options'} }
71124229µs
# spent 114µs within Class::MOP::Method::Constructor::associated_metaclass which was called 124 times, avg 918ns/call: # 31 times (34µs+0s) by Class::MOP::Method::Inlined::can_be_inlined at line 34 of Class/MOP/Method/Inlined.pm, avg 1µs/call # 31 times (29µs+0s) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 109, avg 932ns/call # 31 times (27µs+0s) by Class::MOP::Method::Constructor::_meta_instance at line 77, avg 868ns/call # 31 times (24µs+0s) by Class::MOP::Method::Constructor::_attributes at line 82, avg 787ns/call
sub associated_metaclass { (shift)->{'associated_metaclass'} }
72
73## cached values ...
74
75
# spent 4.27ms (689µs+3.58) within Class::MOP::Method::Constructor::_meta_instance which was called 420 times, avg 10µs/call: # 343 times (412µs+0s) by Class::MOP::Method::Constructor::_generate_slot_initializer at line 159, avg 1µs/call # 39 times (61µs+0s) by Moose::Meta::Method::Constructor::_generate_slot_assignment at line 272 of Moose/Meta/Method/Constructor.pm, avg 2µs/call # 31 times (160µs+3.57ms) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 113, avg 120µs/call # 6 times (54µs+15µs) by Moose::Meta::Method::Constructor::_generate_instance at line 121 of Moose/Meta/Method/Constructor.pm, avg 12µs/call # once (2µs+0s) by Moose::Meta::Method::Constructor::_generate_triggers at line 171 of Moose/Meta/Method/Constructor.pm
sub _meta_instance {
7642071µs my $self = shift;
77420846µs743.58ms $self->{'meta_instance'} ||= $self->associated_metaclass->get_meta_instance;
# spent 3.55ms making 37 calls to Class::MOP::Class::get_meta_instance, avg 96µs/call # spent 27µs making 31 calls to Class::MOP::Method::Constructor::associated_metaclass, avg 868ns/call # spent 6µs making 6 calls to Class::MOP::Method::associated_metaclass, avg 950ns/call
78}
79
80
# spent 2.13ms (324µs+1.81) within Class::MOP::Method::Constructor::_attributes which was called 113 times, avg 19µs/call: # 32 times (37µs+0s) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 194 of Moose/Meta/Method/Constructor.pm, avg 1µs/call # 32 times (36µs+0s) by Moose::Meta::Method::Constructor::_generate_triggers at line 163 of Moose/Meta/Method/Constructor.pm, avg 1µs/call # 31 times (183µs+1.58ms) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 116, avg 57µs/call # 6 times (52µs+224µs) by Moose::Meta::Method::Constructor::_generate_slot_initializers at line 129 of Moose/Meta/Method/Constructor.pm, avg 46µs/call # 6 times (9µs+0s) by Moose::Meta::Method::Constructor::_initialize_body at line 86 of Moose/Meta/Method/Constructor.pm, avg 1µs/call # 6 times (8µs+0s) by Moose::Meta::Method::Constructor::_generate_triggers at line 162 of Moose/Meta/Method/Constructor.pm, avg 1µs/call
sub _attributes {
8111320µs my $self = shift;
82113329µs741.81ms $self->{'attributes'} ||= [ $self->associated_metaclass->get_all_attributes ]
# spent 1.78ms making 37 calls to Class::MOP::Class::get_all_attributes, avg 48µs/call # spent 24µs making 31 calls to Class::MOP::Method::Constructor::associated_metaclass, avg 787ns/call # spent 5µs making 6 calls to Class::MOP::Method::associated_metaclass, avg 767ns/call
83}
84
85## method
86
87
# spent 21.9ms (214µs+21.7) within Class::MOP::Method::Constructor::_initialize_body which was called 31 times, avg 706µs/call: # 31 times (214µs+21.7ms) by Class::MOP::Method::Constructor::new at line 34, avg 706µs/call
sub _initialize_body {
88317µs my $self = shift;
89317µs my $method_name = '_generate_constructor_method';
90
913136µs3136µs $method_name .= '_inline' if $self->is_inline;
# spent 36µs making 31 calls to Class::MOP::Method::Generated::is_inline, avg 1µs/call
92
9331119µs3121.6ms $self->{'body'} = $self->$method_name;
# spent 21.6ms making 31 calls to Class::MOP::Method::Constructor::_generate_constructor_method_inline, avg 698µs/call
94}
95
96sub _generate_constructor_method {
97 return sub { Class::MOP::Class->initialize(shift)->new_object(@_) }
98}
99
100
# spent 21.6ms (1.52+20.1) within Class::MOP::Method::Constructor::_generate_constructor_method_inline which was called 31 times, avg 698µs/call: # 31 times (1.52ms+20.1ms) by Class::MOP::Method::Constructor::_initialize_body at line 93, avg 698µs/call
sub _generate_constructor_method_inline {
101317µs my $self = shift;
102
1033116µs my $close_over = {};
104
105315µs my $source = 'sub {';
106314µs $source .= "\n" . 'my $class = shift;';
107
108314µs $source .= "\n" . 'return Class::MOP::Class->initialize($class)->new_object(@_)';
10931109µs6246µs $source .= "\n" . ' if $class ne \'' . $self->associated_metaclass->name . '\';';
# spent 29µs making 31 calls to Class::MOP::Method::Constructor::associated_metaclass, avg 932ns/call # spent 17µs making 31 calls to Class::MOP::Package::name, avg 561ns/call
110
111314µs $source .= "\n" . 'my $params = @_ == 1 ? $_[0] : {@_};';
112
1133177µs623.79ms $source .= "\n" . 'my $instance = ' . $self->_meta_instance->inline_create_instance('$class');
# spent 3.73ms making 31 calls to Class::MOP::Method::Constructor::_meta_instance, avg 120µs/call # spent 59µs making 31 calls to Class::MOP::Instance::inline_create_instance, avg 2µs/call
114267249µs2677.85ms $source .= ";\n" . (join ";\n" => map {
# spent 7.85ms making 267 calls to Class::MOP::Method::Constructor::_generate_slot_initializer, avg 29µs/call
115 $self->_generate_slot_initializer($_, $close_over)
11631303µs311.77ms } @{ $self->_attributes });
# spent 1.77ms making 31 calls to Class::MOP::Method::Constructor::_attributes, avg 57µs/call
117316µs $source .= ";\n" . 'return $instance';
118314µs $source .= ";\n" . '}';
1193142µs3138µs warn $source if $self->options->{debug};
# spent 38µs making 31 calls to Class::MOP::Method::Constructor::options, avg 1µs/call
120
1213155µs316.62ms my ( $code, $e ) = $self->_eval_closure(
# spent 6.62ms making 31 calls to Class::MOP::Method::Generated::_eval_closure, avg 213µs/call
122 $close_over,
123 $source
124 );
125313µs confess "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$e" if $e;
126
1273173µs return $code;
128}
129
130
# spent 7.85ms (4.33+3.53) within Class::MOP::Method::Constructor::_generate_slot_initializer which was called 267 times, avg 29µs/call: # 267 times (4.33ms+3.53ms) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 114, avg 29µs/call
sub _generate_slot_initializer {
13126755µs my $self = shift;
13226727µs my $attr = shift;
13326727µs my $close = shift;
134
1352675µs my $default;
136267395µs447487µs if ($attr->has_default) {
# spent 291µs making 267 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 1µs/call # spent 197µs making 180 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 1µs/call
137 # NOTE:
138 # default values can either be CODE refs
139 # in which case we need to call them. Or
140 # they can be scalars (strings/numbers)
141 # in which case we can just deal with them
142 # in the code we eval.
1438782µs87175µs if ($attr->is_default_a_coderef) {
# spent 175µs making 87 calls to Class::MOP::Mixin::AttributeCore::is_default_a_coderef, avg 2µs/call
1445841µs my $idx = @{$close->{'@defaults'}||=[]};
1455874µs5889µs push(@{$close->{'@defaults'}}, $attr->default);
# spent 89µs making 58 calls to Class::MOP::Mixin::AttributeCore::default, avg 2µs/call
1465837µs $default = '$defaults[' . $idx . ']->($instance)';
147 }
148 else {
1492929µs2946µs $default = $attr->default;
# spent 46µs making 29 calls to Class::MOP::Mixin::AttributeCore::default, avg 2µs/call
150 # make sure to quote strings ...
1512986µs2928µs unless (looks_like_number($default)) {
# spent 28µs making 29 calls to Scalar::Util::looks_like_number, avg 966ns/call
152 $default = "'$default'";
153 }
154 }
155 } elsif( $attr->has_builder ) {
156 $default = '$instance->'.$attr->builder;
157 }
158
1592672.22ms12962.70ms if ( defined(my $init_arg = $attr->init_arg) ) {
# spent 1.83ms making 343 calls to Class::MOP::Instance::inline_set_slot_value, avg 5µs/call # spent 412µs making 343 calls to Class::MOP::Method::Constructor::_meta_instance, avg 1µs/call # spent 295µs making 267 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 1µs/call # spent 160µs making 343 calls to Class::MOP::Mixin::AttributeCore::name, avg 468ns/call
160 return (
161 'if(exists $params->{\'' . $init_arg . '\'}){' . "\n" .
162 $self->_meta_instance->inline_set_slot_value(
163 '$instance',
164 $attr->name,
165 '$params->{\'' . $init_arg . '\'}' ) . "\n" .
166 '} ' . (!defined $default ? '' : 'else {' . "\n" .
167 $self->_meta_instance->inline_set_slot_value(
168 '$instance',
169 $attr->name,
170 $default ) . "\n" .
171 '}')
172 );
173 } elsif ( defined $default ) {
174 return (
175 $self->_meta_instance->inline_set_slot_value(
176 '$instance',
177 $attr->name,
178 $default ) . "\n"
179 );
18012µs } else { return '' }
181}
182
18314µs1;
184
185__END__
186
187=pod
188
189=head1 NAME
190
191Class::MOP::Method::Constructor - Method Meta Object for constructors
192
193=head1 SYNOPSIS
194
195 use Class::MOP::Method::Constructor;
196
197 my $constructor = Class::MOP::Method::Constructor->new(
198 metaclass => $metaclass,
199 options => {
200 debug => 1, # this is all for now
201 },
202 );
203
204 # calling the constructor ...
205 $constructor->body->execute($metaclass->name, %params);
206
207=head1 DESCRIPTION
208
209This is a subclass of C<Class::MOP::Method> which generates
210constructor methods.
211
212=head1 METHODS
213
214=over 4
215
216=item B<< Class::MOP::Method::Constructor->new(%options) >>
217
218This creates a new constructor object. It accepts a hash reference of
219options.
220
221=over 8
222
223=item * metaclass
224
225This should be a L<Class::MOP::Class> object. It is required.
226
227=item * name
228
229The method name (without a package name). This is required.
230
231=item * package_name
232
233The package name for the method. This is required.
234
235=item * is_inline
236
237This indicates whether or not the constructor should be inlined. This
238defaults to false.
239
240=back
241
242=item B<< $metamethod->is_inline >>
243
244Returns a boolean indicating whether or not the constructor is
245inlined.
246
247=item B<< $metamethod->associated_metaclass >>
248
249This returns the L<Class::MOP::Class> object for the method.
250
251=back
252
253=head1 AUTHORS
254
255Stevan Little E<lt>stevan@iinteractive.comE<gt>
256
257=head1 COPYRIGHT AND LICENSE
258
259Copyright 2006-2010 by Infinity Interactive, Inc.
260
261L<http://www.iinteractive.com>
262
263This library is free software; you can redistribute it and/or modify
264it under the same terms as Perl itself.
265
266=cut
267