← Index
NYTProf Performance Profile   « line view »
For starman worker -M FindBin --max-requests 50 --workers 2 --user=kohadev-koha --group kohadev-koha --pid /var/run/koha/kohadev/plack.pid --daemonize --access-log /var/log/koha/kohadev/plack.log --error-log /var/log/koha/kohadev/plack-error.log -E deployment --socket /var/run/koha/kohadev/plack.sock /etc/koha/sites/kohadev/plack.psgi
  Run on Fri Jan 8 14:31:06 2016
Reported on Fri Jan 8 14:33:28 2016

Filename/usr/share/perl5/DBIx/Class/ResultSetColumn.pm
StatementsExecuted 43 statements in 186µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111127µs825µsDBIx::Class::ResultSetColumn::::newDBIx::Class::ResultSetColumn::new
11126µs187µsDBIx::Class::ResultSetColumn::::_resultsetDBIx::Class::ResultSetColumn::_resultset
51124µs24µsDBIx::Class::ResultSetColumn::::CORE:regcompDBIx::Class::ResultSetColumn::CORE:regcomp (opcode)
11121µs1.78msDBIx::Class::ResultSetColumn::::nextDBIx::Class::ResultSetColumn::next
11118µs48µsDBIx::Class::ResultSetColumn::::BEGIN@8DBIx::Class::ResultSetColumn::BEGIN@8
11116µs23µsDBIx::Class::ResultSetColumn::::BEGIN@3DBIx::Class::ResultSetColumn::BEGIN@3
11112µs163µsDBIx::Class::ResultSetColumn::::BEGIN@9DBIx::Class::ResultSetColumn::BEGIN@9
1119µs46µsDBIx::Class::ResultSetColumn::::BEGIN@6DBIx::Class::ResultSetColumn::BEGIN@6
1117µs10µsDBIx::Class::ResultSetColumn::::BEGIN@4DBIx::Class::ResultSetColumn::BEGIN@4
1117µs33µsDBIx::Class::ResultSetColumn::::BEGIN@7DBIx::Class::ResultSetColumn::BEGIN@7
1114µs4µsDBIx::Class::ResultSetColumn::::BEGIN@12DBIx::Class::ResultSetColumn::BEGIN@12
10112µs2µsDBIx::Class::ResultSetColumn::::CORE:matchDBIx::Class::ResultSetColumn::CORE:match (opcode)
0000s0sDBIx::Class::ResultSetColumn::::__ANON__[:59]DBIx::Class::ResultSetColumn::__ANON__[:59]
0000s0sDBIx::Class::ResultSetColumn::::allDBIx::Class::ResultSetColumn::all
0000s0sDBIx::Class::ResultSetColumn::::as_queryDBIx::Class::ResultSetColumn::as_query
0000s0sDBIx::Class::ResultSetColumn::::firstDBIx::Class::ResultSetColumn::first
0000s0sDBIx::Class::ResultSetColumn::::funcDBIx::Class::ResultSetColumn::func
0000s0sDBIx::Class::ResultSetColumn::::func_rsDBIx::Class::ResultSetColumn::func_rs
0000s0sDBIx::Class::ResultSetColumn::::maxDBIx::Class::ResultSetColumn::max
0000s0sDBIx::Class::ResultSetColumn::::max_rsDBIx::Class::ResultSetColumn::max_rs
0000s0sDBIx::Class::ResultSetColumn::::minDBIx::Class::ResultSetColumn::min
0000s0sDBIx::Class::ResultSetColumn::::min_rsDBIx::Class::ResultSetColumn::min_rs
0000s0sDBIx::Class::ResultSetColumn::::resetDBIx::Class::ResultSetColumn::reset
0000s0sDBIx::Class::ResultSetColumn::::singleDBIx::Class::ResultSetColumn::single
0000s0sDBIx::Class::ResultSetColumn::::sumDBIx::Class::ResultSetColumn::sum
0000s0sDBIx::Class::ResultSetColumn::::sum_rsDBIx::Class::ResultSetColumn::sum_rs
0000s0sDBIx::Class::ResultSetColumn::::throw_exceptionDBIx::Class::ResultSetColumn::throw_exception
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package DBIx::Class::ResultSetColumn;
2
3229µs
# spent 23µs (16+6) within DBIx::Class::ResultSetColumn::BEGIN@3 which was called: # once (16µs+6µs) by DBIx::Class::ResultSet::BEGIN@7 at line 3
use strict;
# spent 23µs making 1 call to DBIx::Class::ResultSetColumn::BEGIN@3 # spent 6µs making 1 call to strict::import
4214µs
# spent 10µs (7+4) within DBIx::Class::ResultSetColumn::BEGIN@4 which was called: # once (7µs+4µs) by DBIx::Class::ResultSet::BEGIN@7 at line 4
use warnings;
# spent 10µs making 1 call to DBIx::Class::ResultSetColumn::BEGIN@4 # spent 4µs making 1 call to warnings::import
5
6246µs
# spent 46µs (9+37) within DBIx::Class::ResultSetColumn::BEGIN@6 which was called: # once (9µs+37µs) by DBIx::Class::ResultSet::BEGIN@7 at line 6
use base 'DBIx::Class';
# spent 46µs making 1 call to DBIx::Class::ResultSetColumn::BEGIN@6 # spent 37µs making 1 call to base::import, recursion: max depth 1, sum of overlapping time 37µs
7259µs
# spent 33µs (7+26) within DBIx::Class::ResultSetColumn::BEGIN@7 which was called: # once (7µs+26µs) by DBIx::Class::ResultSet::BEGIN@7 at line 7
use DBIx::Class::Carp;
# spent 33µs making 1 call to DBIx::Class::ResultSetColumn::BEGIN@7 # spent 26µs making 1 call to DBIx::Class::Carp::import
8279µs
# spent 48µs (18+31) within DBIx::Class::ResultSetColumn::BEGIN@8 which was called: # once (18µs+31µs) by DBIx::Class::ResultSet::BEGIN@7 at line 8
use DBIx::Class::_Util 'fail_on_internal_wantarray';
# spent 48µs making 1 call to DBIx::Class::ResultSetColumn::BEGIN@8 # spent 31µs making 1 call to Exporter::import
92315µs
# spent 163µs (12+152) within DBIx::Class::ResultSetColumn::BEGIN@9 which was called: # once (12µs+152µs) by DBIx::Class::ResultSet::BEGIN@7 at line 9
use namespace::clean;
# spent 163µs making 1 call to DBIx::Class::ResultSetColumn::BEGIN@9 # spent 152µs making 1 call to namespace::clean::import
10
11# not importing first() as it will clash with our own method
1214µs
# spent 4µs within DBIx::Class::ResultSetColumn::BEGIN@12 which was called: # once (4µs+0s) by DBIx::Class::ResultSet::BEGIN@7 at line 12
use List::Util ();
# spent 4µs making 1 call to DBIx::Class::ResultSetColumn::BEGIN@12
13
14=head1 NAME
15
16 DBIx::Class::ResultSetColumn - helpful methods for messing
17 with a single column of the resultset
18
19=head1 SYNOPSIS
20
21 $rs = $schema->resultset('CD')->search({ artist => 'Tool' });
22 $rs_column = $rs->get_column('year');
23 $max_year = $rs_column->max; #returns latest year
24
25=head1 DESCRIPTION
26
27A convenience class used to perform operations on a specific column of
28a resultset.
29
30=cut
31
32=head1 METHODS
33
34=head2 new
35
36 my $obj = DBIx::Class::ResultSetColumn->new($rs, $column);
37
38Creates a new resultset column object from the resultset and column
39passed as params. Used internally by L<DBIx::Class::ResultSet/get_column>.
40
41=cut
42
43
# spent 825µs (127+699) within DBIx::Class::ResultSetColumn::new which was called: # once (127µs+699µs) by DBIx::Class::ResultSet::get_column at line 1127 of DBIx/Class/ResultSet.pm
sub new {
441400ns my ($class, $rs, $column) = @_;
451300ns $class = ref $class if ref $class;
46
471300ns $rs->throw_exception('column must be supplied') unless $column;
48
4911µs157µs my $orig_attrs = $rs->_resolved_attrs;
# spent 57µs making 1 call to DBIx::Class::ResultSet::_resolved_attrs
5014µs14µs my $alias = $rs->current_source_alias;
# spent 4µs making 1 call to DBIx::Class::ResultSet::current_source_alias
5116µs12µs my $rsrc = $rs->result_source;
# spent 2µs making 1 call to DBIx::Class::ResultSet::result_source
52
53 # If $column can be found in the 'as' list of the parent resultset, use the
54 # corresponding element of its 'select' list (to keep any custom column
55 # definition set up with 'select' or '+select' attrs), otherwise use $column
56 # (to create a new column definition on-the-fly).
571600ns my $as_list = $orig_attrs->{as} || [];
581400ns my $select_list = $orig_attrs->{select} || [];
59213µs12µs my $as_index = List::Util::first { ($as_list->[$_] || "") eq $column } 0..$#$as_list;
# spent 2µs making 1 call to List::Util::first
6012µs my $select = defined $as_index ? $select_list->[$as_index] : $column;
61
621200ns my $colmap;
6313µs13µs for ($rsrc->columns, $column) {
# spent 3µs making 1 call to DBIx::Class::ResultSource::columns
64554µs1526µs if ($_ =~ /^ \Q$alias\E \. ([^\.]+) $ /x) {
# spent 24µs making 5 calls to DBIx::Class::ResultSetColumn::CORE:regcomp, avg 5µs/call # spent 2µs making 10 calls to DBIx::Class::ResultSetColumn::CORE:match, avg 210ns/call
65 $colmap->{$_} = $1;
66 }
67 elsif ($_ !~ /\./) {
6856µs $colmap->{"$alias.$_"} = $_;
6953µs $colmap->{$_} = $_;
70 }
71 }
72
731300ns my $new_parent_rs;
74 # analyze the order_by, and see if it is done over a function/nonexistentcolumn
75 # if this is the case we will need to wrap a subquery since the result of RSC
76 # *must* be a single column select
77116µs3433µs if (
# spent 424µs making 1 call to DBIx::Class::Storage::DBIHacks::_extract_order_criteria # spent 8µs making 1 call to DBIx::Class::Schema::storage # spent 2µs making 1 call to DBIx::Class::ResultSource::schema
78 scalar grep
79 { ! exists $colmap->{$_->[0]} }
80 ( $rsrc->schema->storage->_extract_order_criteria ($orig_attrs->{order_by} ) )
81 ) {
82 # nuke the prefetch before collapsing to sql
83 my $subq_rs = $rs->search_rs;
84 $subq_rs->{attrs}{join} = $subq_rs->_merge_joinpref_attr( $subq_rs->{attrs}{join}, delete $subq_rs->{attrs}{prefetch} );
85 $new_parent_rs = $subq_rs->as_subselect_rs;
86 }
87
8813µs1166µs $new_parent_rs ||= $rs->search_rs;
# spent 166µs making 1 call to DBIx::Class::ResultSet::search_rs
891800ns my $new_attrs = $new_parent_rs->{attrs} ||= {};
90
91 # prefetch causes additional columns to be fetched, but we can not just make a new
92 # rs via the _resolved_attrs trick - we need to retain the separation between
93 # +select/+as and select/as. At the same time we want to preserve any joins that the
94 # prefetch would otherwise generate.
95111µs17µs $new_attrs->{join} = $rs->_merge_joinpref_attr( $new_attrs->{join}, delete $new_attrs->{prefetch} );
# spent 7µs making 1 call to DBIx::Class::ResultSet::_merge_joinpref_attr
96
97 # {collapse} would mean a has_many join was injected, which in turn means
98 # we need to group *IF WE CAN* (only if the column in question is unique)
991900ns if (!$orig_attrs->{group_by} && $orig_attrs->{collapse}) {
100
101 if ($colmap->{$select} and $rsrc->_identifying_column_set([$colmap->{$select}])) {
102 $new_attrs->{group_by} = [ $select ];
103 delete @{$new_attrs}{qw(distinct _grouped_by_distinct)}; # it is ignored when group_by is present
104 }
105 else {
106 carp (
107 "Attempting to retrieve non-unique column '$column' on a resultset containing "
108 . 'one-to-many joins will return duplicate results.'
109 );
110 }
111 }
112
113114µs return bless {
114 _select => $select,
115 _as => $column,
116 _parent_resultset => $new_parent_rs
117 }, $class;
118}
119
120=head2 as_query
121
122=over 4
123
124=item Arguments: none
125
126=item Return Value: \[ $sql, L<@bind_values|DBIx::Class::ResultSet/DBIC BIND VALUES> ]
127
128=back
129
130Returns the SQL query and bind vars associated with the invocant.
131
132This is generally used as the RHS for a subquery.
133
134=cut
135
136sub as_query { return shift->_resultset->as_query(@_) }
137
138=head2 next
139
140=over 4
141
142=item Arguments: none
143
144=item Return Value: $value
145
146=back
147
148Returns the next value of the column in the resultset (or C<undef> if
149there is none).
150
151Much like L<DBIx::Class::ResultSet/next> but just returning the
152one value.
153
154=cut
155
156
# spent 1.78ms (21µs+1.75) within DBIx::Class::ResultSetColumn::next which was called: # once (21µs+1.75ms) by DBIx::Class::ResultSet::count at line 1610 of DBIx/Class/ResultSet.pm
sub next {
1571400ns my $self = shift;
158
159 # using cursor so we don't inflate anything
160112µs31.75ms my ($row) = $self->_resultset->cursor->next;
# spent 1.28ms making 1 call to DBIx::Class::Storage::DBI::Cursor::next # spent 288µs making 1 call to DBIx::Class::ResultSet::cursor # spent 187µs making 1 call to DBIx::Class::ResultSetColumn::_resultset
161
16218µs return $row;
163}
164
165=head2 all
166
167=over 4
168
169=item Arguments: none
170
171=item Return Value: @values
172
173=back
174
175Returns all values of the column in the resultset (or C<undef> if
176there are none).
177
178Much like L<DBIx::Class::ResultSet/all> but returns values rather
179than result objects.
180
181=cut
182
183sub all {
184 my $self = shift;
185
186 # using cursor so we don't inflate anything
187 return map { $_->[0] } $self->_resultset->cursor->all;
188}
189
190=head2 reset
191
192=over 4
193
194=item Arguments: none
195
196=item Return Value: $self
197
198=back
199
200Resets the underlying resultset's cursor, so you can iterate through the
201elements of the column again.
202
203Much like L<DBIx::Class::ResultSet/reset>.
204
205=cut
206
207sub reset {
208 my $self = shift;
209 $self->_resultset->cursor->reset;
210 return $self;
211}
212
213=head2 first
214
215=over 4
216
217=item Arguments: none
218
219=item Return Value: $value
220
221=back
222
223Resets the underlying resultset and returns the next value of the column in the
224resultset (or C<undef> if there is none).
225
226Much like L<DBIx::Class::ResultSet/first> but just returning the one value.
227
228=cut
229
230sub first {
231 my $self = shift;
232
233 # using cursor so we don't inflate anything
234 $self->_resultset->cursor->reset;
235 my ($row) = $self->_resultset->cursor->next;
236
237 return $row;
238}
239
240=head2 single
241
242=over 4
243
244=item Arguments: none
245
246=item Return Value: $value
247
248=back
249
250Much like L<DBIx::Class::ResultSet/single> fetches one and only one column
251value using the cursor directly. If additional rows are present a warning
252is issued before discarding the cursor.
253
254=cut
255
256sub single {
257 my $self = shift;
258
259 my $attrs = $self->_resultset->_resolved_attrs;
260 my ($row) = $self->_resultset->result_source->storage->select_single(
261 $attrs->{from}, $attrs->{select}, $attrs->{where}, $attrs
262 );
263
264 return $row;
265}
266
267=head2 min
268
269=over 4
270
271=item Arguments: none
272
273=item Return Value: $lowest_value
274
275=back
276
277 my $first_year = $year_col->min();
278
279Wrapper for ->func. Returns the lowest value of the column in the
280resultset (or C<undef> if there are none).
281
282=cut
283
284sub min {
285 return shift->func('MIN');
286}
287
288=head2 min_rs
289
290=over 4
291
292=item Arguments: none
293
294=item Return Value: L<$resultset|DBIx::Class::ResultSet>
295
296=back
297
298 my $rs = $year_col->min_rs();
299
300Wrapper for ->func_rs for function MIN().
301
302=cut
303
304sub min_rs { return shift->func_rs('MIN') }
305
306=head2 max
307
308=over 4
309
310=item Arguments: none
311
312=item Return Value: $highest_value
313
314=back
315
316 my $last_year = $year_col->max();
317
318Wrapper for ->func. Returns the highest value of the column in the
319resultset (or C<undef> if there are none).
320
321=cut
322
323sub max {
324 return shift->func('MAX');
325}
326
327=head2 max_rs
328
329=over 4
330
331=item Arguments: none
332
333=item Return Value: L<$resultset|DBIx::Class::ResultSet>
334
335=back
336
337 my $rs = $year_col->max_rs();
338
339Wrapper for ->func_rs for function MAX().
340
341=cut
342
343sub max_rs { return shift->func_rs('MAX') }
344
345=head2 sum
346
347=over 4
348
349=item Arguments: none
350
351=item Return Value: $sum_of_values
352
353=back
354
355 my $total = $prices_col->sum();
356
357Wrapper for ->func. Returns the sum of all the values in the column of
358the resultset. Use on varchar-like columns at your own risk.
359
360=cut
361
362sub sum {
363 return shift->func('SUM');
364}
365
366=head2 sum_rs
367
368=over 4
369
370=item Arguments: none
371
372=item Return Value: L<$resultset|DBIx::Class::ResultSet>
373
374=back
375
376 my $rs = $year_col->sum_rs();
377
378Wrapper for ->func_rs for function SUM().
379
380=cut
381
382sub sum_rs { return shift->func_rs('SUM') }
383
384=head2 func
385
386=over 4
387
388=item Arguments: $function
389
390=item Return Value: $function_return_value
391
392=back
393
394 $rs = $schema->resultset("CD")->search({});
395 $length = $rs->get_column('title')->func('LENGTH');
396
397Runs a query using the function on the column and returns the
398value. Produces the following SQL:
399
400 SELECT LENGTH( title ) FROM cd me
401
402=cut
403
404sub func {
405 my ($self,$function) = @_;
406 my $cursor = $self->func_rs($function)->cursor;
407
408 if( wantarray ) {
409 DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_WANTARRAY and my $sog = fail_on_internal_wantarray;
410 return map { $_->[ 0 ] } $cursor->all;
411 }
412
413 return ( $cursor->next )[ 0 ];
414}
415
416=head2 func_rs
417
418=over 4
419
420=item Arguments: $function
421
422=item Return Value: L<$resultset|DBIx::Class::ResultSet>
423
424=back
425
426Creates the resultset that C<func()> uses to run its query.
427
428=cut
429
430sub func_rs {
431 my ($self,$function) = @_;
432
433 my $rs = $self->{_parent_resultset};
434 my $select = $self->{_select};
435
436 # wrap a grouped rs
437 if ($rs->_resolved_attrs->{group_by}) {
438 $select = $self->{_as};
439 $rs = $rs->as_subselect_rs;
440 }
441
442 $rs->search( undef, {
443 columns => { $self->{_as} => { $function => $select } }
444 } );
445}
446
447=head2 throw_exception
448
449See L<DBIx::Class::Schema/throw_exception> for details.
450
451=cut
452
453sub throw_exception {
454 my $self = shift;
455
456 if (ref $self && $self->{_parent_resultset}) {
457 $self->{_parent_resultset}->throw_exception(@_);
458 }
459 else {
460 DBIx::Class::Exception->throw(@_);
461 }
462}
463
464# _resultset
465#
466# Arguments: none
467#
468# Return Value: $resultset
469#
470# $year_col->_resultset->next
471#
472# Returns the underlying resultset. Creates it from the parent resultset if
473# necessary.
474#
475
# spent 187µs (26+161) within DBIx::Class::ResultSetColumn::_resultset which was called: # once (26µs+161µs) by DBIx::Class::ResultSetColumn::next at line 160
sub _resultset {
4761300ns my $self = shift;
477
478122µs return $self->{_resultset} ||= do {
479
4801500ns my $select = $self->{_select};
481
48211µs if ($self->{_parent_resultset}{attrs}{distinct}) {
483 my $alias = $self->{_parent_resultset}->current_source_alias;
484 my $rsrc = $self->{_parent_resultset}->result_source;
485 my %cols = map { $_ => 1, "$alias.$_" => 1 } $rsrc->columns;
486
487 unless( $cols{$select} ) {
488 carp_unique(
489 'Use of distinct => 1 while selecting anything other than a column '
490 . 'declared on the primary ResultSource is deprecated (you selected '
491 . "'$self->{_as}') - please supply an explicit group_by instead"
492 );
493
494 # collapse the selector to a literal so that it survives the distinct parse
495 # if it turns out to be an aggregate - at least the user will get a proper exception
496 # instead of silent drop of the group_by altogether
497 $select = \[ $rsrc->storage->sql_maker->_recurse_fields($select) ];
498 }
499 }
500
50114µs1161µs $self->{_parent_resultset}->search(undef, {
# spent 161µs making 1 call to DBIx::Class::ResultSet::search
502 columns => { $self->{_as} => $select }
503 });
504 };
505}
506
507=head1 FURTHER QUESTIONS?
508
509Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
510
511=head1 COPYRIGHT AND LICENSE
512
513This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
514by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
515redistribute it and/or modify it under the same terms as the
516L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
517
518=cut
519
5201;
5211122µs
# spent 122µs making 1 call to B::Hooks::EndOfScope::XS::__ANON__
 
# spent 2µs within DBIx::Class::ResultSetColumn::CORE:match which was called 10 times, avg 210ns/call: # 10 times (2µs+0s) by DBIx::Class::ResultSetColumn::new at line 64, avg 210ns/call
sub DBIx::Class::ResultSetColumn::CORE:match; # opcode
# spent 24µs within DBIx::Class::ResultSetColumn::CORE:regcomp which was called 5 times, avg 5µs/call: # 5 times (24µs+0s) by DBIx::Class::ResultSetColumn::new at line 64, avg 5µs/call
sub DBIx::Class::ResultSetColumn::CORE:regcomp; # opcode