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