blib/lib/DBIO/PostgreSQL/Diff/SequenceOwner.pm

filter: Statementstmt 100% 61 / 61 Branchbran 100% 20 / 20 Conditioncond 83.3% 10 / 12 MC/DCmcdc 71.4% 5 / 7 Subroutinesub 100% 12 / 12 Podpod 100% 4 / 4 totaltotal 96.5% 112 / 116 CC 17 SCAR 15.2
CC
17
Cov
98%
as_sql
8.0
diff
6.0
_owner
4.0
CRAP 4.6
« blib/lib/DBIO/PostgreSQL/Extension.pm ↑ Summary blib/lib/DBIO/PostgreSQL/Adapter.pm »
1 package DBIO::PostgreSQL::Diff::SequenceOwner;
2 # ABSTRACT: Diff operations for the column a PostgreSQL sequence belongs to
3  
4 103 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 103 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 103 our $VERSION = '0.900007';
8  
9 103 ▶use base 'DBIO::Diff::Op';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 103 ▶use DBIO::PostgreSQL::Diff::NoStatement ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 103 ▶use DBIO::PostgreSQL::Diff::Sequence ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 103 ▶use DBIO::PostgreSQL::Introspect ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 103 ▶use DBIO::PostgreSQL::Util qw(quote_qualified);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 103 __PACKAGE__->mk_diff_accessors(qw(schema_name sequence_name table_name column_name));
17  
18  
19  
20  
21  
22  
23 # The column an entry of the model says the sequence belongs to, as a list
24 # ( table, column ), or the empty list for none. The sequence of an identity
25 # column is no sequence of its own and is not asked.
26 42 ▶sub _owner {
Subroutine _owner: called CC=4 SCAR=13.9
27 42 my ($info) = @_;
28 42 ▶ return unless DBIO::PostgreSQL::Diff::Sequence->is_own($info);
Branch: 1 branch
BranchTrueFalseTotal
unless "DBIO::PostgreSQL::Diff::Sequence"->is_own($info) 8 34 42
29 34 my ($table, $column) = @{$info}{qw( owned_by_table_name owned_by_column )};
30 34 ▶ return unless defined $table && defined $column;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $table and defined $column 7 27 34
Condition66%2/3
defined $table and defined $column
!ll&&!rl&&r
7027
MC/DC50%1/2
defined $table and defined $column
defined $table defined $column
Truth table66%2/3
A and B
A= defined $tableB= defined $column
ABresult
0X0
100
111
31 27 return ($table, $column);
32 }
33  
34  
35 25 ▶sub diff {
Subroutine diff: called CC=6 SCAR=17.9
Pod documented
36 25 my ($class, $source, $target) = @_;
37 25 my @ops;
38  
39 25 for my $key (sort keys %$target) {
40 26 my $new = $target->{$key};
41 26 ▶ next unless DBIO::PostgreSQL::Diff::Sequence->is_own($new);
Branch: 1 branch
BranchTrueFalseTotal
unless "DBIO::PostgreSQL::Diff::Sequence"->is_own($new) 2 24 26
42 24 ▶ next unless exists $new->{owned_by_table_name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $new->{"owned_by_table_name"} 3 21 24
43  
44 21 my @is = _owner($new);
45 21 my @was = _owner($source->{$key});
46 21 ▶ next if @is == @was && !grep { $is[$_] ne $was[$_] } 0 .. $#is;
Branch: 1 branch
BranchTrueFalseTotal
if @is == @was and not grep({$is[$_] ne $was[$_];} 0 .. $#is) 9 12 21
Condition100%3/3
@is == @was and not grep({$is[$_] ne $was[$_];} 0 .. $#is)
!ll&&!rl&&r
1119
MC/DC100%2/2
@is == @was and not grep({$is[$_] ne $was[$_];} 0 .. $#is)
@is == @was not grep({$is[$_] ne $was[$_];} 0 .. $#is)
Truth table100%3/3
A and not(B)
A= @is == @wasB= not grep({$is[$_] ne $was[$_];} 0 .. $#is)
ABresult
0X0
100
111
47  
48 12 my ($schema_name, $sequence_name)
49 = DBIO::PostgreSQL::Introspect->key_names($key, sequence_name => $new);
50 12 push @ops, $class->new(
51 action => 'own',
52 schema_name => $schema_name,
53 sequence_name => $sequence_name,
54 table_name => $is[0],
55 column_name => $is[1],
56 );
57 }
58  
59 25 return @ops;
60 }
61  
62  
63 16 ▶sub qualified_name {
Subroutine qualified_name: called CC=1 SCAR=0.0
Pod documented
64 16 my ($self) = @_;
65 16 return join '.', grep { defined } $self->schema_name, $self->sequence_name;
66 }
67  
68  
69 14 ▶sub as_sql {
Subroutine as_sql: called CC=8 SCAR=20.8
Pod documented
70 14 my ($self) = @_;
71 14 my $object = 'sequence ' . $self->qualified_name;
72  
73 14 ▶ DBIO::PostgreSQL::Diff::NoStatement->throw($self, $object)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->action // "") eq "own" 1 13 14
Condition50%1/2
$self->action // ""
l!l
140
MC/DC0%0/1
$self->action // ""
$self->action
Truth table50%1/2
A
A= $self->action
Aresult
11
00
74 unless ($self->action // '') eq 'own';
75 13 ▶ DBIO::PostgreSQL::Diff::NoStatement->throw($self, $object, 'it has no sequence_name')
Branch: 1 branch
BranchTrueFalseTotal
unless length($self->sequence_name // "") 1 12 13
Condition100%2/2
$self->sequence_name // ""
l!l
121
MC/DC100%1/1
$self->sequence_name // ""
$self->sequence_name
Truth table100%2/2
A
A= $self->sequence_name
Aresult
11
00
76 unless length($self->sequence_name // '');
77  
78 12 ▶ my @column = grep { length($_ // '') } $self->table_name, $self->column_name;
Condition100%2/2
$_ // ""
l!l
177
MC/DC100%1/1
$_ // ""
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
79 12 ▶ DBIO::PostgreSQL::Diff::NoStatement->throw(
Branch: 1 branch
BranchTrueFalseTotal
if @column == 1 1 11 12
80 $self, $object, 'it names a table without a column or a column without a table',
81 ) if @column == 1;
82  
83 11 my @schema = grep { defined } $self->schema_name;
84 11 ▶ return sprintf 'ALTER SEQUENCE %s OWNED BY %s;',
Branch: 1 branch
BranchTrueFalseTotal
@column ? : 8 3 11
85 quote_qualified(@schema, $self->sequence_name),
86 ( @column ? quote_qualified(@schema, @column) : 'NONE' );
87 }
88  
89  
90 2 ▶sub summary {
Subroutine summary: called CC=2 SCAR=6.9
Pod documented
91 2 my ($self) = @_;
92 2 my @column = grep { defined } $self->table_name, $self->column_name;
93 return sprintf ' ~sequence: %s (owned by %s)', $self->qualified_name,
94 2 ▶ ( @column ? join('.', grep { defined } $self->schema_name, @column) : 'none' );
Branch: 1 branch
BranchTrueFalseTotal
@column ? : 1 1 2
95 }
96  
97  
98 103 1;
99  
100 __END__
« blib/lib/DBIO/PostgreSQL/Extension.pm ↑ Summary blib/lib/DBIO/PostgreSQL/Adapter.pm »