blib/lib/DBIO/Diff/Base.pm

filter: Statementstmt 100% 58 / 58 Branchbran 88.8% 16 / 18 Conditioncond 92.0% 23 / 25 MC/DCmcdc 84.6% 11 / 13 Subroutinesub 100% 15 / 15 Podpod 100% 11 / 11 totaltotal 95.7% 134 / 140 CC 21 SCAR 19.7
CC
21
Cov
96%
classify
14.0
destructive_operations
6.1
operations
2.0
CRAP 7.2
« blib/lib/DBIO/PK.pm ↑ Summary blib/lib/DBIO/Test/Schema/Track.pm »
1 package DBIO::Diff::Base;
2 # ABSTRACT: Base class for DBIO driver diff orchestrators
3  
4 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 15 our $VERSION = '0.900007';
8  
9 15 our $CONTRACT_VERSION = '1.3';
10  
11  
12  
13 2 ▶sub contract_version { $CONTRACT_VERSION }
Subroutine contract_version: called CC=1 SCAR=0.0
Pod documented
14  
15  
16 78 ▶sub new { my ($class, %args) = @_; bless \%args, $class }
Subroutine new: called CC=1 SCAR=0.0
Pod documented
17  
18  
19 2 ▶sub diff_options { () }
Subroutine diff_options: called CC=1 SCAR=0.0
Pod documented
20  
21 1 ▶sub source { $_[0]->{source} }
Subroutine source: called CC=1 SCAR=0.0
Pod documented
22  
23  
24 1 ▶sub target { $_[0]->{target} }
Subroutine target: called CC=1 SCAR=0.0
Pod documented
25  
26  
27 201 ▶sub operations { $_[0]->{operations} //= $_[0]->_build_operations }
Subroutine operations: called CC=2 SCAR=6.9
Pod documented
Condition100%3/3
$_[0]{"operations"} //= $_[0]->_build_operations
l!l&&r!l&&!r
133671
MC/DC100%2/2
$_[0]{"operations"} //= $_[0]->_build_operations
$_[0]{"operations"} $_[0]->_build_operations
Truth table100%3/3
A //= B
A= $_[0]{"operations"}B= $_[0]->_build_operations
ABresult
1X1
011
000
28  
29  
30 1 ▶sub _build_operations {
Subroutine _build_operations: called CC=1 SCAR=0.0
31 1 my ($self) = @_;
32 1 die ref($self) . '::_build_operations not implemented';
33 }
34  
35  
36 78 ▶sub has_changes {
Subroutine has_changes: called CC=1 SCAR=0.0
Pod documented
37 78 my ($self) = @_;
38 78 return scalar @{ $self->operations } > 0;
39 }
40  
41  
42 34 ▶sub as_sql {
Subroutine as_sql: called CC=1 SCAR=0.0
Pod documented
43 34 my ($self) = @_;
44 34 return join "\n", map { $_->as_sql } @{ $self->operations };
45 }
46  
47  
48 3 ▶sub summary {
Subroutine summary: called CC=1 SCAR=0.0
Pod documented
49 3 my ($self) = @_;
50 3 return join "\n", map { $_->summary } @{ $self->operations };
51 }
52  
53  
54 60 ▶sub classify {
Subroutine classify: called CC=14 SCAR=26.4
Pod documented
55 60 my ($self) = @_;
56  
57 60 my $ops = $self->operations;
58 60 my %counts = (additive => 0, changing => 0, destructive => 0);
59 60 my @refused;
60  
61 60 for my $op (@$ops) {
62 101 ▶ my $action = $op->can('action') ? $op->action : undef;
Branch: 1 branch
BranchTrueFalseTotal
$op->can('action') ? : 101 0 101
63 101 ▶ $action //= '';
Condition100%2/2
$action //= ""
l!l
1001
MC/DC100%1/1
$action //= ""
$action
Truth table100%2/2
A
A= $action
Aresult
11
00
64  
65 101 ▶ if ($action eq 'refuse') {
Branch: 3 branches
BranchTrueFalseTotal
if ($action eq 'refuse') { } 8 93 101
elsif ($action eq 'create' or $action eq 'add' or $action eq 'add_value') { } 27 66 93
elsif ($action eq 'drop') { } 31 35 66
66 8 push @refused, $op->summary;
67 }
68 ▶ elsif ($action eq 'create' || $action eq 'add' || $action eq 'add_value') {
Condition100%6/6
$action eq "create" or $action eq "add" or $action eq "add_value"
l!l&&r!l&&!r
26166
$action eq "create" or $action eq "add"
l!l&&r!l&&!r
25167
MC/DC100%3/3
$action eq "create" or $action eq "add" or $action eq "add_value"
$action eq "create" $action eq "add" $action eq "add_value"
Truth table100%4/4
A or B or C
A= $action eq "create"B= $action eq "add"C= $action eq "add_value"
ABCresult
1XX1
01X1
0011
0000
69 27 $counts{additive}++;
70 }
71 elsif ($action eq 'drop') {
72 31 ▶ if (_op_is_destructive($op)) { $counts{destructive}++ }
Branch: 1 branch
BranchTrueFalseTotal
if (_op_is_destructive($op)) { } 29 2 31
73 2 else { $counts{changing}++ }
74 }
75 else {
76 35 $counts{changing}++;
77 }
78 }
79  
80 60 ▶ my $result = {
Branch: 1 branch
BranchTrueFalseTotal
@$ops ? : 55 5 60
81 has_changes => (@$ops ? 1 : 0),
82 class => undef,
83 counts => undef,
84 refused => \@refused,
85 };
86 60 ▶ return $result if @refused;
Branch: 1 branch
BranchTrueFalseTotal
if @refused 7 53 60
87  
88 53 my $class = 'none';
89 53 for my $c (qw(additive changing destructive)) {
90 159 ▶ $class = $c if $counts{$c};
Branch: 1 branch
BranchTrueFalseTotal
if $counts{$c} 72 87 159
91 }
92 53 @$result{qw(class counts)} = ($class, \%counts);
93 53 return $result;
94 }
95  
96 # A drop is destructive unless it is the first half of a drop plus create.
97 43 ▶sub _op_is_destructive {
Subroutine _op_is_destructive: called CC=2 SCAR=6.9
98 43 my ($op) = @_;
99 43 ▶ return !($op->can('replaced') && $op->replaced);
Condition100%3/3
$op->can('replaced') && $op->replaced
!ll&&!rl&&r
12283
MC/DC100%2/2
$op->can('replaced') && $op->replaced
$op->can('replaced') $op->replaced
Truth table100%3/3
A && B
A= $op->can('replaced')B= $op->replaced
ABresult
0X0
100
111
100 }
101  
102  
103 31 ▶sub destructive_operations {
Subroutine destructive_operations: called CC=6 SCAR=18.2
Pod documented
104 31 my ($self) = @_;
105 return grep {
106 38 my $op = $_;
107 38 ▶ my $action = $op->can('action') ? ($op->action // '') : '';
Branch: 1 branch
BranchTrueFalseTotal
$op->can('action') ? : 38 0 38
Condition50%1/2
$op->action // ""
l!l
380
MC/DC0%0/1
$op->action // ""
$op->action
Truth table50%1/2
A
A= $op->action
Aresult
11
00
108 38 ▶ ($action eq 'drop' && _op_is_destructive($op))
Condition88%8/9
$action eq 'drop' && _op_is_destructive($op) || $op->can('lossy') && $op->lossy
l!l&&r!l&&!r
11522
$action eq "drop" and _op_is_destructive($op)
!ll&&!rl&&r
26111
$op->can("lossy") and $op->lossy
!ll&&!rl&&r
2205
MC/DC75%3/4
$action eq 'drop' && _op_is_destructive($op) || $op->can('lossy') && $op->lossy
$action eq "drop" _op_is_destructive($op) $op->can("lossy") $op->lossy
Truth table57%4/7
A and B || C and D
A= $action eq "drop"B= _op_is_destructive($op)C= $op->can("lossy")D= $op->lossy
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
109 || ($op->can('lossy') && $op->lossy)
110 31 } @{ $self->operations };
111 }
112  
113 15 1;
114  
115 __END__
« blib/lib/DBIO/PK.pm ↑ Summary blib/lib/DBIO/Test/Schema/Track.pm »