Profile of /data/SimpleDB-Class/author.t/../lib/SimpleDB/Class/ResultSet.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:42 2010

File | /data/SimpleDB-Class/author.t/../lib/SimpleDB/Class/ResultSet.pm
Statements Executed | 645
Statement Execution Time | 3.58ms

Subroutines — ordered by exclusive time
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
23 | 10 | 2 | 1.80ms | 602ms | SimpleDB::Class::ResultSet::::nextSimpleDB::Class::ResultSet::next
10 | 2 | 1 | 770µs | 848ms | SimpleDB::Class::ResultSet::::fetch_resultSimpleDB::Class::ResultSet::fetch_result
4 | 4 | 1 | 248µs | 316ms | SimpleDB::Class::ResultSet::::countSimpleDB::Class::ResultSet::count
1 | 1 | 1 | 111µs | 391ms | SimpleDB::Class::ResultSet::::paginateSimpleDB::Class::ResultSet::paginate
1 | 1 | 1 | 32µs | 2.54ms | SimpleDB::Class::ResultSet::::BEGIN@21SimpleDB::Class::ResultSet::BEGIN@21
7 | 1 | 1 | 20µs | 20µs | SimpleDB::Class::ResultSet::::__ANON__[../lib/SimpleDB/Class/ResultSet.pm:109]SimpleDB::Class::ResultSet::__ANON__[../lib/SimpleDB/Class/ResultSet.pm:109]
1 | 1 | 1 | 13µs | 112µs | SimpleDB::Class::ResultSet::::BEGIN@520SimpleDB::Class::ResultSet::BEGIN@520
1 | 1 | 1 | 5µs | 5µs | SimpleDB::Class::ResultSet::::BEGIN@22SimpleDB::Class::ResultSet::BEGIN@22
0 | 0 | 0 | 0s | 0s | SimpleDB::Class::ResultSet::::__ANON__[../lib/SimpleDB/Class/ResultSet.pm:182]SimpleDB::Class::ResultSet::__ANON__[../lib/SimpleDB/Class/ResultSet.pm:182]
0 | 0 | 0 | 0s | 0s | SimpleDB::Class::ResultSet::::deleteSimpleDB::Class::ResultSet::delete
0 | 0 | 0 | 0s | 0s | SimpleDB::Class::ResultSet::::searchSimpleDB::Class::ResultSet::search
0 | 0 | 0 | 0s | 0s | SimpleDB::Class::ResultSet::::to_array_refSimpleDB::Class::ResultSet::to_array_ref
0 | 0 | 0 | 0s | 0s | SimpleDB::Class::ResultSet::::updateSimpleDB::Class::ResultSet::update

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::ResultSet;
2 |  |  |  |  |
3 |  |  |  |  | =head1 NAME
4 |  |  |  |  |
5 |  |  |  |  | SimpleDB::Class::ResultSet - An iterator of items from a domain.
6 |  |  |  |  |
7 |  |  |  |  | =head1 DESCRIPTION
8 |  |  |  |  |
9 |  |  |  |  | This class is an iterator to walk to the items passed back from a query.
10 |  |  |  |  |
11 |  |  |  |  | B<Warning:> Once you have a result set and you start calling methods on it, it will begin iterating over the result set. Therefore you can't call both C<next> and C<search>, or any other combinations of methods on an existing result set.
12 |  |  |  |  |
13 |  |  |  |  | B<Warning:> If you call a method like C<search> on a result set which causes another query to be run, know that the original result set must be very small. This is because there is a limit of 20 comparisons per request as a limitation of SimpleDB.
14 |  |  |  |  |
15 |  |  |  |  | =head1 METHODS
16 |  |  |  |  |
17 |  |  |  |  | The following methods are available from this class.
18 |  |  |  |  |
19 |  |  |  |  | =cut
20 |  |  |  |  |
21 | 3 | 30µs | 2 | 5.05ms | # spent 2.54ms (32µs+2.51) within SimpleDB::Class::ResultSet::BEGIN@21 which was called # once (32µs+2.51ms) by SimpleDB::Class::Domain::BEGIN@19 at line 21 use Moose; # spent 2.54ms making 1 call to SimpleDB::Class::ResultSet::BEGIN@21 # spent 2.51ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:389]
22 | 3 | 994µs | 1 | 5µs | # spent 5µs within SimpleDB::Class::ResultSet::BEGIN@22 which was called # once (5µs+0s) by SimpleDB::Class::Domain::BEGIN@19 at line 22 use SimpleDB::Class::SQL; # spent 5µs making 1 call to SimpleDB::Class::ResultSet::BEGIN@22
23 |  |  |  |  |
24 |  |  |  |  | #--------------------------------------------------------
25 |  |  |  |  |
26 |  |  |  |  | =head2 new ( params )
27 |  |  |  |  |
28 |  |  |  |  | Constructor.
29 |  |  |  |  |
30 |  |  |  |  | =head3 params
31 |  |  |  |  |
32 |  |  |  |  | A hash.
33 |  |  |  |  |
34 |  |  |  |  | =head4 simpledb
35 |  |  |  |  |
36 |  |  |  |  | Required. A L<SimpleDB::Class> object.
37 |  |  |  |  |
38 |  |  |  |  | =head4 item_class
39 |  |  |  |  |
40 |  |  |  |  | Required. A L<SimpleDB::Class::Item> subclass name.
41 |  |  |  |  |
42 |  |  |  |  | =head4 result
43 |  |  |  |  |
44 |  |  |  |  | A result as returned from the send_request() method from L<SimpleDB::Client>. Either this or a where is required.
45 |  |  |  |  |
46 |  |  |  |  | =head4 where
47 |  |  |  |  |
48 |  |  |  |  | A where clause as defined in L<SimpleDB::Class::SQL>. Either this or a result is required.
49 |  |  |  |  |
50 |  |  |  |  | =head4 order_by
51 |  |  |  |  |
52 |  |  |  |  | An order_by clause as defined in L<SimpleDB::Class::SQL>. Optional.
53 |  |  |  |  |
54 |  |  |  |  | =head4 limit
55 |  |  |  |  |
56 |  |  |  |  | A limit clause as defined in L<SimpleDB::Class::SQL>. Optional. B<NOTE:>SimpleDB defines a limit as the number of results to limit to each Next Token, but SimpleDB::Class::ResultSet enforces the limit to be more like a traditional relational database, so calling C<next()> after the limit will return C<undef> just as if there were no more results left to display.
57 |  |  |  |  |
58 |  |  |  |  | =head4 consistent
59 |  |  |  |  |
60 |  |  |  |  | A boolean that if set true will get around Eventual Consistency, but at a reduced performance. Optional.
61 |  |  |  |  |
62 |  |  |  |  | =head4 set
63 |  |  |  |  |
64 |  |  |  |  | A hash reference of attribute names and values, which will be set on the item as C<next> is called. Doing so helps to prevent stale object references.
65 |  |  |  |  |
66 |  |  |  |  | =cut
67 |  |  |  |  |
68 |  |  |  |  | #--------------------------------------------------------
69 |  |  |  |  |
70 |  |  |  |  | =head2 item_class ( )
71 |  |  |  |  |
72 |  |  |  |  | Returns the item_class passed into the constructor.
73 |  |  |  |  |
74 |  |  |  |  | =cut
75 |  |  |  |  |
76 | 1 | 3µs | 1 | 1.45ms | has item_class => ( # spent 1.45ms making 1 call to Moose::has
77 |  |  |  |  | is => 'ro',
78 |  |  |  |  | isa => 'ClassName',
79 |  |  |  |  | required => 1,
80 |  |  |  |  | );
81 |  |  |  |  |
82 | 1 | 2µs | 1 | 59.8ms | with 'SimpleDB::Class::Role::Itemized'; # spent 59.8ms making 1 call to Moose::with
83 |  |  |  |  |
84 |  |  |  |  | #--------------------------------------------------------
85 |  |  |  |  |
86 |  |  |  |  | =head2 consistent ( )
87 |  |  |  |  |
88 |  |  |  |  | Returns the consistent value passed into the constructor.
89 |  |  |  |  |
90 |  |  |  |  | =cut
91 |  |  |  |  |
92 | 1 | 4µs | 1 | 1.70ms | has consistent => ( # spent 1.70ms making 1 call to Moose::has
93 |  |  |  |  | is => 'ro',
94 |  |  |  |  | isa => 'Bool',
95 |  |  |  |  | default => 0,
96 |  |  |  |  | );
97 |  |  |  |  |
98 |  |  |  |  | #--------------------------------------------------------
99 |  |  |  |  |
100 |  |  |  |  | =head2 set ( )
101 |  |  |  |  |
102 |  |  |  |  | Returns the set value passed into the constructor.
103 |  |  |  |  |
104 |  |  |  |  | =cut
105 |  |  |  |  |
106 |  |  |  |  | has set => (
107 |  |  |  |  | is => 'ro',
108 |  |  |  |  | isa => 'HashRef',
109 | 7 | 25µs |  |  | # spent 20µs within SimpleDB::Class::ResultSet::__ANON__[../lib/SimpleDB/Class/ResultSet.pm:109] which was called 7 times, avg 3µs/call: # 7 times (20µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 53 of Class/MOP/Mixin/AttributeCore.pm, avg 3µs/call default => sub { {} },
110 | 1 | 6µs | 1 | 1.10ms | ); # spent 1.10ms making 1 call to Moose::has
111 |  |  |  |  |
112 |  |  |  |  | #--------------------------------------------------------
113 |  |  |  |  |
114 |  |  |  |  | =head2 where ( )
115 |  |  |  |  |
116 |  |  |  |  | Returns the where passed into the constructor.
117 |  |  |  |  |
118 |  |  |  |  | =cut
119 |  |  |  |  |
120 | 1 | 2µs | 1 | 940µs | has where => ( # spent 940µs making 1 call to Moose::has
121 |  |  |  |  | is => 'ro',
122 |  |  |  |  | isa => 'HashRef',
123 |  |  |  |  | );
124 |  |  |  |  |
125 |  |  |  |  | #--------------------------------------------------------
126 |  |  |  |  |
127 |  |  |  |  | =head2 order_by ( )
128 |  |  |  |  |
129 |  |  |  |  | Returns the order_by passed into the constructor.
130 |  |  |  |  |
131 |  |  |  |  | =cut
132 |  |  |  |  |
133 | 1 | 2µs | 1 | 3.19ms | has order_by => ( # spent 3.19ms making 1 call to Moose::has
134 |  |  |  |  | is => 'ro',
135 |  |  |  |  | isa => 'Str | ArrayRef[Str]',
136 |  |  |  |  | predicate => 'has_order_by',
137 |  |  |  |  | );
138 |  |  |  |  |
139 |  |  |  |  | #--------------------------------------------------------
140 |  |  |  |  |
141 |  |  |  |  | =head2 limit ( )
142 |  |  |  |  |
143 |  |  |  |  | Returns the limit passed into the constructor.
144 |  |  |  |  |
145 |  |  |  |  | =cut
146 |  |  |  |  |
147 | 1 | 2µs | 1 | 1.50ms | has limit => ( # spent 1.50ms making 1 call to Moose::has
148 |  |  |  |  | is => 'rw',
149 |  |  |  |  | isa => 'Str',
150 |  |  |  |  | predicate => 'has_limit',
151 |  |  |  |  | );
152 |  |  |  |  |
153 |  |  |  |  | #--------------------------------------------------------
154 |  |  |  |  |
155 |  |  |  |  | =head2 simpledb ( )
156 |  |  |  |  |
157 |  |  |  |  | Returns the simpledb passed into the constructor.
158 |  |  |  |  |
159 |  |  |  |  | =cut
160 |  |  |  |  |
161 | 1 | 2µs | 1 | 914µs | has simpledb => ( # spent 914µs making 1 call to Moose::has
162 |  |  |  |  | is => 'ro',
163 |  |  |  |  | required => 1,
164 |  |  |  |  | );
165 |  |  |  |  |
166 |  |  |  |  | #--------------------------------------------------------
167 |  |  |  |  |
168 |  |  |  |  | =head2 result ( )
169 |  |  |  |  |
170 |  |  |  |  | Returns the result passed into the constructor, or the one generated by fetch_result() if a where is passed into the constructor.
171 |  |  |  |  |
172 |  |  |  |  | =head2 has_result ()
173 |  |  |  |  |
174 |  |  |  |  | A boolean indicating whether a result was passed into the constructor, or generated by fetch_result().
175 |  |  |  |  |
176 |  |  |  |  | =cut
177 |  |  |  |  |
178 |  |  |  |  | has result => (
179 |  |  |  |  | is => 'rw',
180 |  |  |  |  | isa => 'HashRef',
181 |  |  |  |  | predicate => 'has_result',
182 |  |  |  |  | default => sub {{}},
183 | 1 | 6µs | 1 | 1.55ms | lazy => 1, # spent 1.55ms making 1 call to Moose::has
184 |  |  |  |  | );
185 |  |  |  |  |
186 |  |  |  |  | #--------------------------------------------------------
187 |  |  |  |  |
188 |  |  |  |  | =head2 iterator ( )
189 |  |  |  |  |
190 |  |  |  |  | Returns an integer which represents the current position in the result set as traversed by C<next()>.
191 |  |  |  |  |
192 |  |  |  |  | =cut
193 |  |  |  |  |
194 | 1 | 2µs | 1 | 1.17ms | has iterator => ( # spent 1.17ms making 1 call to Moose::has
195 |  |  |  |  | is => 'rw',
196 |  |  |  |  | isa => 'Int',
197 |  |  |  |  | default => 0,
198 |  |  |  |  | );
199 |  |  |  |  |
200 |  |  |  |  | #--------------------------------------------------------
201 |  |  |  |  |
202 |  |  |  |  | =head2 limit_counter ( )
203 |  |  |  |  |
204 |  |  |  |  | Returns an integer representing how many items have been traversed so far by C<next()>. When this reaches the value of C<limit> then no more results will be returned by C<next()>.
205 |  |  |  |  |
206 |  |  |  |  | =cut
207 |  |  |  |  |
208 | 1 | 2µs | 1 | 1.21ms | has limit_counter => ( # spent 1.21ms making 1 call to Moose::has
209 |  |  |  |  | is => 'rw',
210 |  |  |  |  | isa => 'Int',
211 |  |  |  |  | default => 0,
212 |  |  |  |  | );
213 |  |  |  |  |
214 |  |  |  |  | #--------------------------------------------------------
215 |  |  |  |  |
216 |  |  |  |  | =head2 fetch_result ( [ next ] )
217 |  |  |  |  |
218 |  |  |  |  | Fetches a result, based on a where clause passed into a constructor, and then makes it accessible via the C<result()> method.
219 |  |  |  |  |
220 |  |  |  |  | =head3 next
221 |  |  |  |  |
222 |  |  |  |  | A next token, in order to fetch the next part of a result set.
223 |  |  |  |  |
224 |  |  |  |  | =cut
225 |  |  |  |  |
226 |  |  |  |  | # spent 848ms (770µs+847) within SimpleDB::Class::ResultSet::fetch_result which was called 10 times, avg 84.8ms/call: # 9 times (656µs+538ms) by SimpleDB::Class::ResultSet::next at line 432, avg 59.9ms/call # once (114µs+309ms) by SimpleDB::Class::ResultSet::paginate at line 410 sub fetch_result {
227 | 110 | 648µs |  |  | my ($self, $next) = @_;
228 |  |  |  |  | my %sql_params = ( # spent 41µs making 10 calls to SimpleDB::Class::ResultSet::where, avg 4µs/call # spent 32µs making 10 calls to SimpleDB::Class::ResultSet::item_class, avg 3µs/call # spent 25µs making 10 calls to SimpleDB::Class::ResultSet::simpledb, avg 3µs/call
229 |  |  |  |  | item_class => $self->item_class,
230 |  |  |  |  | simpledb => $self->simpledb,
231 |  |  |  |  | where => $self->where,
232 |  |  |  |  | );
233 |  |  |  |  | if ($self->has_order_by) { # spent 32µs making 10 calls to SimpleDB::Class::ResultSet::has_order_by, avg 3µs/call # spent 8µs making 2 calls to SimpleDB::Class::ResultSet::order_by, avg 4µs/call
234 |  |  |  |  | $sql_params{order_by} = $self->order_by;
235 |  |  |  |  | }
236 |  |  |  |  | if ($self->has_limit) { # spent 14µs making 10 calls to SimpleDB::Class::ResultSet::has_limit, avg 1µs/call # spent 5µs making 2 calls to SimpleDB::Class::ResultSet::limit, avg 3µs/call
237 |  |  |  |  | $sql_params{limit} = $self->limit;
238 |  |  |  |  | }
239 |  |  |  |  | my $select = SimpleDB::Class::SQL->new(%sql_params); # spent 327µs making 10 calls to SimpleDB::Class::SQL::new, avg 33µs/call
240 |  |  |  |  | my %params = (SelectExpression => $select->to_sql); # spent 3.69ms making 10 calls to SimpleDB::Class::SQL::to_sql, avg 369µs/call
241 |  |  |  |  | if ($self->consistent) { # spent 41µs making 10 calls to SimpleDB::Class::ResultSet::consistent, avg 4µs/call
242 |  |  |  |  | $params{ConsistentRead} = 'true';
243 |  |  |  |  | }
244 |  |  |  |  |
245 |  |  |  |  | # if we're fetching and we already have a result, we can assume we're getting the next batch
246 |  |  |  |  | if (defined $next && $next ne '') {
247 |  |  |  |  | $params{NextToken} = $next;
248 |  |  |  |  | }
249 |  |  |  |  |
250 |  |  |  |  | my $result = $self->simpledb->http->send_request('Select', \%params); # spent 843ms making 10 calls to SimpleDB::Client::send_request, avg 84.3ms/call # spent 51µs making 10 calls to SimpleDB::Class::http, avg 5µs/call # spent 17µs making 10 calls to SimpleDB::Class::ResultSet::simpledb, avg 2µs/call
251 |  |  |  |  | $self->result($result); # spent 197µs making 10 calls to SimpleDB::Class::ResultSet::result, avg 20µs/call
252 |  |  |  |  | return $result;
253 |  |  |  |  | }
254 |  |  |  |  |
255 |  |  |  |  | #--------------------------------------------------------
256 |  |  |  |  |
257 |  |  |  |  | =head2 count ( [ options ] )
258 |  |  |  |  |
259 |  |  |  |  | Counts the items in the result set. Returns an integer.
260 |  |  |  |  |
261 |  |  |  |  | =head3 options
262 |  |  |  |  |
263 |  |  |  |  | A hash of extra options you can pass to modify the count.
264 |  |  |  |  |
265 |  |  |  |  | =head4 where
266 |  |  |  |  |
267 |  |  |  |  | A where clause as defined by L<SimpleDB::Class::SQL>. If this is specified, then an additional query is executed before counting the items in the result set.
268 |  |  |  |  |
269 |  |  |  |  | =cut
270 |  |  |  |  |
271 |  |  |  |  | # spent 316ms (248µs+315) within SimpleDB::Class::ResultSet::count which was called 4 times, avg 78.9ms/call: # once (118µs+112ms) by main::RUNTIME at line 71 of 05.Domain_and_Item.t # once (47µs+76.6ms) by main::RUNTIME at line 69 of 05.Domain_and_Item.t # once (57µs+70.2ms) by main::RUNTIME at line 73 of 05.Domain_and_Item.t # once (26µs+56.8ms) by main::RUNTIME at line 74 of 05.Domain_and_Item.t sub count {
272 | 16 | 17µs |  |  | my ($self, %options) = @_;
273 |  |  |  |  | my @ids;
274 | 1 | 60µs | 28 | 262ms | while (my $item = $self->next) { # spent 261ms making 12 calls to SimpleDB::Class::ResultSet::next, avg 21.8ms/call # spent 445µs making 8 calls to Moose::Object::DESTROY, avg 56µs/call # spent 34µs making 8 calls to SimpleDB::Class::Item::id, avg 4µs/call
275 |  |  |  |  | push @ids, $item->id;
276 |  |  |  |  | }
277 | 9 | 134µs |  |  | if ($options{where}) {
278 |  |  |  |  | my $clauses = {
279 |  |  |  |  | 'itemName()' => ['in',@ids],
280 |  |  |  |  | '-and' => $options{where},
281 |  |  |  |  | };
282 |  |  |  |  | my $select = SimpleDB::Class::SQL->new( # spent 33µs making 1 call to SimpleDB::Class::SQL::new # spent 2µs making 1 call to SimpleDB::Class::ResultSet::item_class # spent 1µs making 1 call to SimpleDB::Class::ResultSet::simpledb
283 |  |  |  |  | item_class => $self->item_class,
284 |  |  |  |  | simpledb => $self->simpledb,
285 |  |  |  |  | where => $clauses,
286 |  |  |  |  | output => 'count(*)',
287 |  |  |  |  | );
288 |  |  |  |  | my %params = ( SelectExpression => $select->to_sql ); # spent 427µs making 1 call to SimpleDB::Class::SQL::to_sql
289 |  |  |  |  | if ($self->consistent) { # spent 4µs making 1 call to SimpleDB::Class::ResultSet::consistent
290 |  |  |  |  | $params{ConsistentRead} = 'true';
291 |  |  |  |  | }
292 |  |  |  |  | my $result = $self->simpledb->http->send_request('Select', \%params); # spent 53.4ms making 1 call to SimpleDB::Client::send_request # spent 5µs making 1 call to SimpleDB::Class::http # spent 1µs making 1 call to SimpleDB::Class::ResultSet::simpledb
293 |  |  |  |  | return $result->{SelectResult}{Item}[0]{Attribute}{Value};
294 |  |  |  |  | }
295 |  |  |  |  | else {
296 |  |  |  |  | return scalar @ids;
297 |  |  |  |  | }
298 |  |  |  |  | }
299 |  |  |  |  |
300 |  |  |  |  | #--------------------------------------------------------
301 |  |  |  |  |
302 |  |  |  |  | =head2 search ( options )
303 |  |  |  |  |
304 |  |  |  |  | Just like L<SimpleDB::Class::Domain/"search">, but searches within the confines of the current result set, and then returns a new result set.
305 |  |  |  |  |
306 |  |  |  |  | =head3 options
307 |  |  |  |  |
308 |  |  |  |  | A hash of extra options to modify the search.
309 |  |  |  |  |
310 |  |  |  |  | =head4 where
311 |  |  |  |  |
312 |  |  |  |  | A where clause as defined by L<SimpleDB::Class::SQL>.
313 |  |  |  |  |
314 |  |  |  |  | =cut
315 |  |  |  |  |
316 |  |  |  |  | sub search {
317 |  |  |  |  | my ($self, %options) = @_;
318 |  |  |  |  | my @ids;
319 |  |  |  |  | while (my $item = $self->next) {
320 |  |  |  |  | push @ids, $item->id;
321 |  |  |  |  | }
322 |  |  |  |  | my $clauses = {
323 |  |  |  |  | 'itemName()' => ['in',@ids],
324 |  |  |  |  | '-and' => $options{where},
325 |  |  |  |  | };
326 |  |  |  |  | return $self->new(
327 |  |  |  |  | simpledb => $self->simpledb,
328 |  |  |  |  | item_class => $self->item_class,
329 |  |  |  |  | where => $clauses,
330 |  |  |  |  | consistent => $self->consistent,
331 |  |  |  |  | set => $self->set,
332 |  |  |  |  | );
333 |  |  |  |  | }
334 |  |  |  |  |
335 |  |  |  |  | #--------------------------------------------------------
336 |  |  |  |  |
337 |  |  |  |  | =head2 update ( attributes )
338 |  |  |  |  |
339 |  |  |  |  | Calls C<update> and then C<put> on all the items in the result set.
340 |  |  |  |  |
341 |  |  |  |  | =head3 attributes
342 |  |  |  |  |
343 |  |  |  |  | A hash reference containing name/value pairs to update in each item.
344 |  |  |  |  |
345 |  |  |  |  | =cut
346 |  |  |  |  |
347 |  |  |  |  | sub update {
348 |  |  |  |  | my ($self, $attributes) = @_;
349 |  |  |  |  | while (my $item = $self->next) {
350 |  |  |  |  | $item->update($attributes)->put;
351 |  |  |  |  | }
352 |  |  |  |  | }
353 |  |  |  |  |
354 |  |  |  |  | #--------------------------------------------------------
355 |  |  |  |  |
356 |  |  |  |  | =head2 delete ( )
357 |  |  |  |  |
358 |  |  |  |  | Calls C<delete> on all the items in the result set.
359 |  |  |  |  |
360 |  |  |  |  | =cut
361 |  |  |  |  |
362 |  |  |  |  | sub delete {
363 |  |  |  |  | my ($self) = @_;
364 |  |  |  |  | while (my $item = $self->next) {
365 |  |  |  |  | $item->delete;
366 |  |  |  |  | }
367 |  |  |  |  | }
368 |  |  |  |  |
369 |  |  |  |  | #--------------------------------------------------------
370 |  |  |  |  |
371 |  |  |  |  | =head2 paginate ( items_per_page, page_number )
372 |  |  |  |  |
373 |  |  |  |  | Use on a new result set to fast forward to the desired data. After you've paginated, you can call C<next> to start fetching your data. Returns a reference to the result set for easy method chaining.
374 |  |  |  |  |
375 |  |  |  |  | B<NOTE:> Unless you've already set a limit, the limit for this result set will be set to C<items_per_page> as a convenience.
376 |  |  |  |  |
377 |  |  |  |  | =head3 items_per_page
378 |  |  |  |  |
379 |  |  |  |  | An integer representing how many items you're fetching/displaying per page.
380 |  |  |  |  |
381 |  |  |  |  | =head3 page_number
382 |  |  |  |  |
383 |  |  |  |  | An integer representing what page number you'd like to skip ahead to.
384 |  |  |  |  |
385 |  |  |  |  | =cut
386 |  |  |  |  |
387 |  |  |  |  | # spent 391ms (111µs+391) within SimpleDB::Class::ResultSet::paginate which was called # once (111µs+391ms) by main::RUNTIME at line 118 of 05.Domain_and_Item.t sub paginate {
388 | 12 | 87µs |  |  | my ($self, $items_per_page, $page_number) = @_;
389 |  |  |  |  | unless ($self->has_limit) { # spent 11µs making 1 call to SimpleDB::Class::ResultSet::limit # spent 3µs making 1 call to SimpleDB::Class::ResultSet::has_limit
390 |  |  |  |  | $self->limit($items_per_page);
391 |  |  |  |  | }
392 |  |  |  |  | my $limit = ($items_per_page * ($page_number - 1));
393 |  |  |  |  | return $self if $limit == 0;
394 |  |  |  |  | my %sql_params = ( # spent 4µs making 1 call to SimpleDB::Class::ResultSet::where # spent 4µs making 1 call to SimpleDB::Class::ResultSet::item_class # spent 3µs making 1 call to SimpleDB::Class::ResultSet::simpledb
395 |  |  |  |  | item_class => $self->item_class,
396 |  |  |  |  | simpledb => $self->simpledb,
397 |  |  |  |  | where => $self->where,
398 |  |  |  |  | output => 'count(*)',
399 |  |  |  |  | limit => $limit,
400 |  |  |  |  | );
401 |  |  |  |  | if ($self->has_order_by) { # spent 4µs making 1 call to SimpleDB::Class::ResultSet::order_by # spent 3µs making 1 call to SimpleDB::Class::ResultSet::has_order_by
402 |  |  |  |  | $sql_params{order_by} = $self->order_by;
403 |  |  |  |  | }
404 |  |  |  |  | my $select = SimpleDB::Class::SQL->new(%sql_params); # spent 33µs making 1 call to SimpleDB::Class::SQL::new
405 |  |  |  |  | my %params = (SelectExpression => $select->to_sql); # spent 538µs making 1 call to SimpleDB::Class::SQL::to_sql
406 |  |  |  |  | if ($self->consistent) { # spent 4µs making 1 call to SimpleDB::Class::ResultSet::consistent
407 |  |  |  |  | $params{ConsistentRead} = 'true';
408 |  |  |  |  | }
409 |  |  |  |  | my $result = $self->simpledb->http->send_request('Select', \%params); # spent 80.8ms making 1 call to SimpleDB::Client::send_request # spent 5µs making 1 call to SimpleDB::Class::http # spent 1µs making 1 call to SimpleDB::Class::ResultSet::simpledb
410 |  |  |  |  | $self->fetch_result($result->{SelectResult}{NextToken}); # spent 309ms making 1 call to SimpleDB::Class::ResultSet::fetch_result
411 |  |  |  |  | return $self;
412 |  |  |  |  | }
413 |  |  |  |  |
414 |  |  |  |  |
415 |  |  |  |  | #--------------------------------------------------------
416 |  |  |  |  |
417 |  |  |  |  | =head2 next ()
418 |  |  |  |  |
419 |  |  |  |  | Returns the next result in the result set. Also fetches th next partial result set if there's a next token in the first result set and you've iterated through the first partial set.
420 |  |  |  |  |
421 |  |  |  |  | =cut
422 |  |  |  |  |
423 |  |  |  |  | # spent 602ms (1.80+600) within SimpleDB::Class::ResultSet::next which was called 23 times, avg 26.2ms/call: # 12 times (725µs+260ms) by SimpleDB::Class::ResultSet::count at line 274, avg 21.8ms/call # 3 times (236µs+10.5ms) by main::RUNTIME at line 135 of 05.Domain_and_Item.t, avg 3.57ms/call # once (104µs+71.6ms) by main::RUNTIME at line 59 of 05.Domain_and_Item.t # once (128µs+66.6ms) by main::RUNTIME at line 88 of 05.Domain_and_Item.t # once (104µs+64.0ms) by main::RUNTIME at line 53 of 05.Domain_and_Item.t # once (139µs+63.9ms) by main::RUNTIME at line 134 of 05.Domain_and_Item.t # once (89µs+53.9ms) by main::RUNTIME at line 62 of 05.Domain_and_Item.t # once (151µs+4.60ms) by main::RUNTIME at line 123 of 05.Domain_and_Item.t # once (66µs+2.38ms) by main::RUNTIME at line 63 of 05.Domain_and_Item.t # once (55µs+2.22ms) by main::RUNTIME at line 54 of 05.Domain_and_Item.t sub next {
424 | 426 | 1.30ms |  |  | my ($self) = @_;
425 |  |  |  |  |
426 |  |  |  |  | # handle limit counter
427 |  |  |  |  | if ($self->has_limit && $self->limit_counter >= $self->limit) { # spent 64µs making 23 calls to SimpleDB::Class::ResultSet::has_limit, avg 3µs/call # spent 15µs making 5 calls to SimpleDB::Class::ResultSet::limit_counter, avg 3µs/call # spent 15µs making 5 calls to SimpleDB::Class::ResultSet::limit, avg 3µs/call
428 |  |  |  |  | return undef;
429 |  |  |  |  | }
430 |  |  |  |  |
431 |  |  |  |  | # get the current results
432 |  |  |  |  | my $result = ($self->has_result) ? $self->result : $self->fetch_result; # spent 539ms making 9 calls to SimpleDB::Class::ResultSet::fetch_result, avg 59.9ms/call # spent 55µs making 22 calls to SimpleDB::Class::ResultSet::has_result, avg 2µs/call # spent 34µs making 13 calls to SimpleDB::Class::ResultSet::result, avg 3µs/call
433 |  |  |  |  | my $items = [];
434 |  |  |  |  | if (ref $result->{SelectResult}{Item} eq 'ARRAY') {
435 |  |  |  |  | $items = $result->{SelectResult}{Item};
436 |  |  |  |  | }
437 |  |  |  |  |
438 |  |  |  |  | # fetch more results if needed
439 |  |  |  |  | my $iterator = $self->iterator; # spent 70µs making 22 calls to SimpleDB::Class::ResultSet::iterator, avg 3µs/call
440 | 4 | 4µs |  |  | if ($iterator >= scalar @{$items}) {
441 | 4 | 8µs |  |  | if (exists $result->{SelectResult}{NextToken}) {
442 |  |  |  |  | $self->iterator(0);
443 |  |  |  |  | $iterator = 0;
444 |  |  |  |  | $result = $self->fetch_result($result->{SelectResult}{NextToken});
445 |  |  |  |  | $items = $result->{SelectResult}{Item};
446 |  |  |  |  | }
447 |  |  |  |  | else {
448 |  |  |  |  | return undef;
449 |  |  |  |  | }
450 |  |  |  |  | }
451 |  |  |  |  |
452 |  |  |  |  | # iterate
453 |  |  |  |  | my $item = $items->[$iterator];
454 |  |  |  |  | return undef unless defined $item;
455 |  |  |  |  | $iterator++;
456 |  |  |  |  | $self->iterator($iterator); # spent 281µs making 18 calls to SimpleDB::Class::ResultSet::iterator, avg 16µs/call
457 |  |  |  |  |
458 |  |  |  |  | # make the item object
459 |  |  |  |  | my $db = $self->simpledb; # spent 50µs making 18 calls to SimpleDB::Class::ResultSet::simpledb, avg 3µs/call
460 |  |  |  |  | my $domain_name = $db->add_domain_prefix($self->item_class->domain_name); # spent 209µs making 18 calls to SimpleDB::Class::add_domain_prefix, avg 12µs/call # spent 54µs making 18 calls to SimpleDB::Class::ResultSet::item_class, avg 3µs/call # spent 44µs making 17 calls to Foo::Domain::domain_name, avg 3µs/call # spent 4µs making 1 call to Foo::Child::domain_name
461 |  |  |  |  | my $cache = $db->cache; # spent 82µs making 18 calls to SimpleDB::Class::cache, avg 5µs/call
462 |  |  |  |  | ## fetch from cache even though we've already pulled it back from the db, because the one in cache
463 |  |  |  |  | ## might be more up to date than the one from the DB
464 | 18 | 64µs | 18 | 18.4ms | my $attributes = eval{$cache->get($domain_name, $item->{Name})}; # spent 18.4ms making 18 calls to SimpleDB::Class::Cache::get, avg 1.02ms/call
465 |  |  |  |  | my $e;
466 |  |  |  |  | my $itemobj;
467 | 6 | 13µs | 51 | 26.9ms | if ($e = SimpleDB::Class::Exception::ObjectNotFound->caught) { # spent 26.5ms making 15 calls to SimpleDB::Class::Role::Itemized::instantiate_item, avg 1.77ms/call # spent 361µs making 33 calls to Exception::Class::Base::caught, avg 11µs/call # spent 6µs making 3 calls to Exception::Class::Base::__ANON__[Exception/Class/Base.pm:30], avg 2µs/call
468 |  |  |  |  | $itemobj = $self->parse_item($item->{Name}, $item->{Attribute}); # spent 12.7ms making 3 calls to SimpleDB::Class::Role::Itemized::parse_item, avg 4.23ms/call
469 | 3 | 2µs |  |  | if (defined $itemobj) {
470 | 3 | 15µs | 6 | 1.59ms | eval{$cache->set($domain_name, $item->{Name}, $itemobj->to_hashref)}; # spent 1.01ms making 3 calls to SimpleDB::Class::Cache::set, avg 336µs/call # spent 582µs making 3 calls to SimpleDB::Class::Item::to_hashref, avg 194µs/call
471 |  |  |  |  | }
472 |  |  |  |  | }
473 |  |  |  |  | elsif ($e = SimpleDB::Class::Exception->caught) {
474 |  |  |  |  | warn $e->error;
475 |  |  |  |  | $e->rethrow;
476 |  |  |  |  | }
477 |  |  |  |  | elsif (defined $attributes) {
478 |  |  |  |  | $itemobj = $self->instantiate_item($attributes,$item->{Name});
479 |  |  |  |  | }
480 |  |  |  |  | else {
481 |  |  |  |  | SimpleDB::Class::Exception->throw(error=>"An undefined error occured while fetching the item from cache.");
482 |  |  |  |  | }
483 |  |  |  |  |
484 |  |  |  |  | # process the 'set' option
485 |  |  |  |  | my %set = %{$self->set}; # spent 68µs making 18 calls to SimpleDB::Class::ResultSet::set, avg 4µs/call
486 |  |  |  |  | foreach my $attribute (keys %set) {
487 | 5 | 15µs | 5 | 21µs | $itemobj->$attribute( $set{$attribute} ); # spent 14µs making 4 calls to Foo::Domain::parent, avg 4µs/call # spent 7µs making 1 call to Foo::Child::domain
488 |  |  |  |  | }
489 |  |  |  |  |
490 |  |  |  |  | # increment limit counter
491 |  |  |  |  | $self->limit_counter($self->limit_counter + 1); # spent 297µs making 36 calls to SimpleDB::Class::ResultSet::limit_counter, avg 8µs/call
492 |  |  |  |  |
493 |  |  |  |  | return $itemobj;
494 |  |  |  |  | }
495 |  |  |  |  |
496 |  |  |  |  | #--------------------------------------------------------
497 |  |  |  |  |
498 |  |  |  |  | =head2 to_array_ref ()
499 |  |  |  |  |
500 |  |  |  |  | Returns an array reference containing all the objects in the result set. If the result set has already been partially walked, then only the remaining objects will be returned.
501 |  |  |  |  |
502 |  |  |  |  | =cut
503 |  |  |  |  |
504 |  |  |  |  | sub to_array_ref {
505 |  |  |  |  | my ($self) = @_;
506 |  |  |  |  | my @all;
507 |  |  |  |  | while (my $object = $self->next) {
508 |  |  |  |  | push @all, $object;
509 |  |  |  |  | }
510 |  |  |  |  | return \@all;
511 |  |  |  |  | }
512 |  |  |  |  |
513 |  |  |  |  |
514 |  |  |  |  | =head1 LEGAL
515 |  |  |  |  |
516 |  |  |  |  | SimpleDB::Class is Copyright 2009-2010 Plain Black Corporation (L<http://www.plainblack.com/>) and is licensed under the same terms as Perl itself.
517 |  |  |  |  |
518 |  |  |  |  | =cut
519 |  |  |  |  |
520 | 3 | 52µs | 2 | 212µs | # spent 112µs (13+99) within SimpleDB::Class::ResultSet::BEGIN@520 which was called # once (13µs+99µs) by SimpleDB::Class::Domain::BEGIN@19 at line 520 no Moose; # spent 112µs making 1 call to SimpleDB::Class::ResultSet::BEGIN@520 # spent 99µs making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:478]
521 | 1 | 79µs | 2 | 3.89ms | __PACKAGE__->meta->make_immutable; # spent 3.88ms making 1 call to Class::MOP::Class::make_immutable # spent 12µs making 1 call to SimpleDB::Class::ResultSet::meta