PostGIS/Storage.pm

filter: Statementstmt 88.4% 46 / 52 Branchbran 100% 14 / 14 Conditioncond 90.0% 9 / 10 MC/DCmcdc 83.3% 5 / 6 Subroutinesub 85.7% 12 / 14 Podpod 100% 3 / 3 totaltotal 89.9% 89 / 99 CC 12 SCAR 12.0
CC
12
Cov
91%
ensure_postgis
7.0
_postgis_control_schema
3.0
_ensure_postgis_extension
3.0
CRAP 3.3
« PostGIS.pm ↑ Summary PostGIS/Topology/Extension.pm »
1 package DBIO::PostgreSQL::PostGIS::Storage;
2 # ABSTRACT: Storage class with PostGIS spatial extensions
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 DBIO::PostgreSQL::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use DBIO::PostgreSQL::DDL ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 17 ▶sub ensure_postgis {
Subroutine ensure_postgis: called CC=7 SCAR=19.5
Pod documented
14 17 my $self = shift;
15  
16 17 my $schema = $self->schema;
17 17 ▶ my $declared = $schema && $schema->can('pg_extension_schemas')
Branch: 1 branch
BranchTrueFalseTotal
$schema && $schema->can('pg_extension_schemas') ? : 13 4 17
Condition100%3/3
$schema and $schema->can("pg_extension_schemas")
!ll&&!rl&&r
1313
MC/DC100%2/2
$schema and $schema->can("pg_extension_schemas")
$schema $schema->can("pg_extension_schemas")
Truth table100%3/3
A and B
A= $schemaB= $schema->can("pg_extension_schemas")
ABresult
0X0
100
111
18 ? $schema->pg_extension_schemas
19 : {};
20 17 my $into = $declared->{postgis};
21 17 ▶ $into = $self->_postgis_control_schema // 'public' unless defined $into;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $into 11 6 17
Condition100%2/2
$self->_postgis_control_schema // "public"
l!l
29
MC/DC100%1/1
$self->_postgis_control_schema // "public"
$self->_postgis_control_schema
Truth table100%2/2
A
A= $self->_postgis_control_schema
Aresult
11
00
22 17 my $namespace = $self->connection_schema;
23  
24 17 ▶ $self->throw_exception(sprintf
Branch: 1 branch
BranchTrueFalseTotal
if defined $namespace and $into eq $namespace 4 13 17
Condition100%3/3
defined $namespace and $into eq $namespace
!ll&&!rl&&r
944
MC/DC100%2/2
defined $namespace and $into eq $namespace
defined $namespace $into eq $namespace
Truth table100%3/3
A and B
A= defined $namespaceB= $into eq $namespace
ABresult
0X0
100
111
25 'refusing to create the extension postgis in schema %s, the namespace '
26 . 'this connection works in (connect key schema). An extension belongs '
27 . 'to the database and is not installed into the namespace of one '
28 . 'connection; name another schema for it, '
29 . 'pg_extensions(postgis => { schema => ... }).',
30 $into,
31 ) if defined $namespace && $into eq $namespace;
32  
33 13 my $sql = 'CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA '
34 . DBIO::PostgreSQL::Util::quote_ident($into);
35  
36 13 ▶ $self->dbh_do(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
37 13 my (undef, $dbh) = @_;
38 13 $dbh->do($sql);
39 13 });
40 }
41  
42 # The schema the control file of the server fixes for postgis (the rule of
43 # dbio-postgresql k141/k142, asked with the driver's own statement), or undef.
44 11 ▶sub _postgis_control_schema {
Subroutine _postgis_control_schema: called CC=3 SCAR=11.0
45 11 my $self = shift;
46 11 ▶ my $rows = $self->dbh_do(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
47 11 my (undef, $dbh) = @_;
48 11 $dbh->selectall_arrayref(
49 DBIO::PostgreSQL::DDL::control_schemas_sql('postgis'));
50 11 ▶ }) // [];
Condition50%1/2
$self->dbh_do(sub { my(undef, $dbh) = @_; $dbh->selectall_arrayref(DBIO::PostgreSQL::DDL::control_schemas_sql("postgis")); } ) // []
l!l
110
MC/DC0%0/1
$self->dbh_do(sub { my(undef, $dbh) = @_; $dbh->selectall_arrayref(DBIO::PostgreSQL::DDL::control_schemas_sql("postgis")); } ) // []
$self->dbh_do(sub { my(undef, $dbh) = @_; $dbh->selectall_arrayref(DBIO::PostgreSQL::DDL::control_schemas_sql("postgis")); } )
Truth table50%1/2
A
A= $self->dbh_do(sub { my(undef, $dbh) = @_; $dbh->selectall_arrayref(DBIO::PostgreSQL::DDL::control_schemas_sql("postgis")); } )
Aresult
11
00
51 11 my ($row) = grep { $_->[0] eq 'postgis' } @$rows;
52 11 ▶ return $row ? $row->[1] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$row ? : 2 9 11
53 }
54  
55  
56 0 ▶sub postgis_version {
Subroutine postgis_version: not called CC=1 SCAR=6.9
Pod documented
57 0 my $self = shift;
58 0 ▶ return $self->dbh_do(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
59 0 my (undef, $dbh) = @_;
60 0 my ($v) = eval { $dbh->selectrow_array('SELECT PostGIS_Full_Version()') };
61 0 return $v;
62 0 });
63 }
64  
65  
66 3 ▶sub _ensure_postgis_extension {
Subroutine _ensure_postgis_extension: called CC=3 SCAR=11.0
67 3 my $self = shift;
68 3 ▶ my $installed = $self->dbh_do(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
69 3 my (undef, $dbh) = @_;
70 3 my ($row) = $dbh->selectrow_array(
71 "SELECT 1 FROM pg_extension WHERE extname = 'postgis'",
72 );
73 3 ▶ return defined $row ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $row ? : 1 2 3
74 3 });
75 3 ▶ return if $installed;
Branch: 1 branch
BranchTrueFalseTotal
if $installed 1 2 3
76 2 ▶ my $dbname = $self->dbh_do(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
77 2 my (undef, $dbh) = @_;
78 2 my ($n) = $dbh->selectrow_array('SELECT current_database()');
79 2 return $n;
80 2 });
81 2 ▶ $dbname = defined $dbname ? "'$dbname'" : '(unknown)';
Branch: 1 branch
BranchTrueFalseTotal
defined $dbname ? : 1 1 2
82 2 $self->throw_exception(
83 "PostGIS extension is not installed on database $dbname "
84 . '(required by DBIO::PostgreSQL::PostGIS)'
85 );
86 }
87  
88  
89 6 ▶sub async_layer_class {
Subroutine async_layer_class: called CC=1 SCAR=0.0
Pod documented
90 6 my ($class, $mode) = @_;
91 6 return undef; # stated: deliberately sync-only for every async mode (core k159, ADR 0032 addendum 2026-09-25)
92 }
93  
94 7 1;
95  
96 __END__
« PostGIS.pm ↑ Summary PostGIS/Topology/Extension.pm »