PostGIS/Extension.pm

filter: Statementstmt 100% 58 / 58 Branchbran 100% 26 / 26 Conditioncond 84.0% 37 / 44 MC/DCmcdc 71.4% 15 / 21 Subroutinesub 100% 12 / 12 Podpod 100% 7 / 7 totaltotal 92.2% 155 / 168 CC 33 SCAR 26.0
CC
33
Cov
95%
annotate
18.0
verdict
16.2
BEGIN
1.0
CRAP 13.5
« PostGIS/Codec/WKT/Parser.pm ↑ Summary PostGIS/Codec/WKB/Decoder.pm »
1 package DBIO::PostgreSQL::PostGIS::Extension;
2 # ABSTRACT: The postgis extension for deploy, introspection and diff (DBIO extension interface)
3  
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 our $VERSION = '0.900007';
8  
9 7 ▶use base 'DBIO::Extension';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 7 ▶use DBIO::PostgreSQL::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 9 ▶sub extension_interface { 1 }
Subroutine extension_interface: called CC=1 SCAR=0.0
Pod documented
15  
16 13 ▶sub name { 'postgis' }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
17  
18 1 ▶sub driver { 'DBIO::PostgreSQL' }
Subroutine driver: called CC=1 SCAR=0.0
Pod documented
19  
20  
21 2 ▶sub storage_layer { 'DBIO::PostgreSQL::PostGIS::Storage' }
Subroutine storage_layer: called CC=1 SCAR=0.0
Pod documented
22  
23  
24 2 ▶sub inflation_component { 'DBIO::PostgreSQL::PostGIS' }
Subroutine inflation_component: called CC=1 SCAR=0.0
Pod documented
25  
26  
27 108 ▶sub annotate {
Subroutine annotate: called CC=18 SCAR=28.9
Pod documented
28 108 my ($class, $model, $ctx) = @_;
29  
30 # The schema the types live in, per side of the diff: the model's own word
31 # first (a temp database may differ from the live one), the entry's second.
32 my $postgis_schema = ($model->{extensions} // {})->{postgis}
33 ? $model->{extensions}{postgis}{schema_name}
34 108 ▶ : undef;
Branch: 1 branch
BranchTrueFalseTotal
+($model->{'extensions'} // {})->{'postgis'} ? : 98 10 108
Condition100%2/2
$model->{"extensions"} // {}
l!l
9810
MC/DC100%1/1
$model->{"extensions"} // {}
$model->{"extensions"}
Truth table100%2/2
A
A= $model->{"extensions"}
Aresult
11
00
35 108 ▶ $postgis_schema //= ($ctx->{self} // {})->{schema};
Condition100%5/5
$postgis_schema //= +($ctx->{"self"} // {})->{"schema"}
l!l&&r!l&&!r
9828
$ctx->{"self"} // {}
l!l
28
MC/DC100%2/2
$postgis_schema //= +($ctx->{"self"} // {})->{"schema"}
$postgis_schema $ctx->{"self"}
Truth table100%3/3
A //= B
A= $postgis_schemaB= $ctx->{"self"}
ABresult
1X1
011
000
36  
37 108 my @triples;
38 108 ▶ my $columns_by_table = $model->{columns} // {};
Condition50%1/2
$model->{"columns"} // {}
l!l
1080
MC/DC0%0/1
$model->{"columns"} // {}
$model->{"columns"}
Truth table50%1/2
A
A= $model->{"columns"}
Aresult
11
00
39 108 for my $table_key (sort keys %$columns_by_table) {
40 127 ▶ for my $col (@{ $columns_by_table->{$table_key} // [] }) {
Condition50%1/2
$columns_by_table->{$table_key} // []
l!l
1270
MC/DC0%0/1
$columns_by_table->{$table_key} // []
$columns_by_table->{$table_key}
Truth table50%1/2
A
A= $columns_by_table->{$table_key}
Aresult
11
00
41 211 ▶ my $dt = $col->{data_type} // '';
Condition100%2/2
$col->{"data_type"} // ""
l!l
2101
MC/DC100%1/1
$col->{"data_type"} // ""
$col->{"data_type"}
Truth table100%2/2
A
A= $col->{"data_type"}
Aresult
11
00
42 211 ▶ next unless $dt =~ /\A
Branch: 1 branch
BranchTrueFalseTotal
unless $dt =~ /\A (?: (?: "((?:[^"]|"")+)" | ([A-Za-z_][\w\$]*) ) \. )? (geometry|geography) (?: \( (\w+) (?: ,(\d+) )? \) )? \z/xi 88 123 211
43 (?: (?: "((?:[^"]|"")+)" | ([A-Za-z_][\w\$]*) ) \. )?
44 (geometry|geography)
45 (?: \( (\w+) (?: ,(\d+) )? \) )?
46 \z/xi;
47 123 my ($quoted, $plain, $base, $gtype, $srid) = ($1, $2, $3, $4, $5);
48  
49 123 ▶ if (defined $postgis_schema) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $postgis_schema) 118 5 123
50 # Where the type lives: the catalog's word first, the prefix of the
51 # string otherwise. Only when neither says, the type is taken as
52 # PostGIS's -- an unqualified name is resolved through the
53 # search_path, and the search_path found the PostGIS type.
54 118 my $schema = $col->{type_schema};
55 118 ▶ unless (defined $schema) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $schema) 8 110 118
56 8 ▶ if (defined $quoted) { ($schema = $quoted) =~ s/""/"/g }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $quoted) { } 3 5 8
57 5 else { $schema = $plain } # may be undef
58 }
59 118 ▶ next if defined $schema && $schema ne $postgis_schema;
Branch: 1 branch
BranchTrueFalseTotal
if defined $schema and $schema ne $postgis_schema 5 113 118
Condition100%3/3
defined $schema and $schema ne $postgis_schema
!ll&&!rl&&r
11125
MC/DC100%2/2
defined $schema and $schema ne $postgis_schema
defined $schema $schema ne $postgis_schema
Truth table100%3/3
A and B
A= defined $schemaB= $schema ne $postgis_schema
ABresult
0X0
100
111
60 }
61  
62 118 my $address = [ column => $table_key, $col->{column_name} ];
63 118 push @triples, [ $address, base_type => lc $base ];
64 118 ▶ push @triples, [ $address, geometry_type => lc $gtype ] if $gtype;
Branch: 1 branch
BranchTrueFalseTotal
if $gtype 114 4 118
65 118 ▶ push @triples, [ $address, srid => $srid + 0 ] if defined $srid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $srid 113 5 118
66 }
67 }
68 108 return \@triples;
69 }
70  
71  
72 91 ▶sub verdict {
Subroutine verdict: called CC=16 SCAR=27.9
Pod documented
73 91 my ($class, $change, $ctx) = @_;
74 91 ▶ return undef unless ($change->{kind} // '') eq 'column_type';
Branch: 1 branch
BranchTrueFalseTotal
unless ($change->{"kind"} // "") eq "column_type" 1 90 91
Condition50%1/2
$change->{"kind"} // ""
l!l
910
MC/DC0%0/1
$change->{"kind"} // ""
$change->{"kind"}
Truth table50%1/2
A
A= $change->{"kind"}
Aresult
11
00
75  
76 90 my ($old, $new) = @{$change}{qw(old_info new_info)};
77 return undef unless $old && $new
78 90 ▶ && defined $old->{base_type} && defined $new->{base_type};
Branch: 1 branch
BranchTrueFalseTotal
unless $old and $new and defined $old->{"base_type"} and defined $new->{"base_type"} 2 88 90
Condition66%6/9
$old and $new and defined $old->{"base_type"} and defined $new->{"base_type"}
!ll&&!rl&&r
1188
$old and $new and defined $old->{"base_type"}
!ll&&!rl&&r
0189
$old and $new
!ll&&!rl&&r
0090
MC/DC50%2/4
$old and $new and defined $old->{"base_type"} and defined $new->{"base_type"}
$old $new defined $old->{"base_type"} defined $new->{"base_type"}
Truth table60%3/5
A and B and C and D
A= $oldB= $newC= defined $old->{"base_type"}D= defined $new->{"base_type"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
79  
80 88 my $column = $change->{column_name};
81  
82 # the one place that refuses a change of type
83 88 ▶ if ($old->{base_type} ne $new->{base_type}
Branch: 1 branch
BranchTrueFalseTotal
if ($old->{"base_type"} ne $new->{"base_type"} or defined $old->{"geometry_type"} and defined $new->{"geometry_type"} and $old->{"geometry_type"} ne $new->{"geometry_type"}) 4 84 88
Condition100%9/9
$old->{"base_type"} ne $new->{"base_type"} or defined $old->{"geometry_type"} and defined $new->{"geometry_type"} and $old->{"geometry_type"} ne $new->{"geometry_type"}
l!l&&r!l&&!r
2284
defined $old->{"geometry_type"} and defined $new->{"geometry_type"} and $old->{"geometry_type"} ne $new->{"geometry_type"}
!ll&&!rl&&r
2822
defined $old->{"geometry_type"} and defined $new->{"geometry_type"}
!ll&&!rl&&r
1184
MC/DC100%4/4
$old->{"base_type"} ne $new->{"base_type"} or defined $old->{"geometry_type"} and defined $new->{"geometry_type"} and $old->{"geometry_type"} ne $new->{"geometry_type"}
$old->{"base_type"} ne $new->{"base_type"} defined $old->{"geometry_type"} defined $new->{"geometry_type"} $old->{"geometry_type"} ne $new->{"geometry_type"}
Truth table100%5/5
A or B and C and D
A= $old->{"base_type"} ne $new->{"base_type"}B= defined $old->{"geometry_type"}C= defined $new->{"geometry_type"}D= $old->{"geometry_type"} ne $new->{"geometry_type"}
ABCDresult
1XXX1
01111
00XX0
010X0
01100
84 || (defined $old->{geometry_type} && defined $new->{geometry_type}
85 && $old->{geometry_type} ne $new->{geometry_type})) {
86 8 ▶ my $what = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
87 8 my ($i) = @_;
88 8 join ' ', grep { defined } $i->{base_type}, $i->{geometry_type};
89 4 };
90 return { refuse => sprintf
91 "column %s.%s changes from %s to %s. A change of the geometry type, "
92 . "or between geometry and geography, has no conversion the diff can "
93 . "write; the server refuses it on a table that holds rows. No "
94 . "statement was generated. Add a column of the new type, fill it, "
95 . "and drop the old one.",
96 4 ▶ $change->{table} // '', $column, $what->($old), $what->($new) };
Condition50%1/2
$change->{"table"} // ""
l!l
40
MC/DC0%0/1
$change->{"table"} // ""
$change->{"table"}
Truth table50%1/2
A
A= $change->{"table"}
Aresult
11
00
97 }
98  
99 84 my ($from, $to) = ($old->{srid}, $new->{srid});
100 84 ▶ return undef unless $from && $to && $from != $to;
Branch: 1 branch
BranchTrueFalseTotal
unless $from and $to and $from != $to 3 81 84
Condition100%6/6
$from and $to and $from != $to
!ll&&!rl&&r
2181
$from and $to
!ll&&!rl&&r
1182
MC/DC100%3/3
$from and $to and $from != $to
$from $to $from != $to
Truth table100%4/4
A and B and C
A= $fromB= $toC= $from != $to
ABCresult
0XX0
10X0
1100
1111
101  
102 81 my $expr = DBIO::PostgreSQL::Util::quote_ident($column);
103 81 ▶ return { using => $new->{base_type} eq 'geography'
Branch: 1 branch
BranchTrueFalseTotal
$new->{'base_type'} eq 'geography' ? : 1 80 81
104 ? sprintf('ST_Transform(%s::geometry, %d)::geography', $expr, $to)
105 : sprintf('ST_Transform(%s, %d)', $expr, $to) };
106 }
107  
108  
109 7 1;
110  
111 __END__
« PostGIS/Codec/WKT/Parser.pm ↑ Summary PostGIS/Codec/WKB/Decoder.pm »