| 1 | package DBIO::PostgreSQL::PostGIS::Codec::WKT::Builder; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: WKT builder for PostGIS geometry structures | ||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||
| 8 | 6 | ▶ | sub build { | ||||||||||||||||||||||||||
|
Subroutine
build: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 9 | 6 | my ($class, $parsed) = @_; | |||||||||||||||||||||||||||
| 10 | 6 | ▶ | 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"}
| |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | my $dim = $parsed->{has_z} ? ' Z' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 12 | 6 | ▶ | $dim .= 'M' if $parsed->{has_m}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 6 | ▶ | return "${type}${dim} EMPTY" if $parsed->{is_empty}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 5 | my $body = $class->_build_coords($parsed->{type}, $parsed->{coords}); | |||||||||||||||||||||||||||
| 17 | 5 | return "${type}${dim}($body)"; | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 5 | ▶ | sub _build_coords { | ||||||||||||||||||||||||||
|
Subroutine
_build_coords: called CC=7 SCAR=22.9
| |||||||||||||||||||||||||||||
| 21 | 5 | my ($class, $type, $coords) = @_; | |||||||||||||||||||||||||||
| 22 | 5 | $type = lc($type); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 5 | ▶ | if ($type eq 'point') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 2 | return join(' ', @$coords); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | 3 | ▶ | if ($type eq 'linestring' || $type eq 'multipoint') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type eq "linestring" or $type eq "multipoint"
MC/DC50%1/2
$type eq "linestring" or $type eq "multipoint"
$type eq "linestring"
$type eq "multipoint"
Truth table66%2/3
A or B
A= $type eq "linestring"B= $type eq "multipoint"
| |||||||||||||||||||||||||||||
| 28 | 1 | return join(',', map { join(' ', @$_) } @$coords); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | 2 | ▶ | if ($type eq 'polygon' || $type eq 'multilinestring') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type eq "polygon" or $type eq "multilinestring"
MC/DC0%0/2
$type eq "polygon" or $type eq "multilinestring"
$type eq "polygon"
$type eq "multilinestring"
Truth table33%1/3
A or B
A= $type eq "polygon"B= $type eq "multilinestring"
| |||||||||||||||||||||||||||||
| 31 | 2 | return join(',', map { '(' . join(',', map { join(' ', @$_) } @$_) . ')' } @$coords); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ($type eq 'multipolygon') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | return join(',', | ||||||||||||||||||||||||||||
| 35 | map { | ||||||||||||||||||||||||||||
| 36 | 0 | '(' . join(',', map { '(' . join(',', map { join(' ', @$_) } @$_) . ')' } @$_) . ')' | |||||||||||||||||||||||||||
| 37 | } @$coords | ||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | 0 | return ''; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 7 | 1; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | __END__ | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =pod | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =head1 NAME | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | DBIO::PostgreSQL::PostGIS::Codec::WKT::Builder - WKT builder for PostGIS geometry structures | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =head1 VERSION | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | version 0.900001 | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =head1 METHODS | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head2 build | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | my $wkt = DBIO::PostgreSQL::PostGIS::Codec::WKT::Builder->build($parsed); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | Accepts the hashref returned by L<DBIO::PostgreSQL::PostGIS::Codec::WKT::Parser/parse> | ||||||||||||||||||||||||||||
| 66 | and returns a WKT string. | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | DBIO Authors | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | Copyright (C) 2026 DBIO Authors | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 77 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||