| 1 | package DBIO::Diff::Compare; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Engine-agnostic comparison helpers for DBIO diff operations | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||
| 12 | norm norm_type arr_differ changed_fields | ||||||||||||||||||||||||||||||||||||||||||
| 13 | changed_column_fields changed_index_fields changed_fk_fields | ||||||||||||||||||||||||||||||||||||||||||
| 14 | column_change_lossy | ||||||||||||||||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 54 | ▶ | sub norm { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
norm: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 54 | my ($v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 54 | ▶ | return defined $v ? $v : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 92 | ▶ | sub norm_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
norm_type: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 92 | my ($t) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 92 | ▶ | return '' unless defined $t; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 91 | $t =~ s/\s+/ /g; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 91 | $t =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 91 | $t =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 91 | return uc $t; | |||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 25 | ▶ | sub arr_differ { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
arr_differ: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 25 | my ($a, $b) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 25 | ▶ | $a = ref($a) eq 'ARRAY' ? $a : []; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 25 | ▶ | $b = ref($b) eq 'ARRAY' ? $b : []; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 25 | ▶ | return 1 if scalar(@$a) != scalar(@$b); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 24 | my @sa = sort @$a; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 24 | my @sb = sort @$b; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 24 | for my $i (0 .. $#sa) { | |||||||||||||||||||||||||||||||||||||||||
| 42 | 29 | ▶ | return 1 if $sa[$i] ne $sb[$i]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 23 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # Internal: stringify a scalar-or-arrayref into an ORDER-PRESERVING key, for | ||||||||||||||||||||||||||||||||||||||||||
| 48 | # 'dim' fields where order is significant ([precision, scale], ordered columns). | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 14 | ▶ | sub _dim_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dim_key: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 14 | my ($v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 14 | ▶ | return join ',', map { defined $_ ? $_ : "\0" } @$v if ref($v) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 10 | return norm($v); | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 49 | ▶ | sub changed_fields { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
changed_fields: called CC=29 SCAR=33.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 49 | my ($old, $new, %spec) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 58 | # desired_state is the always-on contract now (any non-bool field the target | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # leaves undef is ignored); the key is accepted but vestigial. See DESCRIPTION. | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 49 | delete $spec{desired_state}; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 49 | ▶ | $old ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$old ||= {}
MC/DC0%0/1
$old ||= {}
$old
Truth table50%1/2
A
A= $old
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 49 | ▶ | $new ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$new ||= {}
MC/DC0%0/1
$new ||= {}
$new
Truth table50%1/2
A
A= $new
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 49 | my @changed; | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | # Desired-state contract: a non-bool field the target ($new) leaves undef is a | ||||||||||||||||||||||||||||||||||||||||||
| 67 | # "don't care" -- the desired state did not prescribe it, so whatever the live | ||||||||||||||||||||||||||||||||||||||||||
| 68 | # database reports for it is left alone. Skip it from comparison entirely. | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 122 | ▶ | my $skip = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 122 | my ($field) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 122 | return !defined $new->{$field}; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 49 | }; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 49 | ▶ | for my $field (@{ $spec{scalar} || [] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$spec{'scalar'} || []
MC/DC100%1/1
$spec{'scalar'} || []
$spec{'scalar'}
Truth table100%2/2
A
A= $spec{'scalar'}
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 59 | ▶ | next if $skip->($field); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 18 | ▶ | push @changed, $field if norm($old->{$field}) ne norm($new->{$field}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 49 | ▶ | for my $field (@{ $spec{type} || [] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$spec{'type'} || []
MC/DC100%1/1
$spec{'type'} || []
$spec{'type'}
Truth table100%2/2
A
A= $spec{'type'}
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 22 | ▶ | next if $skip->($field); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 22 | ▶ | push @changed, $field if norm_type($old->{$field}) ne norm_type($new->{$field}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 49 | ▶ | for my $field (@{ $spec{bool} || [] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$spec{'bool'} || []
MC/DC100%1/1
$spec{'bool'} || []
$spec{'bool'}
Truth table100%2/2
A
A= $spec{'bool'}
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 17 | ▶ | push @changed, $field if (($old->{$field} // 0) <=> ($new->{$field} // 0)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%4/4
$old->{$field} // 0
$new->{$field} // 0
MC/DC100%1/1
$old->{$field} // 0
$old->{$field}
MC/DC100%1/1
$new->{$field} // 0
$new->{$field}
Truth table100%2/2
A
A= $old->{$field}
Truth table100%2/2
A
A= $new->{$field}
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 49 | ▶ | for my $field (@{ $spec{dim} || [] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$spec{'dim'} || []
MC/DC100%1/1
$spec{'dim'} || []
$spec{'dim'}
Truth table100%2/2
A
A= $spec{'dim'}
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 20 | ▶ | next if $skip->($field); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 7 | ▶ | push @changed, $field if _dim_key($old->{$field}) ne _dim_key($new->{$field}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 49 | ▶ | for my $field (@{ $spec{array} || [] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$spec{'array'} || []
MC/DC100%1/1
$spec{'array'} || []
$spec{'array'}
Truth table100%2/2
A
A= $spec{'array'}
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 21 | ▶ | next if $skip->($field); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 21 | ▶ | push @changed, $field if arr_differ($old->{$field}, $new->{$field}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 49 | ▶ | for my $field (@{ $spec{mutual} || [] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$spec{'mutual'} || []
MC/DC100%1/1
$spec{'mutual'} || []
$spec{'mutual'}
Truth table100%2/2
A
A= $spec{'mutual'}
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | # Bilateral: a difference only when BOTH sides carry a value. undef on | ||||||||||||||||||||||||||||||||||||||||||
| 95 | # either side means that participant has no opinion (e.g. a driver that | ||||||||||||||||||||||||||||||||||||||||||
| 96 | # does not introspect index_type), so it is never a change -- a typeless | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # driver produces no phantom diff. Compared as a type token. ADR 0052. | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 17 | ▶ | next unless defined $old->{$field} && defined $new->{$field}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $old->{$field} and defined $new->{$field}
MC/DC100%2/2
defined $old->{$field} and defined $new->{$field}
defined $old->{$field}
defined $new->{$field}
Truth table100%3/3
A and B
A= defined $old->{$field}B= defined $new->{$field}
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 6 | ▶ | push @changed, $field if norm_type($old->{$field}) ne norm_type($new->{$field}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 49 | return @changed; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | # Internal: true when a live default value is a real default. An absent one and | ||||||||||||||||||||||||||||||||||||||||||
| 107 | # a literal NULL (plain or as a \'NULL' ref) are none. | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 19 | ▶ | sub _has_default { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_has_default: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 19 | my ($v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 19 | ▶ | $v = $$v if ref($v) eq 'SCALAR' || ref($v) eq 'REF'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $v eq "SCALAR" or ref $v eq "REF"
MC/DC50%1/2
ref $v eq "SCALAR" or ref $v eq "REF"
ref $v eq "SCALAR"
ref $v eq "REF"
Truth table66%2/3
A or B
A= ref $v eq "SCALAR"B= ref $v eq "REF"
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 19 | ▶ | return defined $v && uc(norm($v)) ne 'NULL' ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $v and uc norm($v) ne "NULL"
MC/DC100%2/2
defined $v and uc norm($v) ne "NULL"
defined $v
uc norm($v) ne "NULL"
Truth table100%3/3
A and B
A= defined $vB= uc norm($v) ne "NULL"
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 19 | ▶ | sub changed_column_fields { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
changed_column_fields: called CC=11 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 19 | my ($old, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 19 | ▶ | $old ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$old ||= {}
MC/DC0%0/1
$old ||= {}
$old
Truth table50%1/2
A
A= $old
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 19 | ▶ | $new ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$new ||= {}
MC/DC0%0/1
$new ||= {}
$new
Truth table50%1/2
A
A= $new
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 19 | my @changed = changed_fields($old, $new, | |||||||||||||||||||||||||||||||||||||||||
| 119 | type => ['data_type'], | ||||||||||||||||||||||||||||||||||||||||||
| 120 | scalar => ['not_null', 'default_value'], | ||||||||||||||||||||||||||||||||||||||||||
| 121 | dim => ['size'], | ||||||||||||||||||||||||||||||||||||||||||
| 122 | desired_state => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 124 | # A default the target no longer declares is a change: the live column | ||||||||||||||||||||||||||||||||||||||||||
| 125 | # carries one (a live DEFAULT NULL is none), the target leaves it undef. | ||||||||||||||||||||||||||||||||||||||||||
| 126 | # Placed where the scalar pass puts default_value, after not_null. | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 19 | ▶ | if (!defined $new->{default_value} && _has_default($old->{default_value})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $new->{"default_value"} and _has_default($old->{"default_value"})
MC/DC50%1/2
not defined $new->{"default_value"} and _has_default($old->{"default_value"})
not defined $new->{"default_value"}
_has_default($old->{"default_value"})
Truth table66%2/3
not(A) and B
A= not defined $new->{"default_value"}B= _has_default($old->{"default_value"})
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 3 | my $at = (grep { $changed[$_] eq 'not_null' } 0 .. $#changed)[0]; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 3 | ▶ | splice @changed, defined $at ? $at + 1 : 0, 0, 'default_value'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | # is_auto_increment follows the desired-state rule (a target that leaves it | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # undef prescribes nothing), but a prescribed flag compares as a bool: an | ||||||||||||||||||||||||||||||||||||||||||
| 133 | # explicit 0 equals a live column that carries no flag. | ||||||||||||||||||||||||||||||||||||||||||
| 134 | push @changed, 'is_auto_increment' | ||||||||||||||||||||||||||||||||||||||||||
| 135 | if defined $new->{is_auto_increment} | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 19 | ▶ | && (($old->{is_auto_increment} // 0) ? 1 : 0) != ($new->{is_auto_increment} ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%5/5
defined $new->{"is_auto_increment"} and ($old->{"is_auto_increment"} // 0 ? 1 : 0) != ($new->{"is_auto_increment"} ? 1 : 0)
$old->{"is_auto_increment"} // 0
MC/DC100%2/2
defined $new->{"is_auto_increment"} and ($old->{"is_auto_increment"} // 0 ? 1 : 0) != ($new->{"is_auto_increment"} ? 1 : 0)
defined $new->{"is_auto_increment"}
$old->{"is_auto_increment"}
Truth table100%3/3
A and B
A= defined $new->{"is_auto_increment"}B= $old->{"is_auto_increment"}
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 19 | return @changed; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | # Internal: the components of a size as a list of numbers, or undef when the | ||||||||||||||||||||||||||||||||||||||||||
| 142 | # value is absent or not numeric. | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 18 | ▶ | sub _size_parts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_size_parts: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 18 | my ($v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 18 | ▶ | return undef unless defined $v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 17 | ▶ | my @p = ref($v) eq 'ARRAY' ? @$v : split /\s*,\s*/, $v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 17 | s/^\s+|\s+$//g for grep { defined } @p; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 17 | ▶ | @p = grep { defined $_ && length $_ } @p; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $_ && length $_
MC/DC0%0/2
defined $_ && length $_
defined $_
length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 17 | ▶ | return undef unless @p; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 17 | ▶ | return undef if grep { !/\A[0-9]+\z/ } @p; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 17 | return \@p; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 17 | ▶ | sub column_change_lossy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
column_change_lossy: called CC=17 SCAR=28.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 17 | my ($old, $new, $pairs) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 17 | ▶ | $old ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$old ||= {}
MC/DC0%0/1
$old ||= {}
$old
Truth table50%1/2
A
A= $old
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 17 | ▶ | $new ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$new ||= {}
MC/DC0%0/1
$new ||= {}
$new
Truth table50%1/2
A
A= $new
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 17 | ▶ | $pairs ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$pairs ||= {}
MC/DC100%1/1
$pairs ||= {}
$pairs
Truth table100%2/2
A
A= $pairs
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 17 | my $ot = lc norm_type($old->{data_type}); | |||||||||||||||||||||||||||||||||||||||||
| 161 | 17 | ▶ | my $nt = defined $new->{data_type} ? lc norm_type($new->{data_type}) : $ot; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 17 | ▶ | if ($ot ne $nt) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 5 | ▶ | return $pairs->{"$ot->$nt"} ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 12 | ▶ | return 0 unless defined $new->{size}; # prescribes nothing | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 9 | my $np = _size_parts($new->{size}); | |||||||||||||||||||||||||||||||||||||||||
| 169 | 9 | my $op = _size_parts($old->{size}); | |||||||||||||||||||||||||||||||||||||||||
| 170 | 9 | ▶ | return 0 if !defined $op && !defined $np && norm($old->{size}) eq norm($new->{size}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not defined $op || defined $np and norm($old->{"size"}) eq norm($new->{"size"})
defined $op || defined $np
MC/DC0%0/3
not defined $op || defined $np and norm($old->{"size"}) eq norm($new->{"size"})
defined $op
defined $np
norm($old->{"size"}) eq norm($new->{"size"})
Truth table50%2/4
not(A || B) and C
A= defined $opB= defined $npC= norm($old->{"size"}) eq norm($new->{"size"})
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 9 | ▶ | return 1 unless defined $op && defined $np; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $op and defined $np
MC/DC50%1/2
defined $op and defined $np
defined $op
defined $np
Truth table66%2/3
A and B
A= defined $opB= defined $np
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 8 | ▶ | return 1 if @$op != @$np; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 7 | for my $i (0 .. $#$np) { | |||||||||||||||||||||||||||||||||||||||||
| 174 | 10 | ▶ | return 1 if $i == 1 ? $np->[$i] != $op->[$i] : $np->[$i] < $op->[$i]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 12 | ▶ | sub changed_index_fields { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
changed_index_fields: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 12 | my ($old, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 12 | return changed_fields($old, $new, | |||||||||||||||||||||||||||||||||||||||||
| 183 | bool => ['is_unique'], | ||||||||||||||||||||||||||||||||||||||||||
| 184 | array => ['columns'], | ||||||||||||||||||||||||||||||||||||||||||
| 185 | mutual => ['index_type'], | ||||||||||||||||||||||||||||||||||||||||||
| 186 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 4 | ▶ | sub changed_fk_fields { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
changed_fk_fields: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 4 | my ($old, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 4 | return changed_fields($old, $new, | |||||||||||||||||||||||||||||||||||||||||
| 193 | scalar => ['to_table', 'on_update', 'on_delete'], | ||||||||||||||||||||||||||||||||||||||||||
| 194 | array => ['from_columns', 'to_columns'], | ||||||||||||||||||||||||||||||||||||||||||
| 195 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | __END__ | ||||||||||||||||||||||||||||||||||||||||||