Profile of /data/SimpleDB-Class/author.t/../lib/SimpleDB/Class/Role/Itemized.pm

← 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:53 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
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 2.15ms | 53.4ms | SimpleDB::Class::Role::Itemized::::BEGIN@4SimpleDB::Class::Role::Itemized::BEGIN@4
30 | 3 | 2 | 671µs | 50.9ms | SimpleDB::Class::Role::Itemized::::instantiate_itemSimpleDB::Class::Role::Itemized::instantiate_item
35 | 2 | 1 | 538µs | 728µs | SimpleDB::Class::Role::Itemized::::determine_item_classSimpleDB::Class::Role::Itemized::determine_item_class
5 | 2 | 2 | 320µs | 42.4ms | SimpleDB::Class::Role::Itemized::::parse_itemSimpleDB::Class::Role::Itemized::parse_item
1 | 1 | 1 | 39µs | 1.85ms | SimpleDB::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
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package SimpleDB::Class::Role::Itemized;
2 |  |  |  |  |
3 | 3 | 45µs | 2 | 3.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]
4 | 3 | 477µs | 2 | 56.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 |  |  |  |  |
6 | 1 | 3µs | 1 | 144µs | requires 'item_class'; # spent 144µs making 1 call to Moose::Role::requires
7 |  |  |  |  |
8 |  |  |  |  | =head1 NAME
9 |  |  |  |  |
10 |  |  |  |  | SimpleDB::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 |  |  |  |  |
22 |  |  |  |  | This is a L<Moose::Role> that provides utility methods for instantiating L<SimpleDB::Class::Item>s.
23 |  |  |  |  |
24 |  |  |  |  | =head1 METHODS
25 |  |  |  |  |
26 |  |  |  |  | The following methods are available from this role.
27 |  |  |  |  |
28 |  |  |  |  | =cut
29 |  |  |  |  |
30 |  |  |  |  | #--------------------------------------------------------
31 |  |  |  |  |
32 |  |  |  |  | =head2 instantiate_item ( attributes, [ id ] )
33 |  |  |  |  |
34 |  |  |  |  | Instantiates 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 |  |  |  |  |
38 |  |  |  |  | A hash reference of attribute data.
39 |  |  |  |  |
40 |  |  |  |  | =head3 id
41 |  |  |  |  |
42 |  |  |  |  | An 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 {
47 | 120 | 576µs |  |  | my ($self, $attributes, $id) = @_;
48 |  |  |  |  | $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
49 |  |  |  |  | if (defined $id && $id ne '') {
50 |  |  |  |  | $attributes->{id} = $id;
51 |  |  |  |  | }
52 |  |  |  |  | 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 |  |  |  |  |
59 |  |  |  |  | Given an attribute list we can determine if an item needs to be recast as a different class.
60 |  |  |  |  |
61 |  |  |  |  | =head3 attributes
62 |  |  |  |  |
63 |  |  |  |  | A 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 {
68 | 174 | 462µs |  |  | my ($self, $attributes) = @_;
69 |  |  |  |  | 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
70 |  |  |  |  | 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
71 | 9 | 12µs |  |  | if ($castor) {
72 |  |  |  |  | my $reclass = $attributes->{$castor};
73 |  |  |  |  | if (ref $reclass eq 'ARRAY') {
74 |  |  |  |  | $reclass = $reclass->[0];
75 |  |  |  |  | }
76 |  |  |  |  | if ($reclass) {
77 |  |  |  |  | return $reclass;
78 |  |  |  |  | }
79 |  |  |  |  | }
80 |  |  |  |  | return $class;
81 |  |  |  |  | }
82 |  |  |  |  |
83 |  |  |  |  | #--------------------------------------------------------
84 |  |  |  |  |
85 |  |  |  |  | =head2 parse_item ( id , attributes )
86 |  |  |  |  |
87 |  |  |  |  | Converts the attributes section of an item document returned from SimpleDB into a L<SimpleDB::Class::Item> object.
88 |  |  |  |  |
89 |  |  |  |  | =head3 id
90 |  |  |  |  |
91 |  |  |  |  | The ItemName of the item to create.
92 |  |  |  |  |
93 |  |  |  |  | =head3 attributes
94 |  |  |  |  |
95 |  |  |  |  | An 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 {
100 | 40 | 126µs |  |  | my ($self, $id, $list) = @_;
101 |  |  |  |  | unless (ref $list eq 'ARRAY') {
102 |  |  |  |  | $list = [$list];
103 |  |  |  |  | }
104 |  |  |  |  |
105 |  |  |  |  | # format the data into a reasonable structure
106 |  |  |  |  | my $attributes = {};
107 |  |  |  |  | foreach my $attribute (@{$list}) {
108 |  |  |  |  |
109 |  |  |  |  | # get attribute name
110 | 276 | 142µs |  |  | unless (exists $attribute->{Name}) {
111 |  |  |  |  | return undef; # empty result set
112 |  |  |  |  | }
113 |  |  |  |  | my $name = $attribute->{Name};
114 |  |  |  |  |
115 |  |  |  |  | # skip handling the 'id' field
116 |  |  |  |  | next if $name eq 'id';
117 |  |  |  |  |
118 |  |  |  |  | # get value
119 |  |  |  |  | my $value = $attribute->{Value};
120 |  |  |  |  | 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
125 |  |  |  |  | push @{$attributes->{$name}}, $value;
126 |  |  |  |  | }
127 |  |  |  |  |
128 |  |  |  |  | # now we can determine the item's class from attributes if necessary
129 |  |  |  |  | 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
132 |  |  |  |  | $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
133 |  |  |  |  | $attributes->{id} = $id;
134 |  |  |  |  | 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 |  |  |  |  |
139 |  |  |  |  | SimpleDB::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 |  |  |  |  |
144 | 1 | 5µs |  |  | 1;