DBIx/Class/ResultSource/RowParser.pm

filter: Statementstmt 100% 513 / 513 Branchbran 81.7% 67 / 82 Conditioncond 77.9% 60 / 77 MC/DCmcdc 52.3% 22 / 42 Subroutinesub 100% 171 / 171 Podpod n/a totaltotal 94.1% 833 / 885 CC 85 SCAR 28.8
CC
85
Cov
95%
_resolve_collapse
71.7
_resolve_prefetch
12.2
_mk_row_parser
8.0
CRAP 17.9
« DBIx/Class/Storage/DBI/Sybase/ASE/NoBindVars.pm ↑ Summary DBIx/Class/Storage/DBI/ODBC.pm »
1 package # hide from the pauses
2 DBIx::Class::ResultSource::RowParser;
3  
4 436 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 436 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 436 ▶use base 'DBIx::Class';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 419 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 419 ▶use DBIx::Class::ResultSource::RowParser::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 assemble_simple_parser
13 assemble_collapsing_parser
14 419 );
15  
16 419 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # Accepts one or more relationships for the current source and returns an
19 # array of column names for each of those relationships. Column names are
20 # prefixed relative to the current source, in accordance with where they appear
21 # in the supplied relationships.
22 966 ▶sub _resolve_prefetch {
Subroutine _resolve_prefetch: called CC=12 SCAR=25.0
23 966 my ($self, $pre, $alias, $alias_map, $order, $pref_path) = @_;
24 966 ▶ $pref_path ||= [];
Condition100%2/2
$pref_path ||= []
l!l
612352
MC/DC100%1/1
$pref_path ||= []
$pref_path
Truth table100%2/2
A
A= $pref_path
Aresult
11
00
25  
26 966 ▶ if (not defined $pre or not length $pre) {
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $pre && length $pre) { } 97 867 964
elsif (ref $pre eq 'ARRAY') { } 360 507 867
elsif (ref $pre eq 'HASH') { } 97 410 507
elsif (ref $pre) { } 0 410 410
Condition100%3/3
defined $pre && length $pre
!ll&&!rl&&r
4948867
MC/DC100%2/2
defined $pre && length $pre
defined $pre length $pre
Truth table100%3/3
A && B
A= defined $preB= length $pre
ABresult
0X0
100
111
27 99 return ();
28 }
29 elsif( ref $pre eq 'ARRAY' ) {
30 return
31 362 map { $self->_resolve_prefetch( $_, $alias, $alias_map, $order, [ @$pref_path ] ) }
32 @$pre;
33 }
34 elsif( ref $pre eq 'HASH' ) {
35 my @ret =
36 map {
37 99 $self->_resolve_prefetch($_, $alias, $alias_map, $order, [ @$pref_path ] ),
38 $self->related_source($_)->_resolve_prefetch(
39 98 $pre->{$_}, "${alias}.$_", $alias_map, $order, [ @$pref_path, $_] )
40 } keys %$pre;
41 99 return @ret;
42 }
43 elsif( ref $pre ) {
44 1 $self->throw_exception(
45 "don't know how to resolve prefetch reftype ".ref($pre));
46 }
47 else {
48 411 my $p = $alias_map;
49 411 $p = $p->{$_} for (@$pref_path, $pre);
50  
51 $self->throw_exception (
52 "Unable to resolve prefetch '$pre' - join alias map does not contain an entry for path: "
53 . join (' -> ', @$pref_path, $pre)
54 411 ▶ ) if (ref $p->{-join_aliases} ne 'ARRAY' or not @{$p->{-join_aliases}} );
Branch: 1 branch
BranchTrueFalseTotal
if ref $p->{"-join_aliases"} ne "ARRAY" or not @{$p->{"-join_aliases"};} 0 410 410
Condition33%1/3
ref $p->{"-join_aliases"} ne "ARRAY" or not @{$p->{"-join_aliases"};}
l!l&&r!l&&!r
00410
MC/DC0%0/2
ref $p->{"-join_aliases"} ne "ARRAY" or not @{$p->{"-join_aliases"};}
ref $p->{"-join_aliases"} ne "ARRAY" not @{$p->{"-join_aliases"};}
Truth table33%1/3
A or not(B)
A= ref $p->{"-join_aliases"} ne "ARRAY"B= not @{$p->{"-join_aliases"};}
ABresult
1X1
011
000
55  
56 411 my $as = shift @{$p->{-join_aliases}};
57  
58 411 my $rel_info = $self->relationship_info( $pre );
59 411 ▶ $self->throw_exception( $self->source_name . " has no such relationship '$pre'" )
Branch: 1 branch
BranchTrueFalseTotal
unless $rel_info 0 410 410
60 unless $rel_info;
61  
62 411 ▶ my $as_prefix = ($alias =~ /^.*?\.(.+)$/ ? $1.'.' : '');
Branch: 1 branch
BranchTrueFalseTotal
$alias =~ /^.*?\.(.+)$/ ? : 103 307 410
63  
64 411 return map { [ "${as}.$_", "${as_prefix}${pre}.$_", ] }
65 $self->related_source($pre)->columns;
66 }
67 }
68  
69 # Takes an arrayref of {as} dbic column aliases and the collapse and select
70 # attributes from the same $rs (the selector requirement is a temporary
71 # workaround... I hope), and returns a coderef capable of:
72 # my $me_pref_clps = $coderef->([$rs->cursor->next/all])
73 # Where the $me_pref_clps arrayref is the future argument to inflate_result()
74 #
75 # For an example of this coderef in action (and to see its guts) look at
76 # t/resultset/rowparser_internals.t
77 #
78 # This is a huge performance win, as we call the same code for every row
79 # returned from the db, thus avoiding repeated method lookups when traversing
80 # relationships
81 #
82 # Also since the coderef is completely stateless (the returned structure is
83 # always fresh on every new invocation) this is a very good opportunity for
84 # memoization if further speed improvements are needed
85 #
86 # The way we construct this coderef is somewhat fugly, although the result is
87 # really worth it. The final coderef does not perform any kind of recursion -
88 # the entire nested structure constructor is rolled out into a single scope.
89 #
90 # In any case - the output of this thing is meticulously micro-tested, so
91 # any sort of adjustment/rewrite should be relatively easy (fsvo relatively)
92 #
93 235 ▶sub _mk_row_parser {
Subroutine _mk_row_parser: called CC=8 SCAR=20.8
94 # $args and $attrs are separated to delineate what is core collapser stuff and
95 # what is dbic $rs specific
96 234 my ($self, $args, $attrs) = @_;
97  
98 die "HRI without pruning makes zero sense"
99 234 ▶ if ( $args->{hri_style} && ! $args->{prune_null_branches} );
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"hri_style"} and not $args->{"prune_null_branches"} 0 233 233
Condition66%2/3
$args->{"hri_style"} and not $args->{"prune_null_branches"}
!ll&&!rl&&r
179540
MC/DC0%0/2
$args->{"hri_style"} and not $args->{"prune_null_branches"}
$args->{"hri_style"} not $args->{"prune_null_branches"}
Truth table66%2/3
A and not(B)
A= $args->{"hri_style"}B= not $args->{"prune_null_branches"}
ABresult
0X0
100
111
100  
101 my %common = (
102 hri_style => $args->{hri_style},
103 prune_null_branches => $args->{prune_null_branches},
104 val_index => { map
105 2215 { $args->{inflate_map}[$_] => $_ }
106 234 ( 0 .. $#{$args->{inflate_map}} )
107 },
108 );
109  
110 234 my $check_null_columns;
111  
112 234 ▶ my $src = (! $args->{collapse} ) ? assemble_simple_parser(\%common) : do {
Branch: 1 branch
BranchTrueFalseTotal
!$args->{'collapse'} ? : 68 165 233
113 my $collapse_map = $self->_resolve_collapse ({
114 # FIXME
115 # only consider real columns (not functions) during collapse resolution
116 # this check shouldn't really be here, as fucktards are not supposed to
117 # alias random crap to existing column names anyway, but still - just in
118 # case
119 # FIXME !!!! - this does not yet deal with unbalanced selectors correctly
120 # (it is now trivial as the attrs specify where things go out of sync
121 # needs MOAR tests)
122 as => { map
123 1653 ▶ { ref $attrs->{select}[$common{val_index}{$_}] ? () : ( $_ => $common{val_index}{$_} ) }
Branch: 1 branch
BranchTrueFalseTotal
ref $attrs->{'select'}[$common{'val_index'}{$_}] ? : 14 1638 1652
124 166 keys %{$common{val_index}}
125 },
126 premultiplied => $args->{premultiplied},
127 166 });
128  
129 $check_null_columns = $collapse_map->{-identifying_columns}
130 166 ▶ if @{$collapse_map->{-identifying_columns}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$collapse_map->{"-identifying_columns"};} 152 13 165
131  
132 166 assemble_collapsing_parser({
133 %common,
134 collapse_map => $collapse_map,
135 });
136 };
137  
138 234 utf8::upgrade($src)
139 if DBIx::Class::_ENV_::STRESSTEST_UTF8_UPGRADE_GENERATED_COLLAPSER_SOURCE;
140  
141 return (
142 234 ▶ $args->{eval} ? ( eval "sub $src" || die $@ ) : $src,
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$args->{'eval'} ? : 223 10 233
Condition50%1/2
eval "sub $src" or die $@
l!l
2230
MC/DC0%0/1
eval "sub $src" or die $@
eval "sub $src"
Truth table50%1/2
A
A= eval "sub $src"
Aresult
11
00
143 $check_null_columns,
144 );
145 }
146  
147  
148 # Takes an arrayref selection list and generates a collapse-map representing
149 # row-object fold-points. Every relationship is assigned a set of unique,
150 # non-nullable columns (which may *not even be* from the same resultset)
151 # and the collapser will use this information to correctly distinguish
152 # data of individual to-be-row-objects. See t/resultset/rowparser_internals.t
153 # for extensive RV examples
154 562 ▶sub _resolve_collapse {
Subroutine _resolve_collapse: called CC=67 SCAR=42.7
155 561 my ($self, $args, $common_args) = @_;
156  
157 # for comprehensible error messages put ourselves at the head of the relationship chain
158 561 ▶ $args->{_rel_chain} ||= [ $self->source_name ];
Condition100%2/2
$args->{"_rel_chain"} ||= [$self->source_name]
l!l
392168
MC/DC100%1/1
$args->{"_rel_chain"} ||= [$self->source_name]
$args->{"_rel_chain"}
Truth table100%2/2
A
A= $args->{"_rel_chain"}
Aresult
11
00
159  
160 # record top-level fully-qualified column index, signify toplevelness
161 561 ▶ unless ($common_args->{_as_fq_idx}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($common_args->{"_as_fq_idx"}) 168 392 560
162 169 $common_args->{_as_fq_idx} = { %{$args->{as}} };
163 169 $args->{_is_top_level} = 1;
164 };
165  
166 561 my ($my_cols, $rel_cols);
167 561 for (keys %{$args->{as}}) {
168 3675 ▶ if ($_ =~ /^ ([^\.]+) \. (.+) /x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^ ([^\.]+) \. (.+) /x) { } 1952 1722 3674
169 1953 $rel_cols->{$1}{$2} = 1;
170 }
171 else {
172 1723 $my_cols->{$_} = {}; # important for ||='s below
173 }
174 }
175  
176 561 my $relinfo;
177 # run through relationships, collect metadata
178 561 for my $rel (keys %$rel_cols) {
179 379 my $inf = $self->relationship_info ($rel);
180  
181 $relinfo->{$rel} = {
182 is_single => ( $inf->{attrs}{accessor} && $inf->{attrs}{accessor} ne 'multi' ),
183 379 ▶ is_inner => ( ( $inf->{attrs}{join_type} || '' ) !~ /^left/i),
Condition80%4/5
$inf->{'attrs'}{'accessor'} && $inf->{'attrs'}{'accessor'} ne 'multi'
!ll&&!rl&&r
0223155
$inf->{'attrs'}{'join_type'} || ''
l!l
258120
MC/DC50%1/2
$inf->{'attrs'}{'accessor'} && $inf->{'attrs'}{'accessor'} ne 'multi'
$inf->{'attrs'}{'accessor'} $inf->{'attrs'}{'accessor'} ne 'multi'
MC/DC100%1/1
$inf->{'attrs'}{'join_type'} || ''
$inf->{'attrs'}{'join_type'}
Truth table66%2/3
A && B
A= $inf->{'attrs'}{'accessor'}B= $inf->{'attrs'}{'accessor'} ne 'multi'
ABresult
0X0
100
111
Truth table100%2/2
A
A= $inf->{'attrs'}{'join_type'}
Aresult
11
00
184 rsrc => $self->related_source($rel),
185 };
186  
187 # FIME - need to use _resolve_cond here instead
188 379 my $cond = $inf->{cond};
189  
190 379 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cond eq "HASH" and keys %$cond and not grep({not $_ =~ /^foreign\./;} keys %$cond) and not grep({not $_ =~ /^self\./;} values %$cond)) 377 1 378
Condition66%6/9
ref $cond eq "HASH" and keys %$cond and not grep({not $_ =~ /^foreign\./;} keys %$cond) and not grep({not $_ =~ /^self\./;} values %$cond)
!ll&&!rl&&r
10377
ref $cond eq "HASH" and keys %$cond and not grep({not $_ =~ /^foreign\./;} keys %$cond)
!ll&&!rl&&r
10377
ref $cond eq "HASH" and keys %$cond
!ll&&!rl&&r
10377
MC/DC25%1/4
ref $cond eq "HASH" and keys %$cond and not grep({not $_ =~ /^foreign\./;} keys %$cond) and not grep({not $_ =~ /^self\./;} values %$cond)
ref $cond eq "HASH" keys %$cond not grep({not $_ =~ /^foreign\./;} keys %$cond) not grep({not $_ =~ /^self\./;} values %$cond)
Truth table40%2/5
A and B and not(C) and not(D)
A= ref $cond eq "HASH"B= keys %$condC= not grep({not $_ =~ /^foreign\./;} keys %$cond)D= not grep({not $_ =~ /^self\./;} values %$cond)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
191 ref $cond eq 'HASH'
192 and
193 keys %$cond
194 and
195 378 ! grep { $_ !~ /^foreign\./ } (keys %$cond)
196 and
197 378 ! grep { $_ !~ /^self\./ } (values %$cond)
198 ) {
199 378 for my $f (keys %$cond) {
200 378 my $s = $cond->{$f};
201 378 $_ =~ s/^ (?: foreign | self ) \.//x for ($f, $s);
202 378 $relinfo->{$rel}{fk_map}{$s} = $f;
203 }
204 }
205 }
206  
207 # inject non-left fk-bridges from *INNER-JOINED* children (if any)
208 561 for my $rel (grep { $relinfo->{$_}{is_inner} } keys %$relinfo) {
209 124 my $ri = $relinfo->{$rel};
210 124 for (keys %{$ri->{fk_map}} ) {
211 # need to know source from *our* pov, hence $rel.col
212 $my_cols->{$_} ||= { via_fk => "$rel.$ri->{fk_map}{$_}" }
213 124 ▶ if defined $rel_cols->{$rel}{$ri->{fk_map}{$_}} # in fact selected
Branch: 1 branch
BranchTrueFalseTotal
if defined $rel_cols->{$rel}{$ri->{"fk_map"}{$_}} 89 34 123
Condition100%2/2
$my_cols->{$_} ||= {"via_fk", qq[$rel.$ri->{"fk_map"}{$_}]}
l!l
5336
MC/DC100%1/1
$my_cols->{$_} ||= {"via_fk", qq[$rel.$ri->{"fk_map"}{$_}]}
$my_cols->{$_}
Truth table100%2/2
A
A= $my_cols->{$_}
Aresult
11
00
214 }
215 }
216  
217 # if the parent is already defined *AND* we have an inner reverse relationship
218 # (i.e. do not exist without it) , assume all of its related FKs are selected
219 # (even if they in fact are NOT in the select list). Keep a record of what we
220 # assumed, and if any such phantom-column becomes part of our own collapser,
221 # throw everything assumed-from-parent away and replace with the collapser of
222 # the parent (whatever it may be)
223 561 my $assumed_from_parent;
224 561 ▶ if ( ! $args->{_parent_info}{underdefined} and ! $args->{_parent_info}{rev_rel_is_optional} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"_parent_info"}{"underdefined"} or $args->{"_parent_info"}{"rev_rel_is_optional"}) 394 166 560
Condition100%3/3
$args->{"_parent_info"}{"underdefined"} or $args->{"_parent_info"}{"rev_rel_is_optional"}
l!l&&r!l&&!r
49117394
MC/DC100%2/2
$args->{"_parent_info"}{"underdefined"} or $args->{"_parent_info"}{"rev_rel_is_optional"}
$args->{"_parent_info"}{"underdefined"} $args->{"_parent_info"}{"rev_rel_is_optional"}
Truth table100%3/3
A or B
A= $args->{"_parent_info"}{"underdefined"}B= $args->{"_parent_info"}{"rev_rel_is_optional"}
ABresult
1X1
011
000
225 395 ▶ for my $col ( values %{$args->{_parent_info}{rel_condition} || {}} ) {
Condition100%2/2
$args->{'_parent_info'}{'rel_condition'} || {}
l!l
226168
MC/DC100%1/1
$args->{'_parent_info'}{'rel_condition'} || {}
$args->{'_parent_info'}{'rel_condition'}
Truth table100%2/2
A
A= $args->{'_parent_info'}{'rel_condition'}
Aresult
11
00
226 227 ▶ next if exists $my_cols->{$col};
Branch: 1 branch
BranchTrueFalseTotal
if exists $my_cols->{$col} 173 53 226
227 54 $my_cols->{$col} = { via_collapse => $args->{_parent_info}{collapse_on_idcols} };
228 54 $assumed_from_parent->{columns}{$col}++;
229 }
230 }
231  
232 # get colinfo for everything
233 561 ▶ if ($my_cols) {
Branch: 1 branch
BranchTrueFalseTotal
if ($my_cols) 540 20 560
234 541 my $ci = $self->columns_info;
235 541 $my_cols->{$_}{colinfo} = $ci->{$_} for keys %$my_cols;
236 }
237  
238 561 my $collapse_map;
239  
240 # first try to reuse the parent's collapser (i.e. reuse collapser over 1:1)
241 # (makes for a leaner coderef later)
242 561 ▶ unless ($collapse_map->{-identifying_columns}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($collapse_map->{"-identifying_columns"}) 560 0 560
243 $collapse_map->{-identifying_columns} = $args->{_parent_info}{collapse_on_idcols}
244 561 ▶ if $args->{_parent_info}{collapser_reusable};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"_parent_info"}{"collapser_reusable"} 97 463 560
245 }
246  
247 # Still don't know how to collapse - try to resolve based on our columns (plus already inserted FK bridges)
248 561 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $collapse_map->{"-identifying_columns"} and $my_cols and my $idset = $self->_identifying_column_set({map({$_, $my_cols->{$_}{"colinfo"};} keys %$my_cols)})) 422 138 560
Condition100%6/6
not $collapse_map->{"-identifying_columns"} and $my_cols and my $idset = $self->_identifying_column_set({map({$_, $my_cols->{$_}{"colinfo"};} keys %$my_cols)})
!ll&&!rl&&r
11424422
not $collapse_map->{"-identifying_columns"} and $my_cols
!ll&&!rl&&r
9717446
MC/DC100%3/3
not $collapse_map->{"-identifying_columns"} and $my_cols and my $idset = $self->_identifying_column_set({map({$_, $my_cols->{$_}{"colinfo"};} keys %$my_cols)})
not $collapse_map->{"-identifying_columns"} $my_cols my $idset = $self->_identifying_column_set({map({$_, $my_cols->{$_}{"colinfo"};} keys %$my_cols)})
Truth table100%4/4
not(A) and B and C
A= not $collapse_map->{"-identifying_columns"}B= $my_colsC= my $idset = $self->_identifying_column_set({map({$_, $my_cols->{$_}{"colinfo"};} keys %$my_cols)})
ABCresult
0XX0
10X0
1100
1111
249 ! $collapse_map->{-identifying_columns}
250 and
251 $my_cols
252 and
253 1541 my $idset = $self->_identifying_column_set ({map { $_ => $my_cols->{$_}{colinfo} } keys %$my_cols})
254 ) {
255 # see if the resulting collapser relies on any implied columns,
256 # and fix stuff up if this is the case
257 423 my @reduced_set = grep { ! $assumed_from_parent->{columns}{$_} } @$idset;
258  
259 $collapse_map->{-identifying_columns} = [ __unique_numlist(
260 423 ▶ @{ $args->{_parent_info}{collapse_on_idcols}||[] },
Condition100%2/2
$args->{'_parent_info'}{'collapse_on_idcols'} || []
l!l
237185
MC/DC100%1/1
$args->{'_parent_info'}{'collapse_on_idcols'} || []
$args->{'_parent_info'}{'collapse_on_idcols'}
Truth table100%2/2
A
A= $args->{'_parent_info'}{'collapse_on_idcols'}
Aresult
11
00
261  
262 (map
263 {
264 423 my $fqc = join ('.',
265 496 ▶ @{$args->{_rel_chain}}[1 .. $#{$args->{_rel_chain}}],
Condition66%2/3
$my_cols->{$_}{'via_fk'} || $_
l!l&&r!l&&!r
34920
MC/DC0%0/2
$my_cols->{$_}{'via_fk'} || $_
$my_cols->{$_}{'via_fk'} $_
Truth table66%2/3
A || B
A= $my_cols->{$_}{'via_fk'}B= $_
ABresult
1X1
011
000
266 496 ( $my_cols->{$_}{via_fk} || $_ ),
267 );
268  
269 496 $common_args->{_as_fq_idx}->{$fqc};
270 }
271 @reduced_set
272 ),
273 )];
274 }
275  
276 # Stil don't know how to collapse - keep descending down 1:1 chains - if
277 # a related non-LEFT 1:1 is resolvable - its condition will collapse us
278 # too
279 561 ▶ unless ($collapse_map->{-identifying_columns}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($collapse_map->{"-identifying_columns"}) 41 519 560
280 42 my @candidates;
281  
282 42 for my $rel (keys %$relinfo) {
283 53 ▶ next unless ($relinfo->{$rel}{is_single} && $relinfo->{$rel}{is_inner});
Branch: 1 branch
BranchTrueFalseTotal
unless $relinfo->{$rel}{"is_single"} and $relinfo->{$rel}{"is_inner"} 25 27 52
Condition100%3/3
$relinfo->{$rel}{"is_single"} and $relinfo->{$rel}{"is_inner"}
!ll&&!rl&&r
17827
MC/DC100%2/2
$relinfo->{$rel}{"is_single"} and $relinfo->{$rel}{"is_inner"}
$relinfo->{$rel}{"is_single"} $relinfo->{$rel}{"is_inner"}
Truth table100%3/3
A and B
A= $relinfo->{$rel}{"is_single"}B= $relinfo->{$rel}{"is_inner"}
ABresult
0X0
100
111
284  
285 28 ▶ if ( my $rel_collapse = $relinfo->{$rel}{rsrc}->_resolve_collapse ({
Branch: 1 branch
BranchTrueFalseTotal
if (my $rel_collapse = $relinfo->{$rel}{"rsrc"}->_resolve_collapse({"as", $rel_cols->{$rel}, "_rel_chain", [@{$args->{"_rel_chain"};}, $rel], "_parent_info", {"underdefined", 1}}, $common_args)) 27 0 27
286 as => $rel_cols->{$rel},
287 28 _rel_chain => [ @{$args->{_rel_chain}}, $rel ],
288 _parent_info => { underdefined => 1 },
289 }, $common_args)) {
290 28 push @candidates, $rel_collapse->{-identifying_columns};
291 }
292 }
293  
294 # get the set with least amount of columns
295 # FIXME - maybe need to implement a data type order as well (i.e. prefer several ints
296 # to a single varchar)
297 42 ▶ if (@candidates) {
Branch: 1 branch
BranchTrueFalseTotal
if (@candidates) 27 14 41
298 28 ($collapse_map->{-identifying_columns}) = sort { scalar @$a <=> scalar @$b } (@candidates);
299 }
300 }
301  
302 # Stil don't know how to collapse, and we are the root node. Last ditch
303 # effort in case we are *NOT* premultiplied.
304 # Run through *each multi* all the way down, left or not, and all
305 # *left* singles (a single may become a multi underneath) . When everything
306 # gets back see if all the rels link to us definitively. If this is the
307 # case we are good - either one of them will define us, or if all are NULLs
308 # we know we are "unique" due to the "non-premultiplied" check
309 561 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $collapse_map->{"-identifying_columns"} || $args->{"premultiplied"} and $args->{"_is_top_level"}) 14 546 560
Condition66%4/6
not $collapse_map->{"-identifying_columns"} || $args->{"premultiplied"} and $args->{"_is_top_level"}
!ll&&!rl&&r
546014
$collapse_map->{'-identifying_columns'} || $args->{'premultiplied'}
l!l&&r!l&&!r
546014
MC/DC33%1/3
not $collapse_map->{"-identifying_columns"} || $args->{"premultiplied"} and $args->{"_is_top_level"}
$collapse_map->{'-identifying_columns'} $args->{'premultiplied'} $args->{"_is_top_level"}
Truth table50%2/4
not(A || B) and C
A= $collapse_map->{'-identifying_columns'}B= $args->{'premultiplied'}C= $args->{"_is_top_level"}
ABCresult
1XX0
01X0
0000
0011
310 ! $collapse_map->{-identifying_columns}
311 and
312 ! $args->{premultiplied}
313 and
314 $args->{_is_top_level}
315 ) {
316 15 my (@collapse_sets, $uncollapsible_chain);
317  
318 15 for my $rel (keys %$relinfo) {
319  
320 # we already looked at these higher up
321 23 ▶ next if ($relinfo->{$rel}{is_single} && $relinfo->{$rel}{is_inner});
Branch: 1 branch
BranchTrueFalseTotal
if $relinfo->{$rel}{"is_single"} and $relinfo->{$rel}{"is_inner"} 0 22 22
Condition66%2/3
$relinfo->{$rel}{"is_single"} and $relinfo->{$rel}{"is_inner"}
!ll&&!rl&&r
1480
MC/DC0%0/2
$relinfo->{$rel}{"is_single"} and $relinfo->{$rel}{"is_inner"}
$relinfo->{$rel}{"is_single"} $relinfo->{$rel}{"is_inner"}
Truth table66%2/3
A and B
A= $relinfo->{$rel}{"is_single"}B= $relinfo->{$rel}{"is_inner"}
ABresult
0X0
100
111
322  
323 23 ▶ if (my $clps = $relinfo->{$rel}{rsrc}->_resolve_collapse ({
Branch: 1 branch
BranchTrueFalseTotal
if (my $clps = $relinfo->{$rel}{'rsrc'}->_resolve_collapse({'as', $rel_cols->{$rel}, '_rel_chain', [@{$args->{'_rel_chain'};}, $rel], '_parent_info', {'underdefined', 1}}, $common_args)) { } 22 0 22
324 as => $rel_cols->{$rel},
325 23 _rel_chain => [ @{$args->{_rel_chain}}, $rel ],
326 _parent_info => { underdefined => 1 },
327 }, $common_args) ) {
328  
329 # for singles use the idcols wholesale (either there or not)
330 23 ▶ if ($relinfo->{$rel}{is_single}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($relinfo->{$rel}{'is_single'}) { } 8 14 22
elsif (not $relinfo->{$rel}{'fk_map'}) { } 0 14 14
331 9 push @collapse_sets, $clps->{-identifying_columns};
332 }
333 elsif (! $relinfo->{$rel}{fk_map}) {
334 1 $uncollapsible_chain = 1;
335 1 last;
336 }
337 else {
338 15 my $defined_cols_parent_side;
339  
340 15 for my $fq_col ( grep { /^$rel\.[^\.]+$/ } keys %{$args->{as}} ) {
341 39 my ($col) = $fq_col =~ /([^\.]+)$/;
342  
343 39 $defined_cols_parent_side->{$_} = $args->{as}{$fq_col} for grep
344 39 { $relinfo->{$rel}{fk_map}{$_} eq $col }
345 39 keys %{$relinfo->{$rel}{fk_map}}
346 ;
347 }
348  
349 15 ▶ if (my $set = $self->_identifying_column_set([ keys %$defined_cols_parent_side ]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $set = $self->_identifying_column_set([keys %$defined_cols_parent_side])) { } 14 0 14
350 15 push @collapse_sets, [ sort map { $defined_cols_parent_side->{$_} } @$set ];
351 }
352 else {
353 1 $uncollapsible_chain = 1;
354 1 last;
355 }
356 }
357 }
358 else {
359 1 $uncollapsible_chain = 1;
360 1 last;
361 }
362 }
363  
364 15 ▶ unless ($uncollapsible_chain) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($uncollapsible_chain) 14 0 14
365 # if we got here - we are good to go, but the construction is tricky
366 # since our children will want to include our collapse criteria - we
367 # don't give them anything (safe, since they are all collapsible on their own)
368 # in addition we record the individual collapse possibilities
369 # of all left children node collapsers, and merge them in the rowparser
370 # coderef later
371 15 $collapse_map->{-identifying_columns} = [];
372 $collapse_map->{-identifying_columns_variants} = [ sort {
373 15 (scalar @$a) <=> (scalar @$b)
374 or
375 (
376 # Poor man's max()
377 1 ( sort { $b <=> $a } @$a )[0]
378 <=>
379 9 ▶ ( sort { $b <=> $a } @$b )[0]
Condition33%1/3
scalar @$a <=> scalar @$b || (sort {$b <=> $a;} @$a)[0] <=> (sort {$b <=> $a;} @$b)[0]
l!l&&r!l&&!r
080
MC/DC0%0/2
scalar @$a <=> scalar @$b || (sort {$b <=> $a;} @$a)[0] <=> (sort {$b <=> $a;} @$b)[0]
scalar @$a <=> scalar @$b (sort {$b <=> $a;} @$a)[0] <=> (sort {$b <=> $a;} @$b)[0]
Truth table33%1/3
A || B
A= scalar @$a <=> scalar @$bB= (sort {$b <=> $a;} @$a)[0] <=> (sort {$b <=> $a;} @$b)[0]
ABresult
1X1
011
000
380 )
381 } @collapse_sets ];
382 }
383 }
384  
385 # stop descending into children if we were called by a parent for first-pass
386 # and don't despair if nothing was found (there may be other parallel branches
387 # to dive into)
388 561 ▶ if ($args->{_parent_info}{underdefined}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args->{'_parent_info'}{'underdefined'}) { } 49 511 560
elsif (not $collapse_map->{'-identifying_columns'}) { } 0 511 511
389 50 ▶ return $collapse_map->{-identifying_columns} ? $collapse_map : undef
Branch: 1 branch
BranchTrueFalseTotal
$collapse_map->{'-identifying_columns'} ? : 49 0 49
390 }
391 # nothing down the chain resolved - can't calculate a collapse-map
392 elsif (! $collapse_map->{-identifying_columns}) {
393 $self->throw_exception ( sprintf
394 "Unable to calculate a definitive collapse column set for %s%s: fetch more unique non-nullable columns",
395 $self->source_name,
396 1 @{$args->{_rel_chain}} > 1
397 1 ▶ ? sprintf (' (last member of the %s chain)', join ' -> ', @{$args->{_rel_chain}} )
Branch: 1 branch
BranchTrueFalseTotal
@{$args->{'_rel_chain'};} > 1 ? : 0 0 0
398 : ''
399 ,
400 );
401 }
402  
403 # If we got that far - we are collapsable - GREAT! Now go down all children
404 # a second time, and fill in the rest
405  
406 $collapse_map->{-identifying_columns} = [ __unique_numlist(
407 512 ▶ @{ $args->{_parent_info}{collapse_on_idcols}||[] },
Condition100%2/2
$args->{'_parent_info'}{'collapse_on_idcols'} || []
l!l
343168
MC/DC100%1/1
$args->{'_parent_info'}{'collapse_on_idcols'} || []
$args->{'_parent_info'}{'collapse_on_idcols'}
Truth table100%2/2
A
A= $args->{'_parent_info'}{'collapse_on_idcols'}
Aresult
11
00
408 512 @{ $collapse_map->{-identifying_columns} },
409 )];
410  
411 512 my @id_sets;
412 512 for my $rel (sort keys %$relinfo) {
413  
414 $collapse_map->{$rel} = $relinfo->{$rel}{rsrc}->_resolve_collapse ({
415 1820 as => { map { $_ => 1 } ( keys %{$rel_cols->{$rel}} ) },
416 344 _rel_chain => [ @{$args->{_rel_chain}}, $rel],
417 _parent_info => {
418 # shallow copy
419 344 ▶ collapse_on_idcols => [ @{$collapse_map->{-identifying_columns}} ],
Branch: 1 branch
BranchTrueFalseTotal
grep({ref $_->{'cond'} eq 'HASH' and not +($_->{'attrs'}{'join_type'} || '') =~ /^left/i;} values %{$self->reverse_relationship_info($rel);}) ? : 226 117 343
420  
421 rel_condition => $relinfo->{$rel}{fk_map},
422  
423 is_optional => ! $relinfo->{$rel}{is_inner},
424  
425 # if there is at least one *inner* reverse relationship which is HASH-based (equality only)
426 # we can safely assume that the child can not exist without us
427 rev_rel_is_optional => ( grep
428 585 ▶ { ref $_->{cond} eq 'HASH' and ($_->{attrs}{join_type}||'') !~ /^left/i }
Condition80%4/5
ref $_->{'cond'} eq 'HASH' && !(($_->{'attrs'}{'join_type'} || '') =~ /^left/i)
!ll&&!rl&&r
0211373
$_->{'attrs'}{'join_type'} || ''
l!l
211373
MC/DC50%1/2
ref $_->{'cond'} eq 'HASH' && !(($_->{'attrs'}{'join_type'} || '') =~ /^left/i)
ref $_->{'cond'} eq 'HASH' $_->{'attrs'}{'join_type'}
Truth table66%2/3
A && not(B)
A= ref $_->{'cond'} eq 'HASH'B= $_->{'attrs'}{'join_type'}
ABresult
0X0
110
101
429 344 ▶ values %{ $self->reverse_relationship_info($rel) },
Branch: 1 branch
BranchTrueFalseTotal
$relinfo->{$rel}{'is_single'} && $relinfo->{$rel}{'is_inner'} && @{$collapse_map->{'-identifying_columns'};} ? : 97 246 343
Condition83%5/6
$relinfo->{$rel}{"is_single"} and $relinfo->{$rel}{"is_inner"} and @{$collapse_map->{"-identifying_columns"};}
!ll&&!rl&&r
246097
$relinfo->{$rel}{"is_single"} and $relinfo->{$rel}{"is_inner"}
!ll&&!rl&&r
2113597
MC/DC66%2/3
$relinfo->{$rel}{"is_single"} and $relinfo->{$rel}{"is_inner"} and @{$collapse_map->{"-identifying_columns"};}
$relinfo->{$rel}{"is_single"} $relinfo->{$rel}{"is_inner"} @{$collapse_map->{"-identifying_columns"};}
Truth table75%3/4
A and B and C
A= $relinfo->{$rel}{"is_single"}B= $relinfo->{$rel}{"is_inner"}C= @{$collapse_map->{"-identifying_columns"};}
ABCresult
0XX0
10X0
1100
1111
430 ) ? 0 : 1,
431  
432 # if this is a 1:1 our own collapser can be used as a collapse-map
433 # (regardless of left or not)
434 collapser_reusable => (
435 $relinfo->{$rel}{is_single}
436 &&
437 $relinfo->{$rel}{is_inner}
438 &&
439 344 @{$collapse_map->{-identifying_columns}}
440 ) ? 1 : 0,
441 },
442 }, $common_args );
443  
444 344 ▶ $collapse_map->{$rel}{-is_single} = 1 if $relinfo->{$rel}{is_single};
Branch: 1 branch
BranchTrueFalseTotal
if $relinfo->{$rel}{"is_single"} 132 211 343
445 344 ▶ $collapse_map->{$rel}{-is_optional} ||= 1 unless $relinfo->{$rel}{is_inner};
Branch: 1 branch
BranchTrueFalseTotal
unless $relinfo->{$rel}{"is_inner"} 243 100 343
Condition50%1/2
$collapse_map->{$rel}{"-is_optional"} ||= 1
l!l
0243
MC/DC0%0/1
$collapse_map->{$rel}{"-is_optional"} ||= 1
$collapse_map->{$rel}{"-is_optional"}
Truth table50%1/2
A
A= $collapse_map->{$rel}{"-is_optional"}
Aresult
11
00
446 }
447  
448 512 return $collapse_map;
449 }
450  
451 # adding a dep on MoreUtils *just* for this is retarded
452 934 ▶sub __unique_numlist {
Subroutine __unique_numlist: called CC=1 SCAR=0.0
453 934 sort { $a <=> $b } keys %{ {map { $_ => 1 } @_ }}
454 }
455  
456 380 1;
« DBIx/Class/Storage/DBI/Sybase/ASE/NoBindVars.pm ↑ Summary DBIx/Class/Storage/DBI/ODBC.pm »