| 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
Condition100%3/3
$schema and $schema->can("pg_extension_schemas")
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")
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$self->_postgis_control_schema // "public"
MC/DC100%1/1
$self->_postgis_control_schema // "public"
$self->_postgis_control_schema
Truth table100%2/2
A
A= $self->_postgis_control_schema
| |||||||||||||||||||||||||||||
| 22 | 17 | my $namespace = $self->connection_schema; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 17 | ▶ | $self->throw_exception(sprintf | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $namespace and $into eq $namespace
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
| |||||||||||||||||||||||||||||
| 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"));
}
) // []
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"));
}
)
| |||||||||||||||||||||||||||||
| 51 | 11 | my ($row) = grep { $_->[0] eq 'postgis' } @$rows; | |||||||||||||||||||||||||||
| 52 | 11 | ▶ | return $row ? $row->[1] : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 74 | 3 | }); | |||||||||||||||||||||||||||
| 75 | 3 | ▶ | return if $installed; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||