PostGIS.pm

filter: Statementstmt 100% 51 / 51 Branchbran 95.4% 21 / 22 Conditioncond 70.5% 12 / 17 MC/DCmcdc 54.5% 6 / 11 Subroutinesub 100% 10 / 10 Podpod 50.0% 1 / 2 totaltotal 89.3% 101 / 113 CC 18 SCAR 16.6
CC
18
Cov
93%
register_column
7.0
__ANON__
7.0
__ANON__
6.1
CRAP 5.3
« PostGIS/ResultSet.pm ↑ Summary PostGIS/Storage.pm »
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"} // ""
l!l
120
MC/DC0%0/1
$info->{"data_type"} // ""
$info->{"data_type"}
Truth table50%1/2
A
A= $info->{"data_type"}
Aresult
11
00
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
BranchTrueFalseTotal
exists $info->{'inflate_geometry'} ? : 1 11 12
Condition100%3/3
$data_type eq "geometry" or $data_type eq "geography"
l!l&&r!l&&!r
416
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"
ABresult
1X1
011
000
31 12 ▶ return unless $is_spatial;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_spatial 7 5 12
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
BranchTrueFalseTotal
if ($rs_class and not $rs_class->isa("DBIO::PostgreSQL::PostGIS::ResultSet")) 3 2 5
Condition66%2/3
$rs_class and not $rs_class->isa("DBIO::PostgreSQL::PostGIS::ResultSet")
!ll&&!rl&&r
023
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")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless defined $value 1 12 13
46 12 ▶ return $value if ref($value) && $value->isa('DBIO::PostgreSQL::PostGIS::Geometry');
Branch: 1 branch
BranchTrueFalseTotal
if ref $value and $value->isa("DBIO::PostgreSQL::PostGIS::Geometry") 0 12 12
Condition33%1/3
ref $value and $value->isa("DBIO::PostgreSQL::PostGIS::Geometry")
!ll&&!rl&&r
1200
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")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($value =~ /\A[0-9A-Fa-f]+\z/) 8 4 12
49 8 return DBIO::PostgreSQL::PostGIS::Geometry->from_ewkb_hex($value);
50 }
51 4 ▶ if ($value =~ /\ASRID=\d+;/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /\ASRID=\d+;/) 2 2 4
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
BranchTrueFalseTotal
unless defined $value 2 21 23
61 21 ▶ if (ref($value) && $value->isa('DBIO::PostgreSQL::PostGIS::Geometry')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value and $value->isa("DBIO::PostgreSQL::PostGIS::Geometry")) 20 1 21
Condition66%2/3
ref $value and $value->isa("DBIO::PostgreSQL::PostGIS::Geometry")
!ll&&!rl&&r
1020
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")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if defined $why 4 16 20
68 16 my $hex = $value->ewkb_hex;
69 16 ▶ return $hex if defined $hex && length $hex;
Branch: 1 branch
BranchTrueFalseTotal
if defined $hex and length $hex 7 9 16
Condition100%3/3
defined $hex and length $hex
!ll&&!rl&&r
817
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
ABresult
0X0
100
111
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__
« PostGIS/ResultSet.pm ↑ Summary PostGIS/Storage.pm »