blib/lib/DBIx/Class/Schema/Loader/DBI/RelPatterns.pm

filter: Statementstmt 92.2% 311 / 337 Branchbran 87.5% 175 / 200 Conditioncond 78.7% 196 / 249 MC/DCmcdc 57.4% 81 / 141 Subroutinesub 75.8% 22 / 29 Podpod 50.0% 1 / 2 totaltotal 82.0% 786 / 958 CC 206 SCAR 39.8
CC
206
Cov
87%
_table_fk_info
95.1
_normalize_rel_arg
59.0
_table_indexes_info
20.1
CRAP 53.3
↑ Summary
1 package DBIx::Class::Schema::Loader::DBI::RelPatterns;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 our $VERSION = '0.01043';
7  
8 12 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 ▶use base qw/DBIx::Class::Schema::Loader::DBI Class::Accessor::Grouped/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 12 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 12 ▶use Carp::Clan qw/^DBIx::Class/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 12 __PACKAGE__->mk_group_accessors('simple', qw/
16 _rel_constraint
17 _rel_exclude
18 /);
19  
20 12 ▶unless (__PACKAGE__->can('_disable_uniq_detection')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (__PACKAGE__->can("_disable_uniq_detection")) 0 12 12
21 # in Loader since version 0.07008
22 0 __PACKAGE__->mk_group_accessors('simple', '_disable_uniq_detection');
23 }
24  
25 12 my %INDEX_PRIORITY = (PRIMARY => 3, UNIQUE => 2, ANY => 1);
26  
27  
28 72 ▶sub new {
Subroutine new: called CC=11 SCAR=24.2
Pod documented
29 72 my ($class, %args) = @_;
30
31 # let the driver-specific class load
32 72 my $loader_class = delete $args{loader_class}; # in Loader since version 0.06000
33
34 72 ▶ if ($loader_class && $loader_class ne $class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loader_class and $loader_class ne $class) 0 72 72
Condition33%1/3
$loader_class and $loader_class ne $class
!ll&&!rl&&r
0720
MC/DC0%0/2
$loader_class and $loader_class ne $class
$loader_class $loader_class ne $class
Truth table33%1/3
A and B
A= $loader_classB= $loader_class ne $class
ABresult
0X0
100
111
35 0 die "Unexpected error: loader class $loader_class is not $class";
36 }
37
38 72 my $self = $class->next::method(%args);
39
40 # put back the deleted value, just in case
41 72 ▶ $self->{loader_class} = $loader_class if $loader_class;
Branch: 1 branch
BranchTrueFalseTotal
if $loader_class 72 0 72
42
43 72 ▶ unless ($self->isa($class)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->isa($class)) 28 44 72
44 28 my $superclass = ref $self;
45
46 # security blanket: make sure prospective foster parent does not have our methods
47 28 ▶ unless ($self->{_relpat_override} || $self->{_relpat_inherit}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_relpat_override"} or $self->{"_relpat_inherit"}) 16 12 28
Condition100%3/3
$self->{"_relpat_override"} or $self->{"_relpat_inherit"}
l!l&&r!l&&!r
6616
MC/DC100%2/2
$self->{"_relpat_override"} or $self->{"_relpat_inherit"}
$self->{"_relpat_override"} $self->{"_relpat_inherit"}
Truth table100%3/3
A or B
A= $self->{"_relpat_override"}B= $self->{"_relpat_inherit"}
ABresult
1X1
011
000
48 16 foreach my $method (qw/
49 _columns_index_for
50 _compat_table
51 _match_constraint
52 _normalize_rel_arg
53 _schemas_eq
54 _table_indexes_info
55 /) {
56 81 ▶ die "Unexpected error: $method in $class has super-method in $superclass" if $self->can($method);
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($method) 6 75 81
57 # _relpat_inherit: "*$method = $supermethod" redefinition is
58 # a little too global and takes us past the point of no return.
59 # instead each of the listed methods has to support _relpat_inherit
60 # option and goto next::method when available.
61 # not laconic but reliable.
62 }
63 }
64
65 # inherit from the driver-specific class
66 22 unshift our(@ISA), $superclass;
67 # Class::C3 needs a kick to notice @ISA changes
68 22 Class::C3::reinitialize();
69 # ready to get back behind the wheel
70 22 bless $self, $class;
71 }
72
73 66 $self->_rel_constraint( $self->_normalize_rel_arg('rel_constraint') );
74 58 $self->_rel_exclude( $self->_normalize_rel_arg('rel_exclude') );
75
76 53 ▶ if (!$self->_rel_constraint) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_rel_constraint) 9 44 53
77 9 ▶ warn "RelPatterns loader class makes little sense without rel_constraint patterns\n" unless $self->quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quiet 1 8 9
78 }
79
80 53 return $self;
81 }
82  
83  
84 # takes arg name and optionally raw arg value
85 # returns normalized arg value
86 124 ▶sub _normalize_rel_arg {
Subroutine _normalize_rel_arg: called CC=57 SCAR=40.8
87 124 my $self = shift;
88 124 my ($arg, $input) = @_;
89
90 124 ▶ return $self->next::method(@_) if $self->{_relpat_inherit} && $self->next::can;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_relpat_inherit"} and $self->next::can 1 123 124
Condition100%3/3
$self->{"_relpat_inherit"} and $self->next::can
!ll&&!rl&&r
113101
MC/DC100%2/2
$self->{"_relpat_inherit"} and $self->next::can
$self->{"_relpat_inherit"} $self->next::can
Truth table100%3/3
A and B
A= $self->{"_relpat_inherit"}B= $self->next::can
ABresult
0X0
100
111
91
92 123 ▶ $arg ||= '';
Condition50%1/2
$arg ||= ""
l!l
1230
MC/DC0%0/1
$arg ||= ""
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
93
94 123 ▶ if ($arg ne 'rel_constraint' && $arg ne 'rel_exclude') {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg ne "rel_constraint" and $arg ne "rel_exclude") 0 123 123
Condition66%2/3
$arg ne "rel_constraint" and $arg ne "rel_exclude"
!ll&&!rl&&r
65580
MC/DC0%0/2
$arg ne "rel_constraint" and $arg ne "rel_exclude"
$arg ne "rel_constraint" $arg ne "rel_exclude"
Truth table66%2/3
A and B
A= $arg ne "rel_constraint"B= $arg ne "rel_exclude"
ABresult
0X0
100
111
95 0 die "Unexpected error: unknown arg $arg";
96 }
97
98 123 ▶ $input ||= $self->{$arg} or return;
Branch: 1 branch
BranchTrueFalseTotal
$input ||= $self->{$arg} or return 82 41 123
Condition66%2/3
$input ||= $self->{$arg}
l!l&&r!l&&!r
08241
MC/DC50%1/2
$input ||= $self->{$arg}
$input $self->{$arg}
Truth table66%2/3
A ||= B
A= $inputB= $self->{$arg}
ABresult
1X1
011
000
99
100 82 my $reftype = ref $input;
101 82 ▶ if ($reftype ne 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if ($reftype ne 'ARRAY') { } 6 76 82
elsif (@$input % 2) { } 2 74 76
102 6 croak "Invalid type $reftype for option '$arg'; must be an array refference";
103 } elsif (@$input % 2) {
104 2 croak "Option '$arg' cannot take an arrayref with odd number of elements; must be even";
105 }
106
107 74 my %accepted = (
108 type => { similar => 1, exact => 1 },
109 );
110
111 74 my %defaults = (
112 local => { sch => '', index => 'any' },
113 remote => { sch => '', index => 'any', type => 'exact', diag => 0 },
114 );
115
116 74 my @input = @$input;
117 74 my @output;
118 74 ▶ while (@input) {
Branch: 1 branch
BranchTrueFalseTotal
if (@input) 323 70 393
119 323 my (%local, %remote);
120 323 my $is_empty = 1; # for adjustment of defaults
121
122 323 foreach my $con (\%local, \%remote) {
123 646 ▶ my $constraint = shift @input || '';
Condition100%2/2
shift @input || ''
l!l
63610
MC/DC100%1/1
shift @input || ''
shift @input
Truth table100%2/2
A
A= shift @input
Aresult
11
00
124
125 646 my $reftype = ref $constraint;
126 646 ▶ if (!$reftype) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $reftype) { } 243 403 646
elsif ($reftype eq 'ARRAY') { } 109 294 403
elsif ($reftype eq 'Regexp') { } 103 191 294
elsif ($reftype eq 'HASH') { } 189 2 191
127 # reversed because both 'fooid' and 'foo.fooid' point to column fooid
128 # no stripping because 'foo.' points to table foo
129 243 @$con{ qw/col tab sch/ } = reverse split /\./, $constraint, -1;
130 } elsif ($reftype eq 'ARRAY') {
131 # the same principle applies to arrayrefs
132 109 @$con{ qw/col tab sch/ } = reverse @$constraint;
133 } elsif ($reftype eq 'Regexp') {
134 103 ▶ $con->{ $con == \%local ? 'col' : 'tab' } = $constraint;
Branch: 1 branch
BranchTrueFalseTotal
$con == \%local ? : 56 47 103
135 } elsif ($reftype eq 'HASH') {
136 189 %$con = %$constraint;
137 } else {
138 2 croak "Invalid type $reftype for option's '$arg' element; must be a scalar, qr// regexp, an arrayref or a hashref";
139 }
140
141 644 my $string = '';
142 644 foreach my $key (reverse qw/col tab sch/) {
143 1932 ▶ my $val = $con->{$key} || '';
Condition100%2/2
$con->{$key} || ''
l!l
7931139
MC/DC100%1/1
$con->{$key} || ''
$con->{$key}
Truth table100%2/2
A
A= $con->{$key}
Aresult
11
00
144 1932 ▶ next unless $val || $string;
Branch: 1 branch
BranchTrueFalseTotal
unless $val or $string 934 998 1932
Condition100%3/3
$val or $string
l!l&&r!l&&!r
793205934
MC/DC100%2/2
$val or $string
$val $string
Truth table100%3/3
A or B
A= $valB= $string
ABresult
1X1
011
000
145 998 ▶ $string .= ', ' if $string;
Branch: 1 branch
BranchTrueFalseTotal
if $string 465 533 998
146 998 ▶ $string .= (ref $val eq 'Regexp') ? "qr/$val/" : "'$val'";
Branch: 1 branch
BranchTrueFalseTotal
ref $val eq 'Regexp' ? : 381 617 998
147 }
148 644 $con->{string} = '[' . $string . ']'; #for debugging purposes only
149
150 # respect preserve_case
151 644 ▶ $con->{col} = $self->_lc( $con->{col} ) if $con->{col} && !ref $con->{col};
Branch: 1 branch
BranchTrueFalseTotal
if $con->{"col"} and not ref $con->{"col"} 179 465 644
Condition100%3/3
$con->{"col"} and not ref $con->{"col"}
!ll&&!rl&&r
277188179
MC/DC100%2/2
$con->{"col"} and not ref $con->{"col"}
$con->{"col"} not ref $con->{"col"}
Truth table100%3/3
A and not(B)
A= $con->{"col"}B= not ref $con->{"col"}
ABresult
0X0
100
111
152
153 # default sch can be set only for rel_constraint
154 644 ▶ foreach my $key ($arg eq 'rel_constraint' ? qw/col tab/ : qw/col tab sch/) {
Branch: 1 branch
BranchTrueFalseTotal
$arg eq 'rel_constraint' ? : 541 103 644
155 1391 ▶ $is_empty = 0 if $con->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $con->{$key} 754 637 1391
156 }
157 }
158
159 321 ▶ if ($arg eq 'rel_constraint') {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq "rel_constraint") 270 51 321
160 270 foreach my $key (qw/type diag/) {
161 539 ▶ croak "Hashref's key '$key' applies only to relationship pattern's right-hand side" if $local{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $local{$key} 2 537 539
162 }
163 268 foreach my $con (\%local, \%remote) {
164 536 ▶ my $side = ($con == \%local) ? 'local' : 'remote';
Branch: 1 branch
BranchTrueFalseTotal
$con == \%local ? : 268 268 536
165 536 ▶ while (my ($key, $accepted) = each %accepted) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %accepted) 536 536 1072
166 536 ▶ $con->{$key} = $defaults{$side}{$key} if $con->{$key} && !$accepted->{ $con->{$key} };
Branch: 1 branch
BranchTrueFalseTotal
if $con->{$key} and not $$accepted{$con->{$key}} 0 536 536
Condition66%2/3
$con->{$key} and not $$accepted{$con->{$key}}
!ll&&!rl&&r
515210
MC/DC0%0/2
$con->{$key} and not $$accepted{$con->{$key}}
$con->{$key} not $$accepted{$con->{$key}}
Truth table66%2/3
A and not(B)
A= $con->{$key}B= not $$accepted{$con->{$key}}
ABresult
0X0
100
111
167 }
168 536 ▶ if ($is_empty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_empty) { } 126 410 536
169 # adjust the defaults
170 126 ▶ $defaults{$side}{sch} = $con->{sch} if defined $con->{sch};
Branch: 1 branch
BranchTrueFalseTotal
if defined $con->{"sch"} 48 78 126
171 126 ▶ $defaults{$side}{index} = $con->{index} if $con->{index};
Branch: 1 branch
BranchTrueFalseTotal
if $con->{"index"} 21 105 126
172 126 ▶ $defaults{$side}{type} = $con->{type} if $con->{type} && $side eq 'remote';
Branch: 1 branch
BranchTrueFalseTotal
if $con->{"type"} and $side eq "remote" 21 105 126
Condition66%2/3
$con->{"type"} and $side eq "remote"
!ll&&!rl&&r
105021
MC/DC50%1/2
$con->{"type"} and $side eq "remote"
$con->{"type"} $side eq "remote"
Truth table66%2/3
A and B
A= $con->{"type"}B= $side eq "remote"
ABresult
0X0
100
111
173 126 ▶ $defaults{$side}{diag} = $con->{diag} if defined $con->{diag} && $side eq 'remote';
Branch: 1 branch
BranchTrueFalseTotal
if defined $con->{"diag"} and $side eq "remote" 0 126 126
Condition33%1/3
defined $con->{"diag"} and $side eq "remote"
!ll&&!rl&&r
12600
MC/DC0%0/2
defined $con->{"diag"} and $side eq "remote"
defined $con->{"diag"} $side eq "remote"
Truth table33%1/3
A and B
A= defined $con->{"diag"}B= $side eq "remote"
ABresult
0X0
100
111
174 } else {
175 # apply the defaults
176 410 ▶ $con->{sch} = $defaults{$side}{sch} if !defined $con->{sch};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $con->{"sch"} 398 12 410
177 410 ▶ $con->{index} ||= $defaults{$side}{index};
Condition66%2/3
$con->{"index"} ||= $defaults{$side}{"index"}
l!l&&r!l&&!r
94010
MC/DC0%0/2
$con->{"index"} ||= $defaults{$side}{"index"}
$con->{"index"} $defaults{$side}{"index"}
Truth table66%2/3
A ||= B
A= $con->{"index"}B= $defaults{$side}{"index"}
ABresult
1X1
011
000
178 410 ▶ $con->{type} ||= $defaults{$side}{type} if $side eq 'remote';
Branch: 1 branch
BranchTrueFalseTotal
if $side eq "remote" 205 205 410
Condition33%1/3
$con->{"type"} ||= $defaults{$side}{"type"}
l!l&&r!l&&!r
02050
MC/DC0%0/2
$con->{"type"} ||= $defaults{$side}{"type"}
$con->{"type"} $defaults{$side}{"type"}
Truth table33%1/3
A ||= B
A= $con->{"type"}B= $defaults{$side}{"type"}
ABresult
1X1
011
000
179 410 ▶ $con->{diag} = $defaults{$side}{diag} if !defined $con->{diag} && $side eq 'remote';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $con->{"diag"} and $side eq "remote" 205 205 410
Condition66%2/3
not defined $con->{"diag"} and $side eq "remote"
!ll&&!rl&&r
0205205
MC/DC50%1/2
not defined $con->{"diag"} and $side eq "remote"
not defined $con->{"diag"} $side eq "remote"
Truth table66%2/3
not(A) and B
A= not defined $con->{"diag"}B= $side eq "remote"
ABresult
0X0
100
111
180
181 410 ▶ $con->{min_index_priority} = $INDEX_PRIORITY{ uc $con->{index} } || 0;
Condition100%2/2
$INDEX_PRIORITY{uc $con->{'index'}} || 0
l!l
39812
MC/DC100%1/1
$INDEX_PRIORITY{uc $con->{'index'}} || 0
$INDEX_PRIORITY{uc $con->{'index'}}
Truth table100%2/2
A
A= $INDEX_PRIORITY{uc $con->{'index'}}
Aresult
11
00
182
183 # force index=>'optional' when tab and col are non-empty strings
184 410 ▶ if ($con->{tab} && $con->{col} && !ref $con->{tab} && !ref $con->{col}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($con->{"tab"} and $con->{"col"} and not ref $con->{"tab"} and not ref $con->{"col"}) 113 297 410
Condition100%9/9
$con->{"tab"} and $con->{"col"} and not ref $con->{"tab"} and not ref $con->{"col"}
!ll&&!rl&&r
24948113
$con->{"tab"} and $con->{"col"} and not ref $con->{"tab"}
!ll&&!rl&&r
18960161
$con->{"tab"} and $con->{"col"}
!ll&&!rl&&r
9594221
MC/DC100%4/4
$con->{"tab"} and $con->{"col"} and not ref $con->{"tab"} and not ref $con->{"col"}
$con->{"tab"} $con->{"col"} not ref $con->{"tab"} not ref $con->{"col"}
Truth table100%5/5
A and B and not(C) and not(D)
A= $con->{"tab"}B= $con->{"col"}C= not ref $con->{"tab"}D= not ref $con->{"col"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
185 113 $con->{min_index_priority} = 0;
186 }
187 }
188 }
189 }
190
191 319 ▶ next if $is_empty;
Branch: 1 branch
BranchTrueFalseTotal
if $is_empty 66 253 319
192
193 253 push @output, [\%local, \%remote];
194 }
195
196 70 ▶ return @output ? \@output : undef;
Branch: 1 branch
BranchTrueFalseTotal
@output ? : 62 8 70
197 }
198  
199  
200 # the brain of this module.
201 # constraint can be a string or a qr// regexp (returns true if missing or empty)
202 # if captured_ref is provided, then capture groups are compared
203 # if captured_ref is a reference, then captured_ref is modified
204 6816 ▶sub _match_constraint {
Subroutine _match_constraint: called CC=12 SCAR=24.8
205 6816 my $self = shift;
206 6816 my ($string, $constraint, $captured_ref) = @_;
207
208 6816 ▶ return $self->next::method(@_) if $self->{_relpat_inherit} && $self->next::can;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_relpat_inherit"} and $self->next::can 1 6815 6816
Condition100%3/3
$self->{"_relpat_inherit"} and $self->next::can
!ll&&!rl&&r
6776391
MC/DC100%2/2
$self->{"_relpat_inherit"} and $self->next::can
$self->{"_relpat_inherit"} $self->next::can
Truth table100%3/3
A and B
A= $self->{"_relpat_inherit"}B= $self->next::can
ABresult
0X0
100
111
209
210 # schema and _schema can be undef (_schema is needed for testing purposes only)
211 6815 ▶ $string ||= '';
Condition100%2/2
$string ||= ""
l!l
51871628
MC/DC100%1/1
$string ||= ""
$string
Truth table100%2/2
A
A= $string
Aresult
11
00
212
213 # no constraint means nothing to match
214 6815 ▶ return 1 unless $constraint;
Branch: 1 branch
BranchTrueFalseTotal
unless $constraint 2787 4028 6815
215
216 4028 ▶ return $string eq $constraint if ref $constraint ne 'Regexp';
Branch: 1 branch
BranchTrueFalseTotal
if ref $constraint ne "Regexp" 1687 2341 4028
217
218 2341 ▶ my @cap = $string =~ /$constraint/ or return;
Branch: 1 branch
BranchTrueFalseTotal
my(@cap) = $string =~ /$constraint/ or return 1565 776 2341
219
220 # compare capture groups only if needed and if regexp creates them
221 1565 ▶ return 1 unless defined $captured_ref && defined $1;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $captured_ref and defined $1 429 1136 1565
Condition100%3/3
defined $captured_ref and defined $1
!ll&&!rl&&r
346831136
MC/DC100%2/2
defined $captured_ref and defined $1
defined $captured_ref defined $1
Truth table100%3/3
A and B
A= defined $captured_refB= defined $1
ABresult
0X0
100
111
222
223 # if modifying the original is not desired...
224 1136 ▶ if (!ref $captured_ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $captured_ref) 579 557 1136
225 579 my $captured = $captured_ref;
226 579 $captured_ref = \$captured;
227 }
228
229 1136 my $cap = join "\0", @cap;
230 1136 ▶ if (!defined $$captured_ref || $cap =~ /\A\Q$$captured_ref\E\0/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $$captured_ref or $cap =~ /\A\Q$$captured_ref\E\0/i) 434 702 1136
Condition100%3/3
not defined $$captured_ref or $cap =~ /\A\Q$$captured_ref\E\0/i
l!l&&r!l&&!r
41816702
MC/DC100%2/2
not defined $$captured_ref or $cap =~ /\A\Q$$captured_ref\E\0/i
not defined $$captured_ref $cap =~ /\A\Q$$captured_ref\E\0/i
Truth table100%3/3
not(A) or B
A= not defined $$captured_refB= $cap =~ /\A\Q$$captured_ref\E\0/i
ABresult
1X1
011
000
231 # update captured if cap has more contents
232 434 $$captured_ref = $cap;
233 }
234
235 # ideally, cap should eq captured;
236 # but also fine if captured starts with cap
237 1136 return $$captured_ref =~ /\A\Q$cap\E(?:\0|\z)/i;
238 }
239  
240  
241 105 ▶sub _schemas_eq {
Subroutine _schemas_eq: called CC=7 SCAR=19.7
242 105 my $self = shift;
243 105 my ($table_a, $table_b) = @_;
244
245 105 ▶ return $self->next::method(@_) if $self->{_relpat_inherit} && $self->next::can;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_relpat_inherit"} and $self->next::can 1 104 105
Condition66%2/3
$self->{"_relpat_inherit"} and $self->next::can
!ll&&!rl&&r
10401
MC/DC50%1/2
$self->{"_relpat_inherit"} and $self->next::can
$self->{"_relpat_inherit"} $self->next::can
Truth table66%2/3
A and B
A= $self->{"_relpat_inherit"}B= $self->next::can
ABresult
0X0
100
111
246
247 # _schema is needed for testing purposes only
248 return (
249 104 ▶ ($table_a->schema || $table_a->_schema || '') eq
Condition80%8/10
$table_a->schema || $table_a->_schema || ''
l!l
2282
$table_a->schema or $table_a->_schema
l!l&&r!l&&!r
02282
$table_b->schema || $table_b->_schema || ''
l!l
2282
$table_b->schema or $table_b->_schema
l!l&&r!l&&!r
02282
MC/DC50%1/2
$table_a->schema || $table_a->_schema || ''
$table_a->schema $table_a->_schema
MC/DC50%1/2
$table_b->schema || $table_b->_schema || ''
$table_b->schema $table_b->_schema
Truth table66%2/3
A or B
A= $table_a->schemaB= $table_a->_schema
ABresult
1X1
011
000
Truth table66%2/3
A or B
A= $table_b->schemaB= $table_b->_schema
ABresult
1X1
011
000
250 ($table_b->schema || $table_b->_schema || '')
251 );
252 }
253  
254  
255 # takes a database object
256 # returns a hashref of index information per column
257 371 ▶sub _columns_index_for {
Subroutine _columns_index_for: called CC=11 SCAR=24.1
258 371 my $self = shift;
259 371 my ($table) = @_;
260
261 371 ▶ return $self->next::method(@_) if $self->{_relpat_inherit} && $self->next::can;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_relpat_inherit"} and $self->next::can 1 370 371
Condition100%3/3
$self->{"_relpat_inherit"} and $self->next::can
!ll&&!rl&&r
36641
MC/DC100%2/2
$self->{"_relpat_inherit"} and $self->next::can
$self->{"_relpat_inherit"} $self->next::can
Truth table100%3/3
A and B
A= $self->{"_relpat_inherit"}B= $self->next::can
ABresult
0X0
100
111
262
263 370 ▶ my $pks = $self->_table_pk_info($table) || [];
Condition50%1/2
$self->_table_pk_info($table) || []
l!l
3700
MC/DC0%0/1
$self->_table_pk_info($table) || []
$self->_table_pk_info($table)
Truth table50%1/2
A
A= $self->_table_pk_info($table)
Aresult
11
00
264 370 ▶ my $uniqs = $self->_table_uniq_info($table) || [];
Condition50%1/2
$self->_table_uniq_info($table) || []
l!l
3700
MC/DC0%0/1
$self->_table_uniq_info($table) || []
$self->_table_uniq_info($table)
Truth table50%1/2
A
A= $self->_table_uniq_info($table)
Aresult
11
00
265 370 ▶ my $indxs = $self->_table_indexes_info($table) || []; # requires statistics_info
Condition50%1/2
$self->_table_indexes_info($table) || []
l!l
3690
MC/DC0%0/1
$self->_table_indexes_info($table) || []
$self->_table_indexes_info($table)
Truth table50%1/2
A
A= $self->_table_indexes_info($table)
Aresult
11
00
266
267 369 my %indexes;
268
269 369 foreach (
270 [ $INDEX_PRIORITY{PRIMARY} => [ ['PRIMARY', $pks] ] ],
271 [ $INDEX_PRIORITY{UNIQUE} => $uniqs ],
272 [ $INDEX_PRIORITY{ANY} => $indxs ], # NB! contains other indexes as well
273 ) {
274 1107 my ($priority, $index_info) = @$_;
275 1107 foreach (@$index_info) {
276 2290 my ($index_name, $cols) = @$_;
277 2290 my $index_size = @$cols;
278 2290 foreach my $position (0..$#$cols) {
279 3403 my $col = $cols->[$position];
280
281 # refine the priority
282 3403 my $priority = ($priority
283 # leading column is preferable
284 + (99 - $position) / 100
285 # larger index is preferable
286 + $index_size / 100**2
287 # shorter name is preferable (hopefully, it's "id")
288 #+ (99 - length $col) / 100**3 # not convinced, commented out
289 );
290
291 # not fail-proof in general, but especially if column
292 # is listed in multiple indexes with equal priority
293 $indexes{$col} = {
294 # for sort and rel_constraint's 'index' key
295 priority => $priority,
296 # for is_leftmost
297 position => $position,
298 # for sort
299 size => $index_size,
300 # for composite-key relationships
301 cols => $cols,
302 3403 ▶ } unless $indexes{$col} && $indexes{$col}{priority} >= $priority;
Branch: 1 branch
BranchTrueFalseTotal
unless $indexes{$col} and $indexes{$col}{"priority"} >= $priority 1558 1845 3403
Condition100%3/3
$indexes{$col} and $indexes{$col}{"priority"} >= $priority
!ll&&!rl&&r
1488701845
MC/DC100%2/2
$indexes{$col} and $indexes{$col}{"priority"} >= $priority
$indexes{$col} $indexes{$col}{"priority"} >= $priority
Truth table100%3/3
A and B
A= $indexes{$col}B= $indexes{$col}{"priority"} >= $priority
ABresult
0X0
100
111
303 }
304 }
305 }
306
307 369 return \%indexes;
308 }
309  
310  
311 # the heart of this module.
312 # takes a database object
313 # returns the identified relationships
314 292 ▶sub _table_fk_info {
Subroutine _table_fk_info: called CC=87 SCAR=45.5
315 292 my $self = shift;
316 292 my $table = $self->_compat_table(shift);
317
318 292 ▶ if (my $cached = $self->{_cache}{_table_fk_info}{$table->sql_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cached = $self->{"_cache"}{"_table_fk_info"}{$table->sql_name}) 144 148 292
319 144 return $cached;
320 }
321
322 148 my $rels = $self->next::method($table);
323
324 148 ▶ my $rel_constraint = $self->_rel_constraint || [];
Condition100%2/2
$self->_rel_constraint || []
l!l
12127
MC/DC100%1/1
$self->_rel_constraint || []
$self->_rel_constraint
Truth table100%2/2
A
A= $self->_rel_constraint
Aresult
11
00
325 148 ▶ my $rel_exclude = $self->_rel_exclude || [];
Condition100%2/2
$self->_rel_exclude || []
l!l
5494
MC/DC100%1/1
$self->_rel_exclude || []
$self->_rel_exclude
Truth table100%2/2
A
A= $self->_rel_exclude
Aresult
11
00
326
327 148 ▶ return $self->{_cache}{_table_fk_info}{$table->sql_name} = $rels if !@$rel_constraint;
Branch: 1 branch
BranchTrueFalseTotal
unless @$rel_constraint 27 121 148
328
329 121 my $columns = $self->_table_columns($table);
330 121 ▶ my $infos = $self->_columns_info_for($table) || {};
Condition50%1/2
$self->_columns_info_for($table) || {}
l!l
1210
MC/DC0%0/1
$self->_columns_info_for($table) || {}
$self->_columns_info_for($table)
Truth table50%1/2
A
A= $self->_columns_info_for($table)
Aresult
11
00
331 121 my $indexes = $self->_columns_index_for($table);
332
333 # all possible single-column relationships and diagnostics of failures
334 119 my (@rels_single, %diag);
335
336 119 foreach my $rel_con (@$rel_constraint) {
337 588 my ($con_local, $con_remote) = @$rel_con;
338 588 my ($captured, $captured_sch);
339
340 next unless $con_local->{col} && $con_remote->{tab}
341 && $self->_match_constraint($table->schema || $table->_schema, $con_local->{sch}, \$captured_sch)
342 588 ▶ && $self->_match_constraint($table->name, $con_local->{tab}, \$captured);
Branch: 1 branch
BranchTrueFalseTotal
unless $con_local->{"col"} and $con_remote->{"tab"} and $self->_match_constraint($table->schema || $table->_schema, $con_local->{"sch"}, \$captured_sch) and $self->_match_constraint($table->name, $con_local->{"tab"}, \$captured) 264 323 587
Condition91%11/12
$con_local->{"col"} and $con_remote->{"tab"} and $self->_match_constraint($table->schema || $table->_schema, $con_local->{"sch"}, \$captured_sch) and $self->_match_constraint($table->name, $con_local->{"tab"}, \$captured)
!ll&&!rl&&r
66198323
$con_local->{"col"} and $con_remote->{"tab"} and $self->_match_constraint($table->schema || $table->_schema, $con_local->{"sch"}, \$captured_sch)
!ll&&!rl&&r
3630522
$con_local->{"col"} and $con_remote->{"tab"}
!ll&&!rl&&r
1818552
$table->schema || $table->_schema
l!l&&r!l&&!r
054498
MC/DC100%4/4
$con_local->{"col"} and $con_remote->{"tab"} and $self->_match_constraint($table->schema || $table->_schema, $con_local->{"sch"}, \$captured_sch) and $self->_match_constraint($table->name, $con_local->{"tab"}, \$captured)
$con_local->{"col"} $con_remote->{"tab"} $self->_match_constraint($table->schema || $table->_schema, $con_local->{"sch"}, \$captured_sch) $self->_match_constraint($table->name, $con_local->{"tab"}, \$captured)
MC/DC50%1/2
$table->schema || $table->_schema
$table->schema $table->_schema
Truth table100%5/5
A and B and C and D
A= $con_local->{"col"}B= $con_remote->{"tab"}C= $self->_match_constraint($table->schema || $table->_schema, $con_local->{"sch"}, \$captured_sch)D= $self->_match_constraint($table->name, $con_local->{"tab"}, \$captured)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table66%2/3
A || B
A= $table->schemaB= $table->_schema
ABresult
1X1
011
000
343
344 my @remote_tables = grep {
345 # self-referential rels are set up only if tab is specified on both sides
346 323 ($con_local->{tab} && $con_remote->{tab} || $_->sql_name ne $table->sql_name)
347 && $self->_match_constraint($_->schema || $_->_schema, $con_remote->{sch}, \$captured_sch)
348 && $self->_match_constraint($_->name, $con_remote->{tab})
349 969 ▶ } map $self->_compat_table($_), $self->tables;
Condition86%13/15
($con_local->{'tab'} && $con_remote->{'tab'} || $_->sql_name ne $table->sql_name) && $self->_match_constraint($_->schema || $_->_schema, $con_remote->{'sch'}, \$captured_sch) && $self->_match_constraint($_->name, $con_remote->{'tab'})
!ll&&!rl&&r
277300392
$con_local->{"tab"} && $con_remote->{"tab"} || $_->sql_name ne $table->sql_name and $self->_match_constraint($_->schema || $_->_schema, $con_remote->{"sch"}, \$captured_sch)
!ll&&!rl&&r
20572692
$con_local->{"tab"} and $con_remote->{"tab"} or $_->sql_name ne $table->sql_name
l!l&&r!l&&!r
354410205
$con_local->{"tab"} and $con_remote->{"tab"}
!ll&&!rl&&r
6150354
$_->schema || $_->_schema
l!l&&r!l&&!r
084680
MC/DC80%4/5
($con_local->{'tab'} && $con_remote->{'tab'} || $_->sql_name ne $table->sql_name) && $self->_match_constraint($_->schema || $_->_schema, $con_remote->{'sch'}, \$captured_sch) && $self->_match_constraint($_->name, $con_remote->{'tab'})
$con_local->{"tab"} $con_remote->{"tab"} $_->sql_name ne $table->sql_name $self->_match_constraint($_->schema || $_->_schema, $con_remote->{"sch"}, \$captured_sch) $self->_match_constraint($_->name, $con_remote->{'tab'})
MC/DC50%1/2
$_->schema || $_->_schema
$_->schema $_->_schema
Truth table63%7/11
A and B or C and D && E
A= $con_local->{"tab"}B= $con_remote->{"tab"}C= $_->sql_name ne $table->sql_nameD= $self->_match_constraint($_->schema || $_->_schema, $con_remote->{"sch"}, \$captured_sch)E= $self->_match_constraint($_->name, $con_remote->{'tab'})
ABCDEresult
0X0XX0
100XX0
11X0X0
0X10X0
1010X0
11X100
0X1100
101100
11X111
0X1111
101111
Truth table66%2/3
A || B
A= $_->schemaB= $_->_schema
ABresult
1X1
011
000
350
351 COL:
352 323 foreach my $col (@$columns) {
353 # vivify to keep it simple
354 1615 ▶ $indexes->{$col} ||= { priority=>0, position=>0, size=>0, cols=>[] };
Condition100%2/2
$indexes->{$col} ||= {"priority", 0, "position", 0, "size", 0, "cols", []}
l!l
1493122
MC/DC100%1/1
$indexes->{$col} ||= {"priority", 0, "position", 0, "size", 0, "cols", []}
$indexes->{$col}
Truth table100%2/2
A
A= $indexes->{$col}
Aresult
11
00
355
356 # limit the scope a little, so that every column could have a fresh copy
357 1615 my $captured = $captured;
358 1615 my @remote_tables = @remote_tables;
359
360 next COL if $con_local->{min_index_priority} > $indexes->{$col}{priority}
361 1615 ▶ || !$self->_match_constraint($col, $con_local->{col}, \$captured);
Branch: 1 branch
BranchTrueFalseTotal
if $con_local->{"min_index_priority"} > $indexes->{$col}{"priority"} or not $self->_match_constraint($col, $con_local->{"col"}, \$captured) 1151 464 1615
Condition100%3/3
$con_local->{"min_index_priority"} > $indexes->{$col}{"priority"} or not $self->_match_constraint($col, $con_local->{"col"}, \$captured)
l!l&&r!l&&!r
282869464
MC/DC100%2/2
$con_local->{"min_index_priority"} > $indexes->{$col}{"priority"} or not $self->_match_constraint($col, $con_local->{"col"}, \$captured)
$con_local->{"min_index_priority"} > $indexes->{$col}{"priority"} not $self->_match_constraint($col, $con_local->{"col"}, \$captured)
Truth table100%3/3
A or not(B)
A= $con_local->{"min_index_priority"} > $indexes->{$col}{"priority"}B= not $self->_match_constraint($col, $con_local->{"col"}, \$captured)
ABresult
1X1
011
000
362
363 @remote_tables = sort {
364 # tables from the same schema are preferable
365 32 ▶ $self->_schemas_eq($table, $b) <=> $self->_schemas_eq($table, $a)
Condition66%2/3
$self->_schemas_eq($table, $b) <=> $self->_schemas_eq($table, $a) || $a->name cmp $b->name
l!l&&r!l&&!r
5260
MC/DC0%0/2
$self->_schemas_eq($table, $b) <=> $self->_schemas_eq($table, $a) || $a->name cmp $b->name
$self->_schemas_eq($table, $b) <=> $self->_schemas_eq($table, $a) $a->name cmp $b->name
Truth table66%2/3
A || B
A= $self->_schemas_eq($table, $b) <=> $self->_schemas_eq($table, $a)B= $a->name cmp $b->name
ABresult
1X1
011
000
366 # better than random
367 || $a->name cmp $b->name
368 } grep {
369 464 $self->_match_constraint($_->name, $con_remote->{tab}, $captured)
370 } @remote_tables;
371
372 463 my ($r_table, $r_col, $r_indexes, @r_cols);
373
374 # iterate over tables in order of priority until the corresponding column is found
375 RTAB:
376 463 ▶ while ($r_table = shift @remote_tables) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r_table = shift @remote_tables) 250 285 535
377 250 my $r_columns = $self->_table_columns($r_table);
378 250 ▶ my $r_infos = $self->_columns_info_for($r_table) || {};
Condition50%1/2
$self->_columns_info_for($r_table) || {}
l!l
2500
MC/DC0%0/1
$self->_columns_info_for($r_table) || {}
$self->_columns_info_for($r_table)
Truth table50%1/2
A
A= $self->_columns_info_for($r_table)
Aresult
11
00
379 250 $r_indexes = $self->_columns_index_for($r_table);
380
381 250 @r_cols = ();
382
383 RCOL:
384 250 foreach my $r_col (@$r_columns) {
385 # vivify to keep it simple
386 1250 ▶ $r_indexes->{$r_col} ||= { priority=>0, position=>0, size=>0, cols=>[] };
Condition100%2/2
$r_indexes->{$r_col} ||= {"priority", 0, "position", 0, "size", 0, "cols", []}
l!l
1017233
MC/DC100%1/1
$r_indexes->{$r_col} ||= {"priority", 0, "position", 0, "size", 0, "cols", []}
$r_indexes->{$r_col}
Truth table100%2/2
A
A= $r_indexes->{$r_col}
Aresult
11
00
387
388 next RCOL if ($table->sql_name eq $r_table->sql_name && $col eq $r_col)
389 1250 ▶ || !$self->_match_constraint($r_col, $con_remote->{col}, $captured);
Branch: 1 branch
BranchTrueFalseTotal
if $table->sql_name eq $r_table->sql_name and $col eq $r_col or not $self->_match_constraint($r_col, $con_remote->{"col"}, $captured) 417 833 1250
Condition100%6/6
$table->sql_name eq $r_table->sql_name and $col eq $r_col or not $self->_match_constraint($r_col, $con_remote->{"col"}, $captured)
l!l&&r!l&&!r
48369833
$table->sql_name eq $r_table->sql_name and $col eq $r_col
!ll&&!rl&&r
101019248
MC/DC100%3/3
$table->sql_name eq $r_table->sql_name and $col eq $r_col or not $self->_match_constraint($r_col, $con_remote->{"col"}, $captured)
$table->sql_name eq $r_table->sql_name $col eq $r_col not $self->_match_constraint($r_col, $con_remote->{"col"}, $captured)
Truth table100%5/5
A and B or not(C)
A= $table->sql_name eq $r_table->sql_nameB= $col eq $r_colC= not $self->_match_constraint($r_col, $con_remote->{"col"}, $captured)
ABCresult
11X1
0X11
1011
0X00
1000
390
391 833 ▶ if ($con_remote->{min_index_priority} > $r_indexes->{$r_col}{priority}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($con_remote->{"min_index_priority"} > $r_indexes->{$r_col}{"priority"}) 172 661 833
392 172 push @{ $diag{$rel_con} }, ['index mismatch', $col, $r_table, $r_col];
393 172 next RCOL;
394 }
395
396 661 ▶ if (exists $infos->{$col} && exists $r_infos->{$r_col}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $infos->{$col} and exists $r_infos->{$r_col}) { } 661 0 661
elsif ($con_remote->{'type'} eq 'exact') { } 0 0 0
Condition33%1/3
exists $infos->{$col} and exists $r_infos->{$r_col}
!ll&&!rl&&r
00661
MC/DC0%0/2
exists $infos->{$col} and exists $r_infos->{$r_col}
exists $infos->{$col} exists $r_infos->{$r_col}
Truth table33%1/3
A and B
A= exists $infos->{$col}B= exists $r_infos->{$r_col}
ABresult
0X0
100
111
397 # referencing column type has to match
398 661 ▶ if (($infos->{$col}{data_type} || '') ne ($r_infos->{$r_col}{data_type} || '')) {
Branch: 1 branch
BranchTrueFalseTotal
if (($infos->{$col}{"data_type"} || "") ne ($r_infos->{$r_col}{"data_type"} || "")) 358 303 661
Condition50%2/4
$infos->{$col}{'data_type'} || ''
l!l
6610
$r_infos->{$r_col}{'data_type'} || ''
l!l
6610
MC/DC0%0/1
$infos->{$col}{'data_type'} || ''
$infos->{$col}{'data_type'}
MC/DC0%0/1
$r_infos->{$r_col}{'data_type'} || ''
$r_infos->{$r_col}{'data_type'}
Truth table50%1/2
A
A= $infos->{$col}{'data_type'}
Aresult
11
00
Truth table50%1/2
A
A= $r_infos->{$r_col}{'data_type'}
Aresult
11
00
399 358 push @{ $diag{$rel_con} }, ['data type mismatch', $col, $r_table, $r_col];
400 358 next RCOL;
401 }
402
403 # if size of column data type cannot be ignored...
404 303 ▶ if ($con_remote->{type} eq 'exact') {
Branch: 1 branch
BranchTrueFalseTotal
if ($con_remote->{"type"} eq "exact") 258 45 303
405 258 ▶ my $col_size = $infos->{$col}{size} || 0;
Condition100%2/2
$infos->{$col}{'size'} || 0
l!l
10248
MC/DC100%1/1
$infos->{$col}{'size'} || 0
$infos->{$col}{'size'}
Truth table100%2/2
A
A= $infos->{$col}{'size'}
Aresult
11
00
406 258 ▶ my $r_col_size = $r_infos->{$r_col}{size} || 0;
Condition100%2/2
$r_infos->{$r_col}{'size'} || 0
l!l
18240
MC/DC100%1/1
$r_infos->{$r_col}{'size'} || 0
$r_infos->{$r_col}{'size'}
Truth table100%2/2
A
A= $r_infos->{$r_col}{'size'}
Aresult
11
00
407 258 ▶ $col_size = join "\0", @$col_size if ref $col_size eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $col_size eq "ARRAY" 5 253 258
408 258 ▶ $r_col_size = join "\0", @$r_col_size if ref $r_col_size eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $r_col_size eq "ARRAY" 7 251 258
409 258 ▶ if ($col_size ne $r_col_size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col_size ne $r_col_size) 15 243 258
410 15 push @{ $diag{$rel_con} }, ['data type size mismatch', $col, $r_table, $r_col];
411 15 next RCOL;
412 }
413 }
414 } elsif ($con_remote->{type} eq 'exact') {
415 # force majeure, columns' info is not available;
416 # in such a case column data types still are considered to be 'similar'
417 # but certainly not 'exact'
418 0 push @{ $diag{$rel_con} }, ['unknown data type', $col, $r_table, $r_col];
419 0 next RCOL;
420 }
421
422 288 foreach (@$rel_exclude) {
423 288 my ($exc_local, $exc_remote) = @$_;
424 288 my ($captured, $captured_sch);
425 next unless (
426 $self->_match_constraint($table->schema || $table->_schema, $exc_local->{sch}, \$captured_sch)
427 && $self->_match_constraint($r_table->schema || $r_table->_schema, $exc_remote->{sch}, \$captured_sch)
428 && $self->_match_constraint($table->name, $exc_local->{tab}, \$captured)
429 && $self->_match_constraint($col, $exc_local->{col}, \$captured)
430 && $self->_match_constraint($r_table->name, $exc_remote->{tab}, \$captured)
431 288 ▶ && $self->_match_constraint($r_col, $exc_remote->{col}, \$captured)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_match_constraint($table->schema || $table->_schema, $exc_local->{"sch"}, \$captured_sch) and $self->_match_constraint($r_table->schema || $r_table->_schema, $exc_remote->{"sch"}, \$captured_sch) and $self->_match_constraint($table->name, $exc_local->{"tab"}, \$captured) and $self->_match_constraint($col, $exc_local->{"col"}, \$captured) and $self->_match_constraint($r_table->name, $exc_remote->{"tab"}, \$captured) and $self->_match_constraint($r_col, $exc_remote->{"col"}, \$captured) 242 46 288
Condition90%19/21
$self->_match_constraint($table->schema || $table->_schema, $exc_local->{"sch"}, \$captured_sch) and $self->_match_constraint($r_table->schema || $r_table->_schema, $exc_remote->{"sch"}, \$captured_sch) and $self->_match_constraint($table->name, $exc_local->{"tab"}, \$captured) and $self->_match_constraint($col, $exc_local->{"col"}, \$captured) and $self->_match_constraint($r_table->name, $exc_remote->{"tab"}, \$captured) and $self->_match_constraint($r_col, $exc_remote->{"col"}, \$captured)
!ll&&!rl&&r
2231946
$self->_match_constraint($table->schema || $table->_schema, $exc_local->{"sch"}, \$captured_sch) and $self->_match_constraint($r_table->schema || $r_table->_schema, $exc_remote->{"sch"}, \$captured_sch) and $self->_match_constraint($table->name, $exc_local->{"tab"}, \$captured) and $self->_match_constraint($col, $exc_local->{"col"}, \$captured) and $self->_match_constraint($r_table->name, $exc_remote->{"tab"}, \$captured)
!ll&&!rl&&r
1883565
$self->_match_constraint($table->schema || $table->_schema, $exc_local->{"sch"}, \$captured_sch) and $self->_match_constraint($r_table->schema || $r_table->_schema, $exc_remote->{"sch"}, \$captured_sch) and $self->_match_constraint($table->name, $exc_local->{"tab"}, \$captured) and $self->_match_constraint($col, $exc_local->{"col"}, \$captured)
!ll&&!rl&&r
13751100
$self->_match_constraint($table->schema || $table->_schema, $exc_local->{"sch"}, \$captured_sch) and $self->_match_constraint($r_table->schema || $r_table->_schema, $exc_remote->{"sch"}, \$captured_sch) and $self->_match_constraint($table->name, $exc_local->{"tab"}, \$captured)
!ll&&!rl&&r
5285151
$self->_match_constraint($table->schema || $table->_schema, $exc_local->{"sch"}, \$captured_sch) and $self->_match_constraint($r_table->schema || $r_table->_schema, $exc_remote->{"sch"}, \$captured_sch)
!ll&&!rl&&r
2329236
$table->schema || $table->_schema
l!l&&r!l&&!r
051237
$r_table->schema || $r_table->_schema
l!l&&r!l&&!r
051214
MC/DC100%6/6
$self->_match_constraint($table->schema || $table->_schema, $exc_local->{"sch"}, \$captured_sch) and $self->_match_constraint($r_table->schema || $r_table->_schema, $exc_remote->{"sch"}, \$captured_sch) and $self->_match_constraint($table->name, $exc_local->{"tab"}, \$captured) and $self->_match_constraint($col, $exc_local->{"col"}, \$captured) and $self->_match_constraint($r_table->name, $exc_remote->{"tab"}, \$captured) and $self->_match_constraint($r_col, $exc_remote->{"col"}, \$captured)
$self->_match_constraint($table->schema || $table->_schema, $exc_local->{"sch"}, \$captured_sch) $self->_match_constraint($r_table->schema || $r_table->_schema, $exc_remote->{"sch"}, \$captured_sch) $self->_match_constraint($table->name, $exc_local->{"tab"}, \$captured) $self->_match_constraint($col, $exc_local->{"col"}, \$captured) $self->_match_constraint($r_table->name, $exc_remote->{"tab"}, \$captured) $self->_match_constraint($r_col, $exc_remote->{"col"}, \$captured)
MC/DC50%1/2
$table->schema || $table->_schema
$table->schema $table->_schema
MC/DC50%1/2
$r_table->schema || $r_table->_schema
$r_table->schema $r_table->_schema
Truth table100%7/7
A and B and C and D and E and F
A= $self->_match_constraint($table->schema || $table->_schema, $exc_local->{"sch"}, \$captured_sch)B= $self->_match_constraint($r_table->schema || $r_table->_schema, $exc_remote->{"sch"}, \$captured_sch)C= $self->_match_constraint($table->name, $exc_local->{"tab"}, \$captured)D= $self->_match_constraint($col, $exc_local->{"col"}, \$captured)E= $self->_match_constraint($r_table->name, $exc_remote->{"tab"}, \$captured)F= $self->_match_constraint($r_col, $exc_remote->{"col"}, \$captured)
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
Truth table66%2/3
A || B
A= $table->schemaB= $table->_schema
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $r_table->schemaB= $r_table->_schema
ABresult
1X1
011
000
432 );
433 46 push @{ $diag{$rel_con} }, ['matched but excluded', $col, $r_table, $r_col];
434 46 next RCOL;
435 }
436
437 242 push @r_cols, $r_col;
438 }
439
440 @r_cols = sort {
441 # primary or unique key is preferable, basically
442 250 $r_indexes->{$b}{priority} <=> $r_indexes->{$a}{priority}
443 # better than random
444 77 ▶ || $a cmp $b
Condition66%2/3
$r_indexes->{$b}{'priority'} <=> $r_indexes->{$a}{'priority'} || $a cmp $b
l!l&&r!l&&!r
64130
MC/DC0%0/2
$r_indexes->{$b}{'priority'} <=> $r_indexes->{$a}{'priority'} || $a cmp $b
$r_indexes->{$b}{'priority'} <=> $r_indexes->{$a}{'priority'} $a cmp $b
Truth table66%2/3
A || B
A= $r_indexes->{$b}{'priority'} <=> $r_indexes->{$a}{'priority'}B= $a cmp $b
ABresult
1X1
011
000
445 } @r_cols;
446
447 250 ▶ last RTAB if $r_col = shift @r_cols;
Branch: 1 branch
BranchTrueFalseTotal
if $r_col = shift @r_cols 178 72 250
448 }
449
450 463 ▶ next COL if !$r_table;
Branch: 1 branch
BranchTrueFalseTotal
unless $r_table 285 178 463
451
452 @remote_tables = grep {
453 178 $self->_schemas_eq($table, $_) == $self->_schemas_eq($table, $r_table)
454 } @remote_tables;
455
456 178 ▶ if (@remote_tables) {
Branch: 1 branch
BranchTrueFalseTotal
if (@remote_tables) 9 169 178
457 9 my $remote_tables = join ', ', $r_table, @remote_tables;
458 9 ▶ warn "Multiple tables meet the conditions for $table.$col foreign key and have equal priority: $remote_tables; $con_local->{string} => $con_remote->{string}.\n" unless $self->quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quiet 7 2 9
459 9 next COL;
460 }
461
462 169 ▶ next COL if !$r_col;
Branch: 1 branch
BranchTrueFalseTotal
unless $r_col 0 169 169
463
464 @r_cols = grep {
465 169 $r_indexes->{$_}{priority} == $r_indexes->{$r_col}{priority}
466 56 } @r_cols;
467
468 169 ▶ if (@r_cols) {
Branch: 1 branch
BranchTrueFalseTotal
if (@r_cols) 13 156 169
469 13 my $r_cols = join ', ', $r_col, @r_cols;
470 13 ▶ warn "Multiple columns in the referenced table $r_table meet the conditions for $table.$col foreign key and have equal priority: $r_cols; $con_local->{string} => $con_remote->{string}.\n" unless $self->quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quiet 10 3 13
471 13 next COL;
472 }
473
474 push @rels_single, {
475 local_column => $col,
476 local_index => $indexes->{$col},
477 local_is_leftmost => !$con_local->{min_index_priority} || !$indexes->{$col}{position},
478 remote_table => $r_table,
479 remote_column => $r_col,
480 remote_index => $r_indexes->{$r_col},
481 remote_is_leftmost => !$con_remote->{min_index_priority} || !$r_indexes->{$r_col}{position},
482 156 ▶ rel_con => $rel_con,
Condition100%6/6
$con_local->{'min_index_priority'} && $indexes->{$col}{'position'}
!ll&&!rl&&r
399423
$con_remote->{'min_index_priority'} && $r_indexes->{$r_col}{'position'}
!ll&&!rl&&r
276168
MC/DC100%2/2
$con_local->{'min_index_priority'} && $indexes->{$col}{'position'}
$con_local->{'min_index_priority'} $indexes->{$col}{'position'}
MC/DC100%2/2
$con_remote->{'min_index_priority'} && $r_indexes->{$r_col}{'position'}
$con_remote->{'min_index_priority'} $r_indexes->{$r_col}{'position'}
Truth table100%3/3
A && B
A= $con_local->{'min_index_priority'}B= $indexes->{$col}{'position'}
ABresult
0X0
100
111
Truth table100%3/3
A && B
A= $con_remote->{'min_index_priority'}B= $r_indexes->{$r_col}{'position'}
ABresult
0X0
100
111
483 };
484 }
485 }
486
487 # better to process the largest composite indexes first
488 @rels_single = sort {
489 117 $b->{remote_index}{size} <=> $a->{remote_index}{size}
490 || $b->{local_index}{size} <=> $a->{local_index}{size}
491 102 ▶ } @rels_single;
Condition100%3/3
$DBIx::Class::Schema::Loader::DBI::RelPatterns::b->{'remote_index'}{'size'} <=> $DBIx::Class::Schema::Loader::DBI::RelPatterns::a->{'remote_index'}{'size'} || $DBIx::Class::Schema::Loader::DBI::RelPatterns::b->{'local_index'}{'size'} <=> $DBIx::Class::Schema::Loader::DBI::RelPatterns::a->{'local_index'}{'size'}
l!l&&r!l&&!r
303735
MC/DC100%2/2
$DBIx::Class::Schema::Loader::DBI::RelPatterns::b->{'remote_index'}{'size'} <=> $DBIx::Class::Schema::Loader::DBI::RelPatterns::a->{'remote_index'}{'size'} || $DBIx::Class::Schema::Loader::DBI::RelPatterns::b->{'local_index'}{'size'} <=> $DBIx::Class::Schema::Loader::DBI::RelPatterns::a->{'local_index'}{'size'}
$DBIx::Class::Schema::Loader::DBI::RelPatterns::b->{'remote_index'}{'size'} <=> $DBIx::Class::Schema::Loader::DBI::RelPatterns::a->{'remote_index'}{'size'} $DBIx::Class::Schema::Loader::DBI::RelPatterns::b->{'local_index'}{'size'} <=> $DBIx::Class::Schema::Loader::DBI::RelPatterns::a->{'local_index'}{'size'}
Truth table100%3/3
A || B
A= $DBIx::Class::Schema::Loader::DBI::RelPatterns::b->{'remote_index'}{'size'} <=> $DBIx::Class::Schema::Loader::DBI::RelPatterns::a->{'remote_index'}{'size'}B= $DBIx::Class::Schema::Loader::DBI::RelPatterns::b->{'local_index'}{'size'} <=> $DBIx::Class::Schema::Loader::DBI::RelPatterns::a->{'local_index'}{'size'}
ABresult
1X1
011
000
492
493 117 foreach my $rel (@rels_single) {
494 156 ▶ next unless %$rel;
Branch: 1 branch
BranchTrueFalseTotal
unless %$rel 42 114 156
495
496 114 my ($col, $r_table, $r_col, $rel_con) = @$rel{ qw/
497 local_column remote_table remote_column rel_con
498 / };
499
500 114 my (@cols, @r_cols);
501
502 # corresponding columns should form the leftmost prefixes of the indexes
503 114 my $is_leftmost = 0;
504
505 # do not require local_index to be composite as well
506 # because this would require statistics_info method
507 114 ▶ if ($rel->{remote_index}{size} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rel->{"remote_index"}{"size"} > 1) 66 48 114
508 # iterate over columns of the composite index:
509 # this can be done with either local_index or remote_index,
510 # but remote_index is more likely to be unique
511 # and hence not require statistics_info method
512 66 foreach my $r_col (@{ $rel->{remote_index}{cols} }) {
513 120 my $mapped = 0;
514 120 foreach my $rel2 (@rels_single) {
515 # locate the corresponding relationship
516 next unless %$rel2
517 && $rel2->{remote_table}->sql_name eq $r_table->sql_name
518 228 ▶ && $rel2->{remote_column} eq $r_col;
Branch: 1 branch
BranchTrueFalseTotal
unless %$rel2 and $rel2->{"remote_table"}->sql_name eq $r_table->sql_name and $rel2->{"remote_column"} eq $r_col 152 76 228
Condition100%6/6
%$rel2 and $rel2->{"remote_table"}->sql_name eq $r_table->sql_name and $rel2->{"remote_column"} eq $r_col
!ll&&!rl&&r
965676
%$rel2 and $rel2->{"remote_table"}->sql_name eq $r_table->sql_name
!ll&&!rl&&r
7422132
MC/DC100%3/3
%$rel2 and $rel2->{"remote_table"}->sql_name eq $r_table->sql_name and $rel2->{"remote_column"} eq $r_col
%$rel2 $rel2->{"remote_table"}->sql_name eq $r_table->sql_name $rel2->{"remote_column"} eq $r_col
Truth table100%4/4
A and B and C
A= %$rel2B= $rel2->{"remote_table"}->sql_name eq $r_table->sql_nameC= $rel2->{"remote_column"} eq $r_col
ABCresult
0XX0
10X0
1100
1111
519
520 # not sure if any of these are necessary,
521 # commented out for the time being
522 #next unless $rel2->{local_is_leftmost} || $rel2->{local_index}{position} == @cols;
523 #next unless $rel2->{remote_is_leftmost} || $rel2->{remote_index}{position} == @r_cols;
524 # make sure all r_cols are included in this rel's remote_index
525 #my %rel2_index_cols = map {$_ => 1} @{ $rel2->{remote_index}{cols} };
526 #next if grep !$_, @rel2_index_cols{ @r_cols };
527
528 76 push @cols, $rel2->{local_column};
529 76 push @r_cols, $rel2->{remote_column};
530
531 76 $mapped = 1; # first mapped=1 implies remote_is_leftmost
532 76 ▶ $is_leftmost = 1 if $rel2->{local_is_leftmost};
Branch: 1 branch
BranchTrueFalseTotal
if $rel2->{"local_is_leftmost"} 66 10 76
533 76 undef %$rel2; # so this one is processed
534 76 last;
535 }
536
537 # at least the leftmost prefix of the composite index has to be mapped
538 120 ▶ last unless $mapped;
Branch: 1 branch
BranchTrueFalseTotal
unless $mapped 44 76 120
539 }
540 }
541
542 114 ▶ if (!@cols) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@cols) 80 34 114
543 80 @cols = ($col);
544 80 @r_cols = ($r_col);
545 80 ▶ $is_leftmost = 1 if $rel->{local_is_leftmost} && $rel->{remote_is_leftmost};
Branch: 1 branch
BranchTrueFalseTotal
if $rel->{"local_is_leftmost"} and $rel->{"remote_is_leftmost"} 47 33 80
Condition100%3/3
$rel->{"local_is_leftmost"} and $rel->{"remote_is_leftmost"}
!ll&&!rl&&r
132047
MC/DC100%2/2
$rel->{"local_is_leftmost"} and $rel->{"remote_is_leftmost"}
$rel->{"local_is_leftmost"} $rel->{"remote_is_leftmost"}
Truth table100%3/3
A and B
A= $rel->{"local_is_leftmost"}B= $rel->{"remote_is_leftmost"}
ABresult
0X0
100
111
546 }
547
548 114 my $cols = join ',', @cols;
549 114 my $r_cols = join ',', @r_cols;
550
551 114 ▶ unless ($is_leftmost) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_leftmost) 36 78 114
552 36 push @{ $diag{$rel_con} }, ['matched but not leftmost', $cols, $r_table, $r_cols];
553 36 next;
554 }
555
556 78 @cols = map $self->_lc($_), @cols;
557 78 @r_cols = map $self->_lc($_), @r_cols;
558
559 my $is_a_duplicate = grep {
560 78 $r_table->sql_name eq $self->_compat_table($_->{remote_table})->sql_name
561 11 && $#cols <= $#{ $_->{local_columns} }
562 41 ▶ && join("\0", @cols) eq join("\0", @{ $_->{local_columns} }[0..$#cols])
Condition100%6/6
$r_table->sql_name eq $self->_compat_table($_->{'remote_table'})->sql_name && $#cols <= $#{$$_{'local_columns'};} && join("\000", @cols) eq join("\000", @{$$_{'local_columns'};}[0 .. $#cols])
!ll&&!rl&&r
3533
$r_table->sql_name eq $self->_compat_table($_->{"remote_table"})->sql_name and $#cols <= $#{$$_{"local_columns"};}
!ll&&!rl&&r
3056
MC/DC100%3/3
$r_table->sql_name eq $self->_compat_table($_->{'remote_table'})->sql_name && $#cols <= $#{$$_{'local_columns'};} && join("\000", @cols) eq join("\000", @{$$_{'local_columns'};}[0 .. $#cols])
$r_table->sql_name eq $self->_compat_table($_->{"remote_table"})->sql_name $#cols <= $#{$$_{"local_columns"};} join("\000", @cols) eq join("\000", @{$$_{'local_columns'};}[0 .. $#cols])
Truth table100%4/4
A and B && C
A= $r_table->sql_name eq $self->_compat_table($_->{"remote_table"})->sql_nameB= $#cols <= $#{$$_{"local_columns"};}C= join("\000", @cols) eq join("\000", @{$$_{'local_columns'};}[0 .. $#cols])
ABCresult
0XX0
10X0
1100
1111
563 } @$rels;
564
565 78 ▶ if ($is_a_duplicate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_a_duplicate) 3 75 78
566 3 push @{ $diag{$rel_con} }, ['matched but duplicated', $cols, $r_table, $r_cols];
567 3 next;
568 }
569
570 75 ▶ warn sprintf "Relationship matched: %s.%s => %s.%s\n", $table, $cols, $r_table, $r_cols if $self->debug && !$self->quiet;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug and not $self->quiet 0 75 75
Condition33%1/3
$self->debug and not $self->quiet
!ll&&!rl&&r
7500
MC/DC0%0/2
$self->debug and not $self->quiet
$self->debug not $self->quiet
Truth table33%1/3
A and not(B)
A= $self->debugB= not $self->quiet
ABresult
0X0
100
111
571
572 75 push @$rels, {
573 local_columns => \@cols,
574 remote_columns => \@r_cols,
575 remote_table => $r_table,
576 };
577
578 75 undef %$rel; # just in case
579 }
580
581 117 ▶ if (%diag && !$self->quiet) {
Branch: 1 branch
BranchTrueFalseTotal
if (%diag and not $self->quiet) 42 75 117
Condition100%3/3
%diag and not $self->quiet
!ll&&!rl&&r
304542
MC/DC100%2/2
%diag and not $self->quiet
%diag not $self->quiet
Truth table100%3/3
A and not(B)
A= %diagB= not $self->quiet
ABresult
0X0
100
111
582 42 foreach my $rel_con (@$rel_constraint) {
583 152 my ($con_local, $con_remote) = @$rel_con;
584
585 152 ▶ next unless $con_remote->{diag};
Branch: 1 branch
BranchTrueFalseTotal
unless $con_remote->{"diag"} 152 0 152
586
587 0 ▶ my $diag = $diag{$rel_con} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $diag = $diag{$rel_con} or next 0 0 0
588
589 my $diagnostics = join '', map {
590 0 my ($message, $col, $r_table, $r_col) = @$_;
591 0 sprintf " - %-24s: %s.%s => %s.%s\n", $message, $table, $col, $r_table, $r_col;
592 } @$diag;
593
594 0 ▶ warn $table->dbic_name . ", diagnostics for rel_constraint: $con_local->{string} => $con_remote->{string}\n" . $diagnostics if $diagnostics;
Branch: 1 branch
BranchTrueFalseTotal
if $diagnostics 0 0 0
595 }
596 }
597
598 117 return $self->{_cache}{_table_fk_info}{$table->sql_name} = $rels;
599 }
600  
601  
602 # adapted from DBIx::Class::Schema::Loader::DBI::_table_uniq_info()
603 # with unique_only in statistics_info call set to undef instead of 1
604 370 ▶sub _table_indexes_info {
Subroutine _table_indexes_info: called CC=15 SCAR=30.0
605 370 my $self = shift;
606 370 my ($table) = @_;
607
608 370 ▶ return $self->next::method(@_) if $self->{_relpat_inherit} && $self->next::can;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_relpat_inherit"} and $self->next::can 1 369 370
Condition100%3/3
$self->{"_relpat_inherit"} and $self->next::can
!ll&&!rl&&r
36631
MC/DC100%2/2
$self->{"_relpat_inherit"} and $self->next::can
$self->{"_relpat_inherit"} $self->next::can
Truth table100%3/3
A and B
A= $self->{"_relpat_inherit"}B= $self->next::can
ABresult
0X0
100
111
609
610 369 ▶ return [] if $self->_disable_uniq_detection;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_disable_uniq_detection 82 287 369
611
612 287 ▶ if (my $cached = $self->{_cache}{_table_indexes_info}{$table->sql_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cached = $self->{"_cache"}{"_table_indexes_info"}{$table->sql_name}) 200 87 287
613 200 return $cached;
614 }
615
616 87 ▶ if (not $self->dbh->can('statistics_info')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->dbh->can("statistics_info")) 0 87 87
617 0 ▶ warn "RelPatterns loader class is unable to obtain the non-unique index information with " . $self->dbh->{Driver}->{Name} . " driver.\n" unless $self->quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quiet 0 0 0
618 0 $self->_disable_uniq_detection(1);
619 0 return [];
620 }
621  
622 87 my %indices;
623 87 my $sth = $self->dbh->statistics_info(undef, $table->schema, $table->name, undef, 1);
624 87 ▶ while(my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 521 87 608
625 # skip table-level stats, conditional indexes, and any index missing
626 # critical fields
627 next if $row->{TYPE} eq 'table'
628 || defined $row->{FILTER_CONDITION}
629 || !$row->{INDEX_NAME}
630 521 ▶ || !defined $row->{ORDINAL_POSITION};
Branch: 1 branch
BranchTrueFalseTotal
if $row->{"TYPE"} eq "table" or defined $row->{"FILTER_CONDITION"} or not $row->{"INDEX_NAME"} or not defined $row->{"ORDINAL_POSITION"} 0 521 521
Condition33%3/9
$row->{"TYPE"} eq "table" or defined $row->{"FILTER_CONDITION"} or not $row->{"INDEX_NAME"} or not defined $row->{"ORDINAL_POSITION"}
l!l&&r!l&&!r
00521
$row->{"TYPE"} eq "table" or defined $row->{"FILTER_CONDITION"} or not $row->{"INDEX_NAME"}
l!l&&r!l&&!r
00521
$row->{"TYPE"} eq "table" or defined $row->{"FILTER_CONDITION"}
l!l&&r!l&&!r
00521
MC/DC0%0/4
$row->{"TYPE"} eq "table" or defined $row->{"FILTER_CONDITION"} or not $row->{"INDEX_NAME"} or not defined $row->{"ORDINAL_POSITION"}
$row->{"TYPE"} eq "table" defined $row->{"FILTER_CONDITION"} not $row->{"INDEX_NAME"} not defined $row->{"ORDINAL_POSITION"}
Truth table20%1/5
A or B or not(C) or not(D)
A= $row->{"TYPE"} eq "table"B= defined $row->{"FILTER_CONDITION"}C= not $row->{"INDEX_NAME"}D= not defined $row->{"ORDINAL_POSITION"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
631  
632 521 ▶ $indices{$row->{INDEX_NAME}}[$row->{ORDINAL_POSITION}] = $self->_lc($row->{COLUMN_NAME} || '');
Condition50%1/2
$row->{'COLUMN_NAME'} || ''
l!l
5210
MC/DC0%0/1
$row->{'COLUMN_NAME'} || ''
$row->{'COLUMN_NAME'}
Truth table50%1/2
A
A= $row->{'COLUMN_NAME'}
Aresult
11
00
633 }
634 87 $sth->finish;
635  
636 87 my @retval;
637 87 foreach my $index_name (sort keys %indices) {
638 376 my (undef, @cols) = @{$indices{$index_name}};
639 # skip indexes with missing column names (e.g. expression indexes)
640 376 ▶ next unless @cols == grep $_, @cols;
Branch: 1 branch
BranchTrueFalseTotal
unless @cols == grep($_, @cols) 0 376 376
641 376 push(@retval, [ $index_name => \@cols ]);
642 }
643
644 87 return $self->{_cache}{_table_indexes_info}{$table->sql_name} = \@retval;
645 }
646  
647  
648 # a bit of caching to reduce the number of queries
649  
650 519 ▶sub _columns_info_for {
Subroutine _columns_info_for: called CC=2 SCAR=7.0
651 519 my $self = shift;
652 519 my $table = $self->_compat_table(shift);
653 519 ▶ return $self->{_cache}{_columns_info_for}{$table->sql_name} ||= $self->next::method($table);
Condition66%2/3
$self->{"_cache"}{"_columns_info_for"}{$table->sql_name} ||= $self->next::method($table)
l!l&&r!l&&!r
3701490
MC/DC0%0/2
$self->{"_cache"}{"_columns_info_for"}{$table->sql_name} ||= $self->next::method($table)
$self->{"_cache"}{"_columns_info_for"}{$table->sql_name} $self->next::method($table)
Truth table66%2/3
A ||= B
A= $self->{"_cache"}{"_columns_info_for"}{$table->sql_name}B= $self->next::method($table)
ABresult
1X1
011
000
654 }
655  
656 520 ▶sub _table_columns {
Subroutine _table_columns: called CC=2 SCAR=7.0
657 520 my $self = shift;
658 520 my $table = $self->_compat_table(shift);
659 519 ▶ return $self->{_cache}{_table_columns}{$table->sql_name} ||= $self->next::method($table);
Condition66%2/3
$self->{"_cache"}{"_table_columns"}{$table->sql_name} ||= $self->next::method($table)
l!l&&r!l&&!r
3701490
MC/DC0%0/2
$self->{"_cache"}{"_table_columns"}{$table->sql_name} ||= $self->next::method($table)
$self->{"_cache"}{"_table_columns"}{$table->sql_name} $self->next::method($table)
Truth table66%2/3
A ||= B
A= $self->{"_cache"}{"_table_columns"}{$table->sql_name}B= $self->next::method($table)
ABresult
1X1
011
000
660 }
661  
662 514 ▶sub _table_pk_info {
Subroutine _table_pk_info: called CC=2 SCAR=7.0
663 514 my $self = shift;
664 514 my $table = $self->_compat_table(shift);
665 514 ▶ return $self->{_cache}{_table_pk_info}{$table->sql_name} ||= $self->next::method($table);
Condition66%2/3
$self->{"_cache"}{"_table_pk_info"}{$table->sql_name} ||= $self->next::method($table)
l!l&&r!l&&!r
3661480
MC/DC0%0/2
$self->{"_cache"}{"_table_pk_info"}{$table->sql_name} ||= $self->next::method($table)
$self->{"_cache"}{"_table_pk_info"}{$table->sql_name} $self->next::method($table)
Truth table66%2/3
A ||= B
A= $self->{"_cache"}{"_table_pk_info"}{$table->sql_name}B= $self->next::method($table)
ABresult
1X1
011
000
666 }
667  
668 658 ▶sub _table_uniq_info {
Subroutine _table_uniq_info: called CC=2 SCAR=7.0
669 658 my $self = shift;
670 658 my $table = $self->_compat_table(shift);
671 658 ▶ return $self->{_cache}{_table_uniq_info}{$table->sql_name} ||= $self->next::method($table);
Condition66%2/3
$self->{"_cache"}{"_table_uniq_info"}{$table->sql_name} ||= $self->next::method($table)
l!l&&r!l&&!r
5101480
MC/DC0%0/2
$self->{"_cache"}{"_table_uniq_info"}{$table->sql_name} ||= $self->next::method($table)
$self->{"_cache"}{"_table_uniq_info"}{$table->sql_name} $self->next::method($table)
Truth table66%2/3
A ||= B
A= $self->{"_cache"}{"_table_uniq_info"}{$table->sql_name}B= $self->next::method($table)
ABresult
1X1
011
000
672 }
673  
674  
675 # compatibility stuff
676  
677 12 ▶if ($DBIx::Class::Schema::Loader::DBI::VERSION < 0.07011 && !__PACKAGE__->can('quiet')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DBIx::Class::Schema::Loader::DBI::VERSION < "0.07011" and not __PACKAGE__->can("quiet")) 0 12 12
Condition33%1/3
$DBIx::Class::Schema::Loader::DBI::VERSION < "0.07011" and not __PACKAGE__->can("quiet")
!ll&&!rl&&r
1200
MC/DC0%0/2
$DBIx::Class::Schema::Loader::DBI::VERSION < "0.07011" and not __PACKAGE__->can("quiet")
$DBIx::Class::Schema::Loader::DBI::VERSION < "0.07011" not __PACKAGE__->can("quiet")
Truth table33%1/3
A and not(B)
A= $DBIx::Class::Schema::Loader::DBI::VERSION < "0.07011"B= not __PACKAGE__->can("quiet")
ABresult
0X0
100
111
678 0 __PACKAGE__->mk_group_ro_accessors('simple', 'quiet');
679 }
680  
681 3747 ▶sub _lc {
Subroutine _lc: called CC=3 SCAR=13.3
682 3747 my $self = shift;
683 3747 ▶ if ($DBIx::Class::Schema::Loader::DBI::VERSION < 0.07000 && !$self->next::can) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DBIx::Class::Schema::Loader::DBI::VERSION < "0.07" and not $self->next::can) 0 3747 3747
Condition33%1/3
$DBIx::Class::Schema::Loader::DBI::VERSION < "0.07" and not $self->next::can
!ll&&!rl&&r
374700
MC/DC0%0/2
$DBIx::Class::Schema::Loader::DBI::VERSION < "0.07" and not $self->next::can
$DBIx::Class::Schema::Loader::DBI::VERSION < "0.07" not $self->next::can
Truth table33%1/3
A and not(B)
A= $DBIx::Class::Schema::Loader::DBI::VERSION < "0.07"B= not $self->next::can
ABresult
0X0
100
111
684 0 return lc shift;
685 }
686 3747 return $self->next::method(@_);
687 }
688  
689 4109 ▶sub dbh {
Subroutine dbh: called CC=3 SCAR=13.3
Pod undocumented
690 4109 my $self = shift;
691 4109 ▶ if ($DBIx::Class::Schema::Loader::DBI::VERSION < 0.07011 && !$self->next::can) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DBIx::Class::Schema::Loader::DBI::VERSION < "0.07011" and not $self->next::can) 0 4109 4109
Condition33%1/3
$DBIx::Class::Schema::Loader::DBI::VERSION < "0.07011" and not $self->next::can
!ll&&!rl&&r
410900
MC/DC0%0/2
$DBIx::Class::Schema::Loader::DBI::VERSION < "0.07011" and not $self->next::can
$DBIx::Class::Schema::Loader::DBI::VERSION < "0.07011" not $self->next::can
Truth table33%1/3
A and not(B)
A= $DBIx::Class::Schema::Loader::DBI::VERSION < "0.07011"B= not $self->next::can
ABresult
0X0
100
111
692 0 return $self->schema->storage->dbh;
693 }
694 4109 return $self->next::method(@_);
695 }
696  
697 3513 ▶sub _compat_table {
Subroutine _compat_table: called CC=5 SCAR=16.8
698 3513 my $self = shift;
699 3513 my ($table) = @_;
700 3513 ▶ return $self->next::method(@_) if $self->{_relpat_inherit} && $self->next::can;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_relpat_inherit"} and $self->next::can 1 3512 3513
Condition100%3/3
$self->{"_relpat_inherit"} and $self->next::can
!ll&&!rl&&r
3476361
MC/DC100%2/2
$self->{"_relpat_inherit"} and $self->next::can
$self->{"_relpat_inherit"} $self->next::can
Truth table100%3/3
A and B
A= $self->{"_relpat_inherit"}B= $self->next::can
ABresult
0X0
100
111
701 3512 ▶ if ($DBIx::Class::Schema::Loader::DBI::VERSION < 0.07011 && !ref $table) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DBIx::Class::Schema::Loader::DBI::VERSION < "0.07011" and not ref $table) 0 3512 3512
Condition33%1/3
$DBIx::Class::Schema::Loader::DBI::VERSION < "0.07011" and not ref $table
!ll&&!rl&&r
351200
MC/DC0%0/2
$DBIx::Class::Schema::Loader::DBI::VERSION < "0.07011" and not ref $table
$DBIx::Class::Schema::Loader::DBI::VERSION < "0.07011" not ref $table
Truth table33%1/3
A and not(B)
A= $DBIx::Class::Schema::Loader::DBI::VERSION < "0.07011"B= not ref $table
ABresult
0X0
100
111
702 0 return DBIx::Class::Schema::Loader::DBI::RelPatterns::TableCompat->new($table);
703 }
704 3512 return $table;
705 }
706  
707 package # hide from PAUSE
708 DBIx::Class::Schema::Loader::DBI::RelPatterns::TableCompat;
709  
710 0 ▶use overload '""' => sub { $_[0]->name }, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
711  
712 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
713 0 my $class = shift;
714 0 return bless { name => shift }, $class;
715 }
716  
717 0 ▶sub schema { undef }
Subroutine schema: not called CC=1 SCAR=6.9
718 0 ▶sub _schema { undef }
Subroutine _schema: not called CC=1 SCAR=6.9
719 0 ▶sub name { $_[0]->{name} }
Subroutine name: not called CC=1 SCAR=6.9
720 0 ▶sub sql_name { $_[0]->{name} }
Subroutine sql_name: not called CC=1 SCAR=6.9
721 0 ▶sub dbic_name { $_[0]->{name} }
Subroutine dbic_name: not called CC=1 SCAR=6.9
722  
723 12 1;
724  
725 __END__
↑ Summary