PostGIS/Codec/WKT/Builder.pm

filter: Statementstmt 97.7% 43 / 44 Branchbran 96.4% 27 / 28 Conditioncond 72.7% 8 / 11 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 91.4% 86 / 94 CC 19 SCAR 22.3
CC
19
Cov
94%
_build_coords
11.0
build
9.1
BEGIN
1.0
CRAP 9.3
« PostGIS/Codec/WKB/Decoder.pm ↑ Summary PostGIS/Geometry.pm »
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"} // ""
l!l
2880
MC/DC0%0/1
$parsed->{"type"} // ""
$parsed->{"type"}
Truth table50%1/2
A
A= $parsed->{"type"}
Aresult
11
00
13 288 ▶ my $dim = ($parsed->{has_z} ? 'Z' : '') . ($parsed->{has_m} ? 'M' : '');
Branch: 2 branches
BranchTrueFalseTotal
$parsed->{'has_z'} ? : 86 202 288
$parsed->{'has_m'} ? : 98 190 288
14 288 ▶ $dim = " $dim" if length $dim;
Branch: 1 branch
BranchTrueFalseTotal
if length $dim 150 138 288
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
!ll&&!rl&&r
1269207
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
ABresult
0X0
100
111
18 return "${type}${dim} EMPTY"
19 288 ▶ if !$has_parts && ($parsed->{is_empty} || ref $coords eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if not $has_parts and $parsed->{"is_empty"} || ref $coords eq "ARRAY" 81 207 288
Condition66%4/6
not $has_parts and $parsed->{"is_empty"} || ref $coords eq "ARRAY"
!ll&&!rl&&r
207081
$parsed->{"is_empty"} or ref $coords eq "ARRAY"
l!l&&r!l&&!r
7920
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"
ABCresult
0XX0
1000
11X1
1011
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
BranchTrueFalseTotal
if ($type eq "point") 68 139 207
30 68 return join(' ', @$coords);
31 }
32 139 ▶ if ($type eq 'linestring') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "linestring") 37 102 139
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
BranchTrueFalseTotal
if ($type eq "multipoint") 28 74 102
37 28 ▶ return join(',', map { @$_ ? join(' ', @$_) : 'EMPTY' } @$coords);
Branch: 1 branch
BranchTrueFalseTotal
@$_ ? : 48 12 60
38 }
39 74 ▶ if ($type eq 'polygon') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "polygon") 14 60 74
40 14 return join(',', map { '(' . join(',', map { join(' ', @$_) } @$_) . ')' } @$coords);
41 }
42 60 ▶ if ($type eq 'multilinestring') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "multilinestring") 9 51 60
43 return join(',', map {
44 9 ▶ @$_ ? '(' . join(',', map { join(' ', @$_) } @$_) . ')' : 'EMPTY'
Branch: 1 branch
BranchTrueFalseTotal
@$_ ? : 10 4 14
45 } @$coords);
46 }
47 51 ▶ if ($type eq 'multipolygon') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "multipolygon") 10 41 51
48 return join(',',
49 map {
50 10 @$_
51 15 ▶ ? '(' . join(',', map { '(' . join(',', map { join(' ', @$_) } @$_) . ')' } @$_) . ')'
Branch: 1 branch
BranchTrueFalseTotal
@$_ ? : 10 5 15
52 : 'EMPTY'
53 } @$coords
54 );
55 }
56 41 ▶ if ($type eq 'geometrycollection') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "geometrycollection") 41 0 41
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__
« PostGIS/Codec/WKB/Decoder.pm ↑ Summary PostGIS/Geometry.pm »