| 1 | 2 | ▶ | use 5.10.1; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | package DBIx::Class::InflateColumn::Geo; | ||||||||||||||
| 6 | |||||||||||||||
| 7 | # ABSTRACT: Inflate geometric columns to data structures | ||||||||||||||
| 8 | 2 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |||||||||||||
| 9 | 2 | our $VERSION = '0.0100'; | |||||||||||||
| 10 | |||||||||||||||
| 11 | 2 | ▶ | use Carp qw/confess/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | 0 | ▶ | sub register_column { | ||||||||||||
|
Subroutine
register_column: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 14 | 0 | my($self, $column, $info, @rest) = @_; | |||||||||||||
| 15 | |||||||||||||||
| 16 | 0 | $self->next::method($column, $info, @rest); | |||||||||||||
| 17 | |||||||||||||||
| 18 | 0 | ▶ | return if !(defined $info->{'data_type'}); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 19 | |||||||||||||||
| 20 | 0 | ▶ | $self->_handle_point($column, $info, @rest) if lc $info->{'data_type'} eq 'point'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 21 | } | ||||||||||||||
| 22 | |||||||||||||||
| 23 | 0 | ▶ | sub _handle_point { | ||||||||||||
|
Subroutine
_handle_point: not called CC=5 SCAR=34.0
| |||||||||||||||
| 24 | 0 | my($self, $column, $info, @rest) = @_; | |||||||||||||
| 25 | |||||||||||||||
| 26 | 0 | ▶ | my $srid = exists $info->{'geo_srid'} ? $info->{'geo_srid'} : 4326; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 27 | 0 | ▶ | my $xname = $info->{'geo_xname'} || 'x'; | ||||||||||||
|
Condition0%0/2
$info->{'geo_xname'} || 'x'
MC/DC0%0/1
$info->{'geo_xname'} || 'x'
$info->{'geo_xname'}
Truth table0%0/2
A
A= $info->{'geo_xname'}
| |||||||||||||||
| 28 | 0 | ▶ | my $yname = $info->{'geo_yname'} || 'y'; | ||||||||||||
|
Condition0%0/2
$info->{'geo_yname'} || 'y'
MC/DC0%0/1
$info->{'geo_yname'} || 'y'
$info->{'geo_yname'}
Truth table0%0/2
A
A= $info->{'geo_yname'}
| |||||||||||||||
| 29 | 0 | ▶ | my $with_astext = exists $info->{'geo_with_astext'} ? $info->{'geo_with_astext'} : 0; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 30 | |||||||||||||||
| 31 | $self->inflate_column( | ||||||||||||||
| 32 | $column => { | ||||||||||||||
| 33 | 0 | ▶ | inflate => sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||
| 34 | 0 | my($value, $object) = @_; | |||||||||||||
| 35 | |||||||||||||||
| 36 | 0 | my($astext) = $object->result_source->schema->storage->dbh->selectrow_array("SELECT ASTEXT(?)", {}, $value); | |||||||||||||
| 37 | |||||||||||||||
| 38 | 0 | ▶ | if($astext =~ m{^POINT\(([^\s]+) ([^\s]+)\)$}i) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 39 | 0 | my $result = { | |||||||||||||
| 40 | $xname => $1, | ||||||||||||||
| 41 | $yname => $2, | ||||||||||||||
| 42 | }; | ||||||||||||||
| 43 | 0 | ▶ | if($with_astext) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | 0 | $result->{'astext'} = $astext; | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | 0 | return $result; | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | 0 | return; | |||||||||||||
| 49 | }, | ||||||||||||||
| 50 | 0 | ▶ | deflate => sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||
| 51 | 0 | my($value, $object) = @_; | |||||||||||||
| 52 | |||||||||||||||
| 53 | 0 | ▶ | my $stringified = ref $value eq 'HASH' ? sprintf ('%s %s', $value->{ $xname }, $value->{ $yname }) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 54 | : ref $value eq 'ARRAY' ? "$value->[0] $value->[1]" | ||||||||||||||
| 55 | : $value | ||||||||||||||
| 56 | ; | ||||||||||||||
| 57 | |||||||||||||||
| 58 | 0 | ▶ | if($stringified =~ m/[^-+\d\s\.]/) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 59 | 0 | confess "The submitted value for column <$column> stringifies to <$stringified>, which is not suitable for POINT"; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 0 | ▶ | return $srid ? \"ST_PointFromText('POINT($stringified)', $srid)" | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 63 | : \"ST_PointFromText('POINT($stringified)')" | ||||||||||||||
| 64 | ; | ||||||||||||||
| 65 | }, | ||||||||||||||
| 66 | } | ||||||||||||||
| 67 | 0 | ); | |||||||||||||
| 68 | } | ||||||||||||||
| 69 | |||||||||||||||
| 70 | 2 | 1; | |||||||||||||
| 71 | |||||||||||||||
| 72 | __END__ | ||||||||||||||