← 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:24 2010

File /data/SimpleDB-Class/author.t/../lib/SimpleDB/Class/Role/Itemized.pm
Statements Executed 627
Statement Execution Time 1.85ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1112.15ms53.4msSimpleDB::Class::Role::Itemized::::BEGIN@4SimpleDB::Class::Role::Itemized::BEGIN@4
3032671µs50.9msSimpleDB::Class::Role::Itemized::::instantiate_itemSimpleDB::Class::Role::Itemized::instantiate_item
3521538µs728µsSimpleDB::Class::Role::Itemized::::determine_item_classSimpleDB::Class::Role::Itemized::determine_item_class
522320µs42.4msSimpleDB::Class::Role::Itemized::::parse_itemSimpleDB::Class::Role::Itemized::parse_item
11139µs1.85msSimpleDB::Class::Role::Itemized::::BEGIN@3SimpleDB::Class::Role::Itemized::BEGIN@3
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package SimpleDB::Class::Role::Itemized;
2
3345µs23.67ms
# spent 1.85ms (39µs+1.81) within SimpleDB::Class::Role::Itemized::BEGIN@3 which was called # once (39µs+1.81ms) 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.85ms making 1 call to SimpleDB::Class::Role::Itemized::BEGIN@3 # spent 1.81ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:389]
43477µs256.8ms
# spent 53.4ms (2.15+51.3) within SimpleDB::Class::Role::Itemized::BEGIN@4 which was called # once (2.15ms+51.3ms) by Class::MOP::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Class/MOP.pm:103] at line 4
use SimpleDB::Class::Types ':all';
# spent 53.4ms making 1 call to SimpleDB::Class::Role::Itemized::BEGIN@4 # spent 3.39ms making 1 call to MooseX::Types::Base::import
5
613µs1144µsrequires 'item_class';
# spent 144µs making 1 call to Moose::Role::requires
7
8=head1 NAME
9
10SimpleDB::Class::Role::Itemized - Provides utility methods to classes that need to instantiate items.
11
12=head1 SYNOPSIS
13
14 my $class = $self->determine_item_class(\%attributes);
15
16 my $item = $self->instantiate_item(\%attributes, $id);
17
18 my $item = $self->parse_item($id, \@attributes);
19
20=head1 DESCRIPTION
21
22This is a L<Moose::Role> that provides utility methods for instantiating L<SimpleDB::Class::Item>s.
23
24=head1 METHODS
25
26The following methods are available from this role.
27
28=cut
29
30#--------------------------------------------------------
31
32=head2 instantiate_item ( attributes, [ id ] )
33
34Instantiates an item based upon it's proper classname and then calls C<update> to populate it's attributes with data.
35
36=head3 attributes
37
38A hash reference of attribute data.
39
40=head3 id
41
42An optional id to instantiate the item with.
43
44=cut
45
46
# spent 50.9ms (671µs+50.2) within SimpleDB::Class::Role::Itemized::instantiate_item which was called 30 times, avg 1.70ms/call: # 15 times (299µs+26.2ms) by SimpleDB::Class::ResultSet::next at line 467 of ../lib/SimpleDB/Class/ResultSet.pm, avg 1.77ms/call # 11 times (289µs+16.3ms) by SimpleDB::Class::Domain::insert at line 218 of ../lib/SimpleDB/Class/Domain.pm, avg 1.51ms/call # 4 times (83µs+7.66ms) by SimpleDB::Class::Domain::find at line 158 of ../lib/SimpleDB/Class/Domain.pm, avg 1.94ms/call
sub instantiate_item {
473065µs my ($self, $attributes, $id) = @_;
4830115µs3088µs $attributes->{simpledb} = $self->simpledb;
# spent 59µs making 15 calls to SimpleDB::Class::Domain::simpledb, avg 4µs/call # spent 29µs making 15 calls to SimpleDB::Class::ResultSet::simpledb, avg 2µs/call
493065µs if (defined $id && $id ne '') {
50 $attributes->{id} = $id;
51 }
5230331µs6050.1ms return $self->determine_item_class($attributes)->new($attributes);
# spent 49.5ms making 30 calls to Moose::Object::new, avg 1.65ms/call # spent 622µs making 30 calls to SimpleDB::Class::Role::Itemized::determine_item_class, avg 21µs/call
53}
54
55#--------------------------------------------------------
56
57=head2 determine_item_class ( attributes )
58
59Given an attribute list we can determine if an item needs to be recast as a different class.
60
61=head3 attributes
62
63A hash ref of attributes.
64
65=cut
66
67
# spent 728µs (538+190) within SimpleDB::Class::Role::Itemized::determine_item_class which was called 35 times, avg 21µs/call: # 30 times (462µs+161µs) by SimpleDB::Class::Role::Itemized::instantiate_item at line 52, avg 21µs/call # 5 times (77µs+29µs) by SimpleDB::Class::Role::Itemized::parse_item at line 129, avg 21µs/call
sub determine_item_class {
683542µs my ($self, $attributes) = @_;
6935108µs3595µs my $class = $self->item_class;
# spent 65µs making 17 calls to SimpleDB::Class::Domain::item_class, avg 4µs/call # spent 30µs making 18 calls to SimpleDB::Class::ResultSet::item_class, avg 2µs/call
7035163µs3594µs my $castor = $class->_castor_attribute;
# spent 83µs making 32 calls to SimpleDB::Class::Item::_castor_attribute, avg 3µs/call # spent 11µs making 3 calls to Foo::Child::_castor_attribute, avg 4µs/call
713515µs if ($castor) {
7234µs my $reclass = $attributes->{$castor};
7333µs if (ref $reclass eq 'ARRAY') {
74 $reclass = $reclass->[0];
75 }
7636µs if ($reclass) {
77 return $reclass;
78 }
79 }
8034133µs return $class;
81}
82
83#--------------------------------------------------------
84
85=head2 parse_item ( id , attributes )
86
87Converts the attributes section of an item document returned from SimpleDB into a L<SimpleDB::Class::Item> object.
88
89=head3 id
90
91The ItemName of the item to create.
92
93=head3 attributes
94
95An array of attributes as returned by L<SimpleDB::Client>.
96
97=cut
98
99
# spent 42.4ms (320µs+42.0) within SimpleDB::Class::Role::Itemized::parse_item which was called 5 times, avg 8.47ms/call: # 3 times (139µs+12.6ms) by SimpleDB::Class::ResultSet::next at line 468 of ../lib/SimpleDB/Class/ResultSet.pm, avg 4.23ms/call # 2 times (180µs+29.5ms) by SimpleDB::Class::Domain::find at line 167 of ../lib/SimpleDB/Class/Domain.pm, avg 14.8ms/call
sub parse_item {
10058µs my ($self, $id, $list) = @_;
10156µs unless (ref $list eq 'ARRAY') {
102 $list = [$list];
103 }
104
105 # format the data into a reasonable structure
10654µs my $attributes = {};
10758µs foreach my $attribute (@{$list}) {
108
109 # get attribute name
1104616µs unless (exists $attribute->{Name}) {
111 return undef; # empty result set
112 }
1134613µs my $name = $attribute->{Name};
114
115 # skip handling the 'id' field
1164616µs next if $name eq 'id';
117
118 # get value
1194615µs my $value = $attribute->{Value};
120469µs if (ref $value eq 'HASH' && !(keys %{$value})) { # undef comes back as an empty hash for some reason
121 next; # no need to store undef
122 }
123
124 # store attribute list
1254673µs push @{$attributes->{$name}}, $value;
126 }
127
128 # now we can determine the item's class from attributes if necessary
129515µs5106µs my $item_class = $self->determine_item_class($attributes);
# spent 106µs making 5 calls to SimpleDB::Class::Role::Itemized::determine_item_class, avg 21µs/call
130
131 # now we're ready to instantiate
132517µs513µs $attributes->{simpledb} = $self->simpledb;
# spent 8µs making 2 calls to SimpleDB::Class::Domain::simpledb, avg 4µs/call # spent 5µs making 3 calls to SimpleDB::Class::ResultSet::simpledb, avg 2µs/call
13356µs $attributes->{id} = $id;
134563µs541.9ms return $item_class->new($attributes);
# spent 41.9ms making 5 calls to Moose::Object::new, avg 8.39ms/call
135}
136
137=head1 LEGAL
138
139SimpleDB::Class is Copyright 2009-2010 Plain Black Corporation (L<http://www.plainblack.com/>) and is licensed under the same terms as Perl itself.
140
141=cut
142
143
14415µs1;