DBIx/Class/ResultSource/RowParser.pm

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