blib/lib/DBIO/DuckDB/Diff/View.pm

filter: Statementstmt 50.0% 21 / 42 Branchbran 0.0% 0 / 12 Conditioncond 14.2% 2 / 14 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 55.5% 5 / 9 Podpod 100% 3 / 3 totaltotal 35.6% 31 / 87 CC 14 SCAR 32.7
CC
14
Cov
34%
diff
48.0
as_sql
20.0
_comparable
6.0
CRAP 26.4
« blib/lib/DBIO/DuckDB/Introspect/Uniques.pm ↑ Summary blib/lib/DBIO/DuckDB/Introspect.pm »
1 package DBIO::DuckDB::Diff::View;
2 # ABSTRACT: Diff operations for DuckDB views
3  
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 our $VERSION = '0.900007';
8  
9 8 ▶use base 'DBIO::Diff::Op';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 8 ▶use DBIO::DuckDB::DDL::Emit qw(quote_ident);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 8 __PACKAGE__->mk_diff_accessors(qw/view_name view_info replaced/);
14  
15  
16 0 ▶sub _comparable {
Subroutine _comparable: not called CC=2 SCAR=17.9
17 0 my ($def) = @_;
18 0 ▶ $def //= '';
Condition0%0/2
$def //= ""
l!l
00
MC/DC0%0/1
$def //= ""
$def
Truth table0%0/2
A
A= $def
Aresult
11
00
19 0 $def =~ s/\A\s+//;
20 0 $def =~ s/[\s;]+\z//;
21 0 return $def;
22 }
23  
24 # what is compared: the query of the statement, not the spelling of the name
25 # it was created under (a database deployed before every name was quoted holds
26 # CREATE VIEW v, the target CREATE VIEW "v")
27 0 ▶sub _body {
Subroutine _body: not called CC=1 SCAR=6.9
28 0 my ($def) = @_;
29 0 $def = _comparable($def);
30 0 $def =~ s/\A CREATE \s+ (?: OR \s+ REPLACE \s+ )? (?: (?:LOCAL|GLOBAL)? \s* TEMP(?:ORARY)? \s+ )?
31 VIEW \s+ (?: IF \s+ NOT \s+ EXISTS \s+ )?
32 (?: "(?:[^"]|"")*" | [\w\$.]+ ) \s+ //xi;
33 0 return $def;
34 }
35  
36 2 ▶sub diff {
Subroutine diff: called CC=10 SCAR=38.7
Pod documented
37 2 my ($class, $source, $target) = @_;
38 2 ▶ $source //= {};
Condition50%1/2
$source //= {}
l!l
20
MC/DC0%0/1
$source //= {}
$source
Truth table50%1/2
A
A= $source
Aresult
11
00
39 2 ▶ $target //= {};
Condition50%1/2
$target //= {}
l!l
20
MC/DC0%0/1
$target //= {}
$target
Truth table50%1/2
A
A= $target
Aresult
11
00
40  
41 2 my %seen;
42 my @ops;
43 0 for my $name (sort grep { !$seen{$_}++ } keys %$source, keys %$target) {
44 0 my ($old, $new) = ($source->{$name}, $target->{$name});
45  
46 next if $old && $new
47 0 ▶ && _body($old->{view_definition}) eq _body($new->{view_definition});
Branch: 1 branch
BranchTrueFalseTotal
if $old and $new and _body($old->{"view_definition"}) eq _body($new->{"view_definition"}) 0 0 0
Condition0%0/6
$old and $new and _body($old->{"view_definition"}) eq _body($new->{"view_definition"})
!ll&&!rl&&r
000
$old and $new
!ll&&!rl&&r
000
MC/DC0%0/3
$old and $new and _body($old->{"view_definition"}) eq _body($new->{"view_definition"})
$old $new _body($old->{"view_definition"}) eq _body($new->{"view_definition"})
Truth table0%0/4
A and B and C
A= $oldB= $newC= _body($old->{"view_definition"}) eq _body($new->{"view_definition"})
ABCresult
0XX0
10X0
1100
1111
48  
49 0 ▶ push @ops, $class->new(
Branch: 2 branches
BranchTrueFalseTotal
if $old 0 0 0
$new ? : 0 0 0
50 action => 'drop',
51 view_name => $name,
52 view_info => $old,
53 replaced => ($new ? 1 : 0),
54 ) if $old;
55  
56 0 ▶ push @ops, $class->new(
Branch: 1 branch
BranchTrueFalseTotal
if $new 0 0 0
57 action => 'create',
58 view_name => $name,
59 view_info => $new,
60 ) if $new;
61 }
62 2 return @ops;
63 }
64  
65  
66 0 ▶sub as_sql {
Subroutine as_sql: not called CC=4 SCAR=30.0
Pod documented
67 0 my ($self) = @_;
68  
69 0 ▶ return sprintf 'DROP VIEW %s;', quote_ident($self->view_name)
Branch: 1 branch
BranchTrueFalseTotal
if $self->action eq "drop" 0 0 0
70 if $self->action eq 'drop';
71  
72 0 ▶ my $def = _comparable(($self->view_info // {})->{view_definition});
Condition0%0/2
$self->view_info // {}
l!l
00
MC/DC0%0/1
$self->view_info // {}
$self->view_info
Truth table0%0/2
A
A= $self->view_info
Aresult
11
00
73 0 ▶ die sprintf "Cannot create view %s: the target model holds no definition "
Branch: 1 branch
BranchTrueFalseTotal
unless length $def 0 0 0
74 . "for it, and a view cannot be written from its columns\n", $self->view_name
75 unless length $def;
76  
77 0 return "$def;";
78 }
79  
80  
81 0 ▶sub summary {
Subroutine summary: not called CC=1 SCAR=6.9
Pod documented
82 0 my ($self) = @_;
83 0 return sprintf '%s view: %s', $self->summary_prefix, $self->view_name;
84 }
85  
86 8 1;
87  
88 __END__
« blib/lib/DBIO/DuckDB/Introspect/Uniques.pm ↑ Summary blib/lib/DBIO/DuckDB/Introspect.pm »