| 1 | package DBIO::PostgreSQL::PostGIS::Codec::WKT::Builder; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: WKT builder for PostGIS geometry structures | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 13 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 288 | ▶ | sub build { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build: called CC=9 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 288 | my ($class, $parsed) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 288 | ▶ | my $type = uc($parsed->{type} // ''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$parsed->{"type"} // ""
MC/DC0%0/1
$parsed->{"type"} // ""
$parsed->{"type"}
Truth table50%1/2
A
A= $parsed->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 288 | ▶ | my $dim = ($parsed->{has_z} ? 'Z' : '') . ($parsed->{has_m} ? 'M' : ''); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 288 | ▶ | $dim = " $dim" if length $dim; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 288 | my $coords = $parsed->{coords}; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 288 | ▶ | my $has_parts = ref $coords eq 'ARRAY' && @$coords; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
ref $coords eq 'ARRAY' && @$coords
MC/DC100%2/2
ref $coords eq 'ARRAY' && @$coords
ref $coords eq 'ARRAY'
@$coords
Truth table100%3/3
A && B
A= ref $coords eq 'ARRAY'B= @$coords
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | return "${type}${dim} EMPTY" | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 288 | ▶ | if !$has_parts && ($parsed->{is_empty} || ref $coords eq 'ARRAY'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $has_parts and $parsed->{"is_empty"} || ref $coords eq "ARRAY"
$parsed->{"is_empty"} or ref $coords eq "ARRAY"
MC/DC33%1/3
not $has_parts and $parsed->{"is_empty"} || ref $coords eq "ARRAY"
not $has_parts
$parsed->{"is_empty"}
ref $coords eq "ARRAY"
Truth table75%3/4
not(A) and B or C
A= not $has_partsB= $parsed->{"is_empty"}C= ref $coords eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 207 | my $body = $class->_build_coords($parsed->{type}, $coords, $parsed); | |||||||||||||||||||||||||||||||||||||||||
| 22 | 207 | return "${type}${dim}($body)"; | |||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 207 | ▶ | sub _build_coords { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_coords: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 207 | my ($class, $type, $coords, $dim) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 207 | $type = lc($type); | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 207 | ▶ | if ($type eq 'point') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 68 | return join(' ', @$coords); | |||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 139 | ▶ | if ($type eq 'linestring') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 37 | return join(',', map { join(' ', @$_) } @$coords); | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # An empty part is EMPTY, not a list of nothing between parentheses. | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 102 | ▶ | if ($type eq 'multipoint') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 28 | ▶ | return join(',', map { @$_ ? join(' ', @$_) : 'EMPTY' } @$coords); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 74 | ▶ | if ($type eq 'polygon') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 14 | return join(',', map { '(' . join(',', map { join(' ', @$_) } @$_) . ')' } @$coords); | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 60 | ▶ | if ($type eq 'multilinestring') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | return join(',', map { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 9 | ▶ | @$_ ? '(' . join(',', map { join(' ', @$_) } @$_) . ')' : 'EMPTY' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | } @$coords); | ||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 51 | ▶ | if ($type eq 'multipolygon') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | return join(',', | ||||||||||||||||||||||||||||||||||||||||||
| 49 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 10 | @$_ | |||||||||||||||||||||||||||||||||||||||||
| 51 | 15 | ▶ | ? '(' . join(',', map { '(' . join(',', map { join(' ', @$_) } @$_) . ')' } @$_) . ')' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | : 'EMPTY' | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } @$coords | ||||||||||||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 41 | ▶ | if ($type eq 'geometrycollection') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | return join(',', map { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 41 | $class->build({ | |||||||||||||||||||||||||||||||||||||||||
| 59 | type => $_->{type}, coords => $_->{coords}, is_empty => $_->{is_empty}, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | has_z => $dim->{has_z}, has_m => $dim->{has_m}, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | }) | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 61 | } @$coords); | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | __END__ | ||||||||||||||||||||||||||||||||||||||||||