DB2/Diff/ForeignKey.pm

filter: Statementstmt 94.4% 34 / 36 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 100% 3 / 3 totaltotal 94.3% 50 / 53 CC 2 SCAR 2.1
CC
2
Cov
95%
as_sql
2.0
summary
2.0
BEGIN
1.0
CRAP 1.2
« DB2/SQLMaker.pm ↑ Summary Shortcut/db2.pm »
1 package DBIO::DB2::Diff::ForeignKey;
2 # ABSTRACT: Diff operations for DB2 foreign keys
3  
4 46 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 46 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 46 our $VERSION = '0.900007';
8  
9 46 ▶use base 'DBIO::Diff::Op';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 46 ▶use DBIO::DB2::DDL qw(_fk_constraint_clause _db2_quote_ident _db2_quote_table);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 46 ▶use DBIO::Diff::Compare qw(changed_fk_fields);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 46 __PACKAGE__->mk_diff_accessors(qw/table_name constraint_name fk_info/);
16  
17  
18 146 ▶sub diff {
Subroutine diff: called CC=1 SCAR=0.0
Pod documented
19 146 my ($class, $source, $target, $source_tables, $target_tables) = @_;
20  
21 return $class->diff_nested($source, $target,
22 index_by => 'constraint_name',
23 scope => 'both',
24 source_tables => $source_tables,
25 target_tables => $target_tables,
26 3 ▶ changed_when => sub { scalar changed_fk_fields($_[0], $_[1]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
27 4 ▶ on_new => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
28 4 my ($table, $name, $new) = @_;
29 4 $class->new(action => 'add', table_name => $table,
30 constraint_name => $name, fk_info => $new);
31 },
32 2 ▶ on_changed => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
33 2 my ($table, $name, $old, $new) = @_;
34 2 ($class->new(action => 'drop', table_name => $table,
35 constraint_name => $name, fk_info => $old),
36 $class->new(action => 'add', table_name => $table,
37 constraint_name => $name, fk_info => $new));
38 },
39 2 ▶ on_gone => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
40 2 my ($table, $name, $old) = @_;
41 2 $class->new(action => 'drop', table_name => $table,
42 constraint_name => $name, fk_info => $old);
43 },
44 146 );
45 }
46  
47  
48 12 ▶sub as_sql {
Subroutine as_sql: called CC=2 SCAR=6.9
Pod documented
49 12 my ($self) = @_;
50 12 my $tbl = _db2_quote_table($self->table_name);
51 12 my $name = _db2_quote_ident($self->constraint_name);
52  
53 12 ▶ if ($self->action eq 'add') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->action eq "add") 8 4 12
54 # Same FK clause body as the inline create path -- single source of truth
55 # in DBIO::DB2::DDL (ADR 0005), here wrapped in ALTER TABLE ... ADD.
56 8 my $clause = _fk_constraint_clause($self->fk_info);
57 8 return sprintf 'ALTER TABLE %s ADD %s;', $tbl, $clause;
58 }
59 4 return sprintf 'ALTER TABLE %s DROP FOREIGN KEY %s;', $tbl, $name;
60 }
61  
62  
63 0 ▶sub summary {
Subroutine summary: not called CC=1 SCAR=6.9
Pod documented
64 0 my ($self) = @_;
65 0 return sprintf ' %sfk: %s on %s',
66 $self->summary_prefix, $self->constraint_name, $self->table_name;
67 }
68  
69 46 1;
70  
71 __END__
« DB2/SQLMaker.pm ↑ Summary Shortcut/db2.pm »