| 1 | package DBIO::PostgreSQL::PostGIS; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: PostGIS spatial extension support for DBIO::PostgreSQL | ||||||||||||||||||||||||||||
| 3 | 7 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use base 'DBIO::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use DBIO::Exception (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use DBIO::PostgreSQL::PostGIS::Geometry (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use DBIO::PostgreSQL::PostGIS::ResultSet (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 7 | __PACKAGE__->load_components(qw( InflateColumn )); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | sub connection { | ||||||||||||||||||||||||||
|
Subroutine
connection: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 3 | my ($self, @info) = @_; | |||||||||||||||||||||||||||
| 17 | 3 | $self->register_storage_layer('DBIO::PostgreSQL::PostGIS::Storage'); | |||||||||||||||||||||||||||
| 18 | 3 | return $self->next::method(@info); | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 12 | ▶ | sub register_column { | ||||||||||||||||||||||||||
|
Subroutine
register_column: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 12 | my ($self, $column, $info, @rest) = @_; | |||||||||||||||||||||||||||
| 24 | 12 | $self->next::method($column, $info, @rest); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 12 | ▶ | my $data_type = lc($info->{data_type} // ''); | ||||||||||||||||||||||||||
|
Condition50%1/2
$info->{"data_type"} // ""
MC/DC0%0/1
$info->{"data_type"} // ""
$info->{"data_type"}
Truth table50%1/2
A
A= $info->{"data_type"}
| |||||||||||||||||||||||||||||
| 27 | my $is_spatial = | ||||||||||||||||||||||||||||
| 28 | exists $info->{inflate_geometry} | ||||||||||||||||||||||||||||
| 29 | ? $info->{inflate_geometry} | ||||||||||||||||||||||||||||
| 30 | 12 | ▶ | : ($data_type eq 'geometry' || $data_type eq 'geography'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$data_type eq "geometry" or $data_type eq "geography"
MC/DC100%2/2
$data_type eq "geometry" or $data_type eq "geography"
$data_type eq "geometry"
$data_type eq "geography"
Truth table100%3/3
A or B
A= $data_type eq "geometry"B= $data_type eq "geography"
| |||||||||||||||||||||||||||||
| 31 | 12 | ▶ | return unless $is_spatial; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # Promote the resultset class once, leaving custom user subclasses alone. | ||||||||||||||||||||||||||||
| 34 | 5 | my $rs_class = $self->resultset_class; | |||||||||||||||||||||||||||
| 35 | 5 | ▶ | if ($rs_class && !$rs_class->isa('DBIO::PostgreSQL::PostGIS::ResultSet')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$rs_class and not $rs_class->isa("DBIO::PostgreSQL::PostGIS::ResultSet")
MC/DC50%1/2
$rs_class and not $rs_class->isa("DBIO::PostgreSQL::PostGIS::ResultSet")
$rs_class
not $rs_class->isa("DBIO::PostgreSQL::PostGIS::ResultSet")
Truth table66%2/3
A and not(B)
A= $rs_classB= not $rs_class->isa("DBIO::PostgreSQL::PostGIS::ResultSet")
| |||||||||||||||||||||||||||||
| 36 | 3 | $self->resultset_class('DBIO::PostgreSQL::PostGIS::ResultSet'); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 5 | my $default_srid = $info->{srid}; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | $self->inflate_column( | ||||||||||||||||||||||||||||
| 42 | $column => { | ||||||||||||||||||||||||||||
| 43 | 13 | ▶ | inflate => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||
| 44 | 13 | my ($value, $obj) = @_; | |||||||||||||||||||||||||||
| 45 | 13 | ▶ | return undef unless defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 12 | ▶ | return $value if ref($value) && $value->isa('DBIO::PostgreSQL::PostGIS::Geometry'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $value and $value->isa("DBIO::PostgreSQL::PostGIS::Geometry")
MC/DC0%0/2
ref $value and $value->isa("DBIO::PostgreSQL::PostGIS::Geometry")
ref $value
$value->isa("DBIO::PostgreSQL::PostGIS::Geometry")
Truth table33%1/3
A and B
A= ref $valueB= $value->isa("DBIO::PostgreSQL::PostGIS::Geometry")
| |||||||||||||||||||||||||||||
| 47 | # PostGIS hands EWKB-hex back by default, EWKT when ST_AsEWKT is used. | ||||||||||||||||||||||||||||
| 48 | 12 | ▶ | if ($value =~ /\A[0-9A-Fa-f]+\z/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 8 | return DBIO::PostgreSQL::PostGIS::Geometry->from_ewkb_hex($value); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 4 | ▶ | if ($value =~ /\ASRID=\d+;/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 2 | return DBIO::PostgreSQL::PostGIS::Geometry->from_ewkt($value); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 2 | return DBIO::PostgreSQL::PostGIS::Geometry->from_wkt( | |||||||||||||||||||||||||||
| 55 | $value, srid => $default_srid, | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | }, | ||||||||||||||||||||||||||||
| 58 | 23 | ▶ | deflate => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 59 | 23 | my ($value, $obj) = @_; | |||||||||||||||||||||||||||
| 60 | 23 | ▶ | return undef unless defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 21 | ▶ | if (ref($value) && $value->isa('DBIO::PostgreSQL::PostGIS::Geometry')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $value and $value->isa("DBIO::PostgreSQL::PostGIS::Geometry")
MC/DC50%1/2
ref $value and $value->isa("DBIO::PostgreSQL::PostGIS::Geometry")
ref $value
$value->isa("DBIO::PostgreSQL::PostGIS::Geometry")
Truth table66%2/3
A and B
A= ref $valueB= $value->isa("DBIO::PostgreSQL::PostGIS::Geometry")
| |||||||||||||||||||||||||||||
| 62 | # A value that came from the database goes back as the EWKB hex | ||||||||||||||||||||||||||||
| 63 | # it arrived as. The EWKT of such an object is rebuilt from the | ||||||||||||||||||||||||||||
| 64 | # decoded coordinates and holds Perl's printing of each double, | ||||||||||||||||||||||||||||
| 65 | # not the double. | ||||||||||||||||||||||||||||
| 66 | 20 | my $why = $value->_unwritable_reason; | |||||||||||||||||||||||||||
| 67 | 20 | ▶ | DBIO::Exception->throw($why) if defined $why; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 16 | my $hex = $value->ewkb_hex; | |||||||||||||||||||||||||||
| 69 | 16 | ▶ | return $hex if defined $hex && length $hex; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $hex and length $hex
MC/DC100%2/2
defined $hex and length $hex
defined $hex
length $hex
Truth table100%3/3
A and B
A= defined $hexB= length $hex
| |||||||||||||||||||||||||||||
| 70 | 9 | return $value->ewkt; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | # Already an EWKT/WKT/EWKB-hex string — pass through. | ||||||||||||||||||||||||||||
| 73 | 1 | return $value; | |||||||||||||||||||||||||||
| 74 | }, | ||||||||||||||||||||||||||||
| 75 | }, | ||||||||||||||||||||||||||||
| 76 | 5 | ); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 7 | 1; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | __END__ | ||||||||||||||||||||||||||||