| 1 | package DBIO::ResultSetColumn; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Convenience wrapper for working with a single ResultSet column | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 379 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 379 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 379 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 379 | ▶ | use base 'DBIO::Base'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 379 | ▶ | use DBIO::Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 379 | ▶ | use DBIO::Util qw(assert_no_list_context assert_function_name); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 379 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 379 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 259 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=18 SCAR=33.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 259 | my ($class, $rs, $column) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 259 | ▶ | $class = ref $class if ref $class; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 259 | ▶ | $rs->throw_exception('column must be supplied') unless $column; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 259 | my $orig_attrs = $rs->_resolved_attrs; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 259 | my $alias = $rs->current_source_alias; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 259 | my $rsrc = $rs->result_source; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | # If $column can be found in the 'as' list of the parent resultset, use the | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # corresponding element of its 'select' list (to keep any custom column | ||||||||||||||||||||||||||||||||||||||||||
| 30 | # definition set up with 'select' or '+select' attrs), otherwise use $column | ||||||||||||||||||||||||||||||||||||||||||
| 31 | # (to create a new column definition on-the-fly). | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 259 | ▶ | my $as_list = $orig_attrs->{as} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$orig_attrs->{'as'} || []
MC/DC0%0/1
$orig_attrs->{'as'} || []
$orig_attrs->{'as'}
Truth table50%1/2
A
A= $orig_attrs->{'as'}
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 259 | ▶ | my $select_list = $orig_attrs->{select} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$orig_attrs->{'select'} || []
MC/DC0%0/1
$orig_attrs->{'select'} || []
$orig_attrs->{'select'}
Truth table50%1/2
A
A= $orig_attrs->{'select'}
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 259 | ▶ | my ($as_index) = grep { ($as_list->[$_] || "") eq $column } 0..$#$as_list; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$as_list->[$_] || ''
MC/DC0%0/1
$as_list->[$_] || ''
$as_list->[$_]
Truth table50%1/2
A
A= $as_list->[$_]
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 259 | ▶ | my $select = defined $as_index ? $select_list->[$as_index] : $column; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 259 | my $colmap; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 259 | for ($rsrc->columns, $column) { | |||||||||||||||||||||||||||||||||||||||||
| 39 | 1434 | ▶ | if ($_ =~ /^ \Q$alias\E \. ([^\.]+) $ /x) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $colmap->{$_} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | elsif ($_ !~ /\./) { | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 1434 | $colmap->{"$alias.$_"} = $_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 1434 | $colmap->{$_} = $_; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 259 | my $new_parent_rs; | |||||||||||||||||||||||||||||||||||||||||
| 49 | # analyze the order_by, and see if it is done over a function/nonexistentcolumn | ||||||||||||||||||||||||||||||||||||||||||
| 50 | # if this is the case we will need to wrap a subquery since the result of RSC | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # *must* be a single column select | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 259 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | scalar grep | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 15 | { ! exists $colmap->{$_->[0]} } | |||||||||||||||||||||||||||||||||||||||||
| 55 | ( $rsrc->schema->storage->_extract_order_criteria ($orig_attrs->{order_by} ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | # nuke the prefetch before collapsing to sql | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | my $subq_rs = $rs->search_rs; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | $subq_rs->{attrs}{join} = $subq_rs->_merge_joinpref_attr( $subq_rs->{attrs}{join}, delete $subq_rs->{attrs}{prefetch} ); | |||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | $new_parent_rs = $subq_rs->as_subselect_rs; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 258 | ▶ | $new_parent_rs ||= $rs->search_rs; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$new_parent_rs ||= $rs->search_rs
MC/DC0%0/2
$new_parent_rs ||= $rs->search_rs
$new_parent_rs
$rs->search_rs
Truth table66%2/3
A ||= B
A= $new_parent_rsB= $rs->search_rs
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 258 | ▶ | my $new_attrs = $new_parent_rs->{attrs} ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$new_parent_rs->{"attrs"} ||= {}
MC/DC0%0/1
$new_parent_rs->{"attrs"} ||= {}
$new_parent_rs->{"attrs"}
Truth table50%1/2
A
A= $new_parent_rs->{"attrs"}
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | # prefetch causes additional columns to be fetched, but we can not just make a new | ||||||||||||||||||||||||||||||||||||||||||
| 67 | # rs via the _resolved_attrs trick - we need to retain the separation between | ||||||||||||||||||||||||||||||||||||||||||
| 68 | # +select/+as and select/as. At the same time we want to preserve any joins that the | ||||||||||||||||||||||||||||||||||||||||||
| 69 | # prefetch would otherwise generate. | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 258 | $new_attrs->{join} = $rs->_merge_joinpref_attr( $new_attrs->{join}, delete $new_attrs->{prefetch} ); | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | # {collapse} would mean a has_many join was injected, which in turn means | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # we need to group *IF WE CAN* (only if the column in question is unique) | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 258 | ▶ | if (!$orig_attrs->{group_by} && $orig_attrs->{collapse}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $orig_attrs->{"group_by"} and $orig_attrs->{"collapse"}
MC/DC0%0/2
not $orig_attrs->{"group_by"} and $orig_attrs->{"collapse"}
not $orig_attrs->{"group_by"}
$orig_attrs->{"collapse"}
Truth table66%2/3
not(A) and B
A= not $orig_attrs->{"group_by"}B= $orig_attrs->{"collapse"}
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ($colmap->{$select} and $rsrc->_identifying_column_set([$colmap->{$select}])) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$colmap->{$select} and $rsrc->_identifying_column_set([$colmap->{$select}])
MC/DC0%0/2
$colmap->{$select} and $rsrc->_identifying_column_set([$colmap->{$select}])
$colmap->{$select}
$rsrc->_identifying_column_set([$colmap->{$select}])
Truth table0%0/3
A and B
A= $colmap->{$select}B= $rsrc->_identifying_column_set([$colmap->{$select}])
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $new_attrs->{group_by} = [ $select ]; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | delete @{$new_attrs}{qw(distinct _grouped_by_distinct)}; # it is ignored when group_by is present | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | carp ( | |||||||||||||||||||||||||||||||||||||||||
| 82 | "Attempting to retrieve non-unique column '$column' on a resultset containing " | ||||||||||||||||||||||||||||||||||||||||||
| 83 | . 'one-to-many joins will return duplicate results.' | ||||||||||||||||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 258 | ▶ | return bless { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | _select => $select, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | _as => $column, | ||||||||||||||||||||||||||||||||||||||||||
| 91 | _parent_resultset => $new_parent_rs, | ||||||||||||||||||||||||||||||||||||||||||
| 92 | # A column resultset built from a context-bound resultset inherits the | ||||||||||||||||||||||||||||||||||||||||||
| 93 | # pinned async context, so $rs->with_context($ctx)->get_column($c)->all_async | ||||||||||||||||||||||||||||||||||||||||||
| 94 | # fetches on the pinned connection instead of the pool. | ||||||||||||||||||||||||||||||||||||||||||
| 95 | ( $rs->_async_context ? ( _async_context => $rs->_async_context ) : () ), | ||||||||||||||||||||||||||||||||||||||||||
| 96 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 27 | ▶ | sub as_query { return shift->_resultset->as_query(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_query: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 138 | ▶ | sub next { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 138 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | # using cursor so we don't inflate anything | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 138 | my ($row) = $self->_resultset->cursor->next; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 135 | return $row; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 6 | ▶ | sub all { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | # using cursor so we don't inflate anything | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 6 | return map { $_->[0] } $self->_resultset->cursor->all; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub reset { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $self->_resultset->cursor->reset; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub first { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | # using cursor so we don't inflate anything | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $self->_resultset->cursor->reset; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my ($row) = $self->_resultset->cursor->next; | |||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | return $row; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 3 | ▶ | sub single { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
single: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 3 | my $attrs = $self->_resultset->_resolved_attrs; | |||||||||||||||||||||||||||||||||||||||||
| 148 | my ($row) = $self->_resultset->result_source->storage->select_single( | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 3 | $attrs->{from}, $attrs->{select}, $attrs->{where}, $attrs | |||||||||||||||||||||||||||||||||||||||||
| 150 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 3 | return $row; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 16 | ▶ | sub single_async { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
single_async: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | return $self->_rsc_run_async('single', | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 11 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 11 | my ($backend, $fc) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 11 | my $attrs = $self->_resultset->_resolved_attrs; | |||||||||||||||||||||||||||||||||||||||||
| 165 | return $backend->select_single_async( | ||||||||||||||||||||||||||||||||||||||||||
| 166 | $attrs->{from}, $attrs->{select}, $attrs->{where}, $attrs, | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 11 | ▶ | )->then(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 11 | my ($raw_row) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 11 | ▶ | return (defined $raw_row && ref $raw_row eq 'ARRAY') ? $raw_row->[0] : $raw_row; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $raw_row and ref $raw_row eq "ARRAY"
MC/DC50%1/2
defined $raw_row and ref $raw_row eq "ARRAY"
defined $raw_row
ref $raw_row eq "ARRAY"
Truth table66%2/3
A and B
A= defined $raw_rowB= ref $raw_row eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 11 | }); | |||||||||||||||||||||||||||||||||||||||||
| 171 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | sub { $self->single }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 16 | ); | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 10 | ▶ | sub all_async { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all_async: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | return $self->_rsc_run_async('all', | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 6 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 6 | my ($backend, $fc) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 6 | my $attrs = $self->_resultset->_resolved_attrs; | |||||||||||||||||||||||||||||||||||||||||
| 186 | return $backend->select_async( | ||||||||||||||||||||||||||||||||||||||||||
| 187 | $attrs->{from}, $attrs->{select}, $attrs->{where}, $attrs, | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 6 | ▶ | )->then(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 6 | my @raw = @_; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 6 | return $fc->done( map { $_->[0] } @raw ); | |||||||||||||||||||||||||||||||||||||||||
| 191 | 6 | }); | |||||||||||||||||||||||||||||||||||||||||
| 192 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | ▶ | sub { $self->all }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 5 | ▶ | sub min { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
min: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 5 | return shift->func('MIN'); | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | sub min_rs { return shift->func_rs('MIN') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
min_rs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 5 | ▶ | sub min_async { return shift->_run_func_async('MIN', 'min') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
min_async: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 5 | ▶ | sub max { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 5 | return shift->func('MAX'); | |||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 8 | ▶ | sub max_rs { return shift->func_rs('MAX') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max_rs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 7 | ▶ | sub max_async { return shift->_run_func_async('MAX', 'max') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max_async: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 3 | ▶ | sub sum { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sum: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 3 | return shift->func('SUM'); | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | sub sum_rs { return shift->func_rs('SUM') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sum_rs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 4 | ▶ | sub sum_async { return shift->_run_func_async('SUM', 'sum') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sum_async: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 33 | ▶ | sub func { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
func: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 33 | my ($self,$function) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 33 | assert_function_name($function, "->func"); | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | # ADR 0042: func() used to return one value per row in list context. | ||||||||||||||||||||||||||||||||||||||||||
| 244 | # It now always returns the single scalar and refuses list context. | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 22 | ▶ | assert_no_list_context('->func') if wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 19 | my $cursor = $self->func_rs($function)->cursor; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 19 | return ( $cursor->next )[ 0 ]; | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 59 | ▶ | sub func_rs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
func_rs: called CC=2 SCAR=7.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 59 | my ($self,$function) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 59 | assert_function_name($function, "->func_rs"); | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 48 | my $rs = $self->{_parent_resultset}; | |||||||||||||||||||||||||||||||||||||||||
| 259 | 48 | my $select = $self->{_select}; | |||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | # wrap a grouped rs | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 48 | ▶ | if ($rs->_resolved_attrs->{group_by}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $select = $self->{_as}; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | $rs = $rs->as_subselect_rs; | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | $rs->search( undef, { | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 48 | columns => { $self->{_as} => { $function => $select } } | |||||||||||||||||||||||||||||||||||||||||
| 269 | } ); | ||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 4 | ▶ | sub func_async { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
func_async: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 4 | my ($self, $function) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 4 | return $self->_run_func_async($function, 'func'); | |||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | # Shared by min_async/max_async/sum_async/func_async: builds the resultset | ||||||||||||||||||||||||||||||||||||||||||
| 280 | # func_rs($function) would query and fetches its one aggregate row through | ||||||||||||||||||||||||||||||||||||||||||
| 281 | # select_single_async, bypassing the cursor -- the same shape single_async | ||||||||||||||||||||||||||||||||||||||||||
| 282 | # uses, and the async equivalent of func()'s own scalar-context | ||||||||||||||||||||||||||||||||||||||||||
| 283 | # ($cursor->next)[0] return. | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 20 | ▶ | sub _run_func_async { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run_func_async: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 20 | my ($self, $function, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | return $self->_rsc_run_async($name, | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 14 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 14 | my ($backend, $fc) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 14 | my $attrs = $self->func_rs($function)->_resolved_attrs; | |||||||||||||||||||||||||||||||||||||||||
| 292 | return $backend->select_single_async( | ||||||||||||||||||||||||||||||||||||||||||
| 293 | $attrs->{from}, $attrs->{select}, $attrs->{where}, $attrs, | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 14 | ▶ | )->then(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 14 | my ($raw_row) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 14 | ▶ | return (defined $raw_row && ref $raw_row eq 'ARRAY') ? $raw_row->[0] : $raw_row; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $raw_row and ref $raw_row eq "ARRAY"
MC/DC50%1/2
defined $raw_row and ref $raw_row eq "ARRAY"
defined $raw_row
ref $raw_row eq "ARRAY"
Truth table66%2/3
A and B
A= defined $raw_rowB= ref $raw_row eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 14 | }); | |||||||||||||||||||||||||||||||||||||||||
| 298 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 299 | # scalar: _rsc_run_async's sync fallback runs its closure in list | ||||||||||||||||||||||||||||||||||||||||||
| 300 | # context (my @r = eval { ... }), and func() now refuses list context | ||||||||||||||||||||||||||||||||||||||||||
| 301 | # outright (ADR 0042) -- force scalar so the immediate mode keeps working. | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | ▶ | sub { scalar $self->func($function) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | # ResultSetColumn-level mirror of DBIO::ResultSet::_rs_run_async / | ||||||||||||||||||||||||||||||||||||||||||
| 307 | # DBIO::Row::_row_run_async (ADR 0030/0031), one tier down: route to a live | ||||||||||||||||||||||||||||||||||||||||||
| 308 | # embedded backend, degrade synchronously in the 'immediate' mode, or croak on | ||||||||||||||||||||||||||||||||||||||||||
| 309 | # a sync instance. RSC has no ResultSet of its own to delegate the dispatch to | ||||||||||||||||||||||||||||||||||||||||||
| 310 | # (it wraps one, via _resultset/_parent_resultset), so it gets its own copy of | ||||||||||||||||||||||||||||||||||||||||||
| 311 | # the three-way contract, exactly as Row does. | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 46 | ▶ | sub _rsc_run_async { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rsc_run_async: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 46 | my ($self, $name, $backend_build, $sync_run) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 46 | my $storage = $self->_resultset->result_source->storage; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 46 | my $fc = $storage->future_class; | |||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | # A pinned context inherited from a context-bound resultset (get_column | ||||||||||||||||||||||||||||||||||||||||||
| 319 | # on a bound RS) or bound directly wins over the pooled backend, so this | ||||||||||||||||||||||||||||||||||||||||||
| 320 | # column's single_async/all_async/func_async runs on the pinned connection. | ||||||||||||||||||||||||||||||||||||||||||
| 321 | # No context => historical path below, unchanged. | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 46 | ▶ | if (my $ctx = $self->_async_context) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 16 | $self->_assert_async_context_active($ctx, $name); | |||||||||||||||||||||||||||||||||||||||||
| 324 | 10 | $storage->_assert_async_context_owner($ctx); | |||||||||||||||||||||||||||||||||||||||||
| 325 | 9 | return $backend_build->($ctx, $fc); | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 30 | ▶ | if (my $backend = $storage->_async_storage) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | # A Future derived from the storage's own is reported to the pool (k397). | ||||||||||||||||||||||||||||||||||||||||||
| 330 | return $backend->can('_note_pooled_derivation') | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 22 | ▶ | ? $backend->_note_pooled_derivation(sub { $backend_build->($backend, $fc) }) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 22 | ▶ | : $backend_build->($backend, $fc); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | $self->throw_exception( | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 8 | ▶ | "not an async connection -- connect with { async => ... } to use ${name}_async" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | ) unless defined $storage->_async_mode; | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 2 | my @r = eval { $sync_run->() }; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 2 | ▶ | return $@ ? $fc->fail($@) : $fc->done(@r); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | # ADR 0045: the pinned async context bound to this column resultset (undef when | ||||||||||||||||||||||||||||||||||||||||||
| 344 | # unbound). A column resultset produced by ->get_column on a context-bound | ||||||||||||||||||||||||||||||||||||||||||
| 345 | # ResultSet inherits its context (see new()), so a bound $rs->get_column($c) | ||||||||||||||||||||||||||||||||||||||||||
| 346 | # still batches/pins its aggregate fetch. Mirrors the same-named helpers on | ||||||||||||||||||||||||||||||||||||||||||
| 347 | # DBIO::ResultSet / DBIO::Row. | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 46 | ▶ | sub _async_context { $_[0]->{_async_context} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_async_context: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 14 | ▶ | sub with_context { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
with_context: called CC=4 SCAR=14.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 14 | my ($self, $ctx) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 14 | ▶ | $self->throw_exception( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $ctx and builtin::blessed($ctx) and $ctx->can("select_async")
defined $ctx and builtin::blessed($ctx)
MC/DC0%0/3
defined $ctx and builtin::blessed($ctx) and $ctx->can("select_async")
defined $ctx
builtin::blessed($ctx)
$ctx->can("select_async")
Truth table25%1/4
A and B and C
A= defined $ctxB= builtin::blessed($ctx)C= $ctx->can("select_async")
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 'with_context requires an async context object (the one passed to a ' | ||||||||||||||||||||||||||||||||||||||||||
| 355 | . 'txn_do_async / pipeline coderef)' | ||||||||||||||||||||||||||||||||||||||||||
| 356 | ) unless defined $ctx and blessed($ctx) and $ctx->can('select_async'); | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 14 | my $storage = $self->{_parent_resultset}->result_source->storage; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 14 | $storage->_assert_async_context_owner($ctx); | |||||||||||||||||||||||||||||||||||||||||
| 359 | 12 | my $clone = bless { %$self }, ref $self; | |||||||||||||||||||||||||||||||||||||||||
| 360 | 12 | $clone->{_async_context} = $ctx; | |||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | # ADR 0045 / karr k325: func_rs (and min_rs / max_rs / sum_rs) and _resultset | ||||||||||||||||||||||||||||||||||||||||||
| 363 | # are derived from the parent resultset, so the clone gets a bound clone of | ||||||||||||||||||||||||||||||||||||||||||
| 364 | # it -- a column bound here then looks the same as one that get_column made | ||||||||||||||||||||||||||||||||||||||||||
| 365 | # from a bound resultset. The inner resultset is forgotten and built again | ||||||||||||||||||||||||||||||||||||||||||
| 366 | # from the bound parent on first use. The column this was cloned from keeps | ||||||||||||||||||||||||||||||||||||||||||
| 367 | # its own parent and stays unbound. | ||||||||||||||||||||||||||||||||||||||||||
| 368 | 12 | $clone->{_parent_resultset} = $self->{_parent_resultset}->with_context($ctx); | |||||||||||||||||||||||||||||||||||||||||
| 369 | 12 | delete $clone->{_resultset}; | |||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 12 | return $clone; | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 16 | ▶ | sub _assert_async_context_active { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_async_context_active: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 16 | my ($self, $ctx, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 376 | 16 | ▶ | return if !$ctx->can('_context_active') || $ctx->_context_active; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $ctx->can("_context_active") or $ctx->_context_active
MC/DC50%1/2
not $ctx->can("_context_active") or $ctx->_context_active
not $ctx->can("_context_active")
$ctx->_context_active
Truth table66%2/3
not(A) or B
A= not $ctx->can("_context_active")B= $ctx->_context_active
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 6 | $self->throw_exception( | |||||||||||||||||||||||||||||||||||||||||
| 378 | "the async context bound to this result is no longer active; ${name}_async " | ||||||||||||||||||||||||||||||||||||||||||
| 379 | . "cannot be routed onto it. Pipeline contexts stop accepting work when their " | ||||||||||||||||||||||||||||||||||||||||||
| 380 | . "synchronous batch coderef returns; transaction contexts stop on their " | ||||||||||||||||||||||||||||||||||||||||||
| 381 | . "terminal BEGIN / COMMIT / ROLLBACK path. Issue the async work while its " | ||||||||||||||||||||||||||||||||||||||||||
| 382 | . "owning context remains active, not from a column held past it." | ||||||||||||||||||||||||||||||||||||||||||
| 383 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 12 | ▶ | sub throw_exception { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
throw_exception: called CC=3 SCAR=13.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 12 | ▶ | if (ref $self && $self->{_parent_resultset}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $self and $self->{"_parent_resultset"}
MC/DC0%0/2
ref $self and $self->{"_parent_resultset"}
ref $self
$self->{"_parent_resultset"}
Truth table33%1/3
A and B
A= ref $selfB= $self->{"_parent_resultset"}
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 12 | $self->{_parent_resultset}->throw_exception(@_); | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | DBIO::Exception->throw(@_); | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | # _resultset | ||||||||||||||||||||||||||||||||||||||||||
| 400 | # | ||||||||||||||||||||||||||||||||||||||||||
| 401 | # Arguments: none | ||||||||||||||||||||||||||||||||||||||||||
| 402 | # | ||||||||||||||||||||||||||||||||||||||||||
| 403 | # Return Value: $resultset | ||||||||||||||||||||||||||||||||||||||||||
| 404 | # | ||||||||||||||||||||||||||||||||||||||||||
| 405 | # $year_col->_resultset->next | ||||||||||||||||||||||||||||||||||||||||||
| 406 | # | ||||||||||||||||||||||||||||||||||||||||||
| 407 | # Returns the underlying resultset. Creates it from the parent resultset if | ||||||||||||||||||||||||||||||||||||||||||
| 408 | # necessary. | ||||||||||||||||||||||||||||||||||||||||||
| 409 | # | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 265 | ▶ | sub _resultset { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resultset: called CC=4 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | 265 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | 265 | ▶ | return $self->{_resultset} ||= do { | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"_resultset"} ||= do {
my $select = $self->{"_select"};
if ($self->{"_parent_resultset"}{"attrs"}{"distinct"}) {
my $alias = $self->{"_parent_resultset"}->current_source_alias;
my $rsrc = $self->{"_parent_resultset"}->result_source;
my(%cols) = map({$_, 1, "$alias.$_", 1;} $rsrc->columns);
unless ($cols{$select}) {
carp_unique('Use of distinct => 1 while selecting anything other than a column declared on the primary ResultSource is deprecated (you selected ' . qq['$self->{"_as"}') - please supply an explicit group_by instead]);
$select = \[$rsrc->storage->sql_maker->_recurse_fields($select)];
};
};
$self->{"_parent_resultset"}->search(undef, {"columns", {$self->{"_as"}, $select}})
}
MC/DC0%0/2
$self->{"_resultset"} ||= do {
my $select = $self->{"_select"};
if ($self->{"_parent_resultset"}{"attrs"}{"distinct"}) {
my $alias = $self->{"_parent_resultset"}->current_source_alias;
my $rsrc = $self->{"_parent_resultset"}->result_source;
my(%cols) = map({$_, 1, "$alias.$_", 1;} $rsrc->columns);
unless ($cols{$select}) {
carp_unique('Use of distinct => 1 while selecting anything other than a column declared on the primary ResultSource is deprecated (you selected ' . qq['$self->{"_as"}') - please supply an explicit group_by instead]);
$select = \[$rsrc->storage->sql_maker->_recurse_fields($select)];
};
};
$self->{"_parent_resultset"}->search(undef, {"columns", {$self->{"_as"}, $select}})
}
$self->{"_resultset"}
do {
my $select = $self->{"_select"};
if ($self->{"_parent_resultset"}{"attrs"}{"distinct"}) {
my $alias = $self->{"_parent_resultset"}->current_source_alias;
my $rsrc = $self->{"_parent_resultset"}->result_source;
my(%cols) = map({$_, 1, "$alias.$_", 1;} $rsrc->columns);
unless ($cols{$select}) {
carp_unique('Use of distinct => 1 while selecting anything other than a column declared on the primary ResultSource is deprecated (you selected ' . qq['$self->{"_as"}') - please supply an explicit group_by instead]);
$select = \[$rsrc->storage->sql_maker->_recurse_fields($select)];
};
};
$self->{"_parent_resultset"}->search(undef, {"columns", {$self->{"_as"}, $select}})
}
Truth table66%2/3
A ||= B
A= $self->{"_resultset"}B= do {
my $select = $self->{"_select"};
if ($self->{"_parent_resultset"}{"attrs"}{"distinct"}) {
my $alias = $self->{"_parent_resultset"}->current_source_alias;
my $rsrc = $self->{"_parent_resultset"}->result_source;
my(%cols) = map({$_, 1, "$alias.$_", 1;} $rsrc->columns);
unless ($cols{$select}) {
carp_unique('Use of distinct => 1 while selecting anything other than a column declared on the primary ResultSource is deprecated (you selected ' . qq['$self->{"_as"}') - please supply an explicit group_by instead]);
$select = \[$rsrc->storage->sql_maker->_recurse_fields($select)];
};
};
$self->{"_parent_resultset"}->search(undef, {"columns", {$self->{"_as"}, $select}})
}
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 228 | my $select = $self->{_select}; | |||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | 228 | ▶ | if ($self->{_parent_resultset}{attrs}{distinct}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | my $alias = $self->{_parent_resultset}->current_source_alias; | |||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | my $rsrc = $self->{_parent_resultset}->result_source; | |||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | my %cols = map { $_ => 1, "$alias.$_" => 1 } $rsrc->columns; | |||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | unless( $cols{$select} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | carp_unique( | |||||||||||||||||||||||||||||||||||||||||
| 425 | 'Use of distinct => 1 while selecting anything other than a column ' | ||||||||||||||||||||||||||||||||||||||||||
| 426 | . 'declared on the primary ResultSource is deprecated (you selected ' | ||||||||||||||||||||||||||||||||||||||||||
| 427 | . "'$self->{_as}') - please supply an explicit group_by instead" | ||||||||||||||||||||||||||||||||||||||||||
| 428 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | # collapse the selector to a literal so that it survives the distinct parse | ||||||||||||||||||||||||||||||||||||||||||
| 431 | # if it turns out to be an aggregate - at least the user will get a proper exception | ||||||||||||||||||||||||||||||||||||||||||
| 432 | # instead of silent drop of the group_by altogether | ||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $select = \[ $rsrc->storage->sql_maker->_recurse_fields($select) ]; | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | $self->{_parent_resultset}->search(undef, { | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 228 | columns => { $self->{_as} => $select } | |||||||||||||||||||||||||||||||||||||||||
| 439 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 440 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | 379 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | __END__ | ||||||||||||||||||||||||||||||||||||||||||