blib/lib/DBIx/Class/InflateColumn/Geo.pm

filter: Statementstmt 37.8% 14 / 37 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 4 / 8 Podpod 0.0% 0 / 1 totaltotal 25.0% 18 / 72 CC 13 SCAR 29.3
CC
13
Cov
23%
_handle_point
30.0
__ANON__
30.0
register_column
12.0
CRAP 18.8
↑ Summary
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
BranchTrueFalseTotal
unless defined $info->{"data_type"} 0 0 0
19  
20 0 ▶ $self->_handle_point($column, $info, @rest) if lc $info->{'data_type'} eq 'point';
Branch: 1 branch
BranchTrueFalseTotal
if lc $info->{"data_type"} eq "point" 0 0 0
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
BranchTrueFalseTotal
exists $info->{'geo_srid'} ? : 0 0 0
27 0 ▶ my $xname = $info->{'geo_xname'} || 'x';
Condition0%0/2
$info->{'geo_xname'} || 'x'
l!l
00
MC/DC0%0/1
$info->{'geo_xname'} || 'x'
$info->{'geo_xname'}
Truth table0%0/2
A
A= $info->{'geo_xname'}
Aresult
11
00
28 0 ▶ my $yname = $info->{'geo_yname'} || 'y';
Condition0%0/2
$info->{'geo_yname'} || 'y'
l!l
00
MC/DC0%0/1
$info->{'geo_yname'} || 'y'
$info->{'geo_yname'}
Truth table0%0/2
A
A= $info->{'geo_yname'}
Aresult
11
00
29 0 ▶ my $with_astext = exists $info->{'geo_with_astext'} ? $info->{'geo_with_astext'} : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $info->{'geo_with_astext'} ? : 0 0 0
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
BranchTrueFalseTotal
if ($astext =~ /^POINT\(([^\s]+) ([^\s]+)\)$/i) 0 0 0
39 0 my $result = {
40 $xname => $1,
41 $yname => $2,
42 };
43 0 ▶ if($with_astext) {
Branch: 1 branch
BranchTrueFalseTotal
if ($with_astext) 0 0 0
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
BranchTrueFalseTotal
ref $value eq 'HASH' ? : 0 0 0
ref $value eq 'ARRAY' ? : 0 0 0
54 : ref $value eq 'ARRAY' ? "$value->[0] $value->[1]"
55 : $value
56 ;
57  
58 0 ▶ if($stringified =~ m/[^-+\d\s\.]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stringified =~ /[^-+\d\s\.]/) 0 0 0
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
BranchTrueFalseTotal
$srid ? : 0 0 0
63 : \"ST_PointFromText('POINT($stringified)')"
64 ;
65 },
66 }
67 0 );
68 }
69  
70 2 1;
71  
72 __END__
↑ Summary