File Coverage

blib/lib/Eve/PgSqlType/Geometry.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1             package Eve::PgSqlType::Geometry;
2              
3 1     1   178666 use parent qw(Eve::PgSqlType);
  1         3  
  1         9  
4              
5             use strict;
6             use warnings;
7              
8             use DBD::Pg ();
9             use POSIX qw(strtod);
10              
11             use Eve::Geometry::Point;
12             use Eve::Geometry::Polygon;
13              
14             =head1 NAME
15              
16             B - a generic PostGIS geometry type wrapper.
17              
18             =head1 SYNOPSIS
19              
20             my $bigint = Eve::PgSqlType::Geometry->new();
21             $bigint->serialize(value => $geometry);
22              
23             =head1 DESCRIPTION
24              
25             B is a generic PostGIS type that allows
26             basic conversion from PostGIS internal format to a simple
27             B object.
28              
29             =head1 METHODS
30              
31             =head2 B
32              
33             =head3 Returns
34              
35             The PG_ANY type.
36              
37             =cut
38              
39             sub get_type {
40             return DBD::Pg::PG_ANY;
41             }
42              
43             =head2 B
44              
45             Wraps an expression with CAST statement.
46              
47             =head3 Arguments
48              
49             =over 4
50              
51             =item C
52              
53             =back
54              
55             =head3 Returns
56              
57             CAST (C AS geometry)
58              
59             =cut
60              
61             sub wrap {
62             my ($self, %arg_hash) = @_;
63             Eve::Support::arguments(\%arg_hash, my $expression);
64              
65             return 'CAST ('.$expression.' AS geometry)';
66             }
67              
68             =head2 B
69              
70             Formats a B object into the appropriate string
71             representation.
72              
73             =head3 Arguments
74              
75             =over 4
76              
77             =item C
78              
79             =back
80              
81             =head3 Returns
82              
83             The string like 'geomfromtext('POINT(XXX YYY)', 4001)'.
84              
85             =cut
86              
87             sub serialize {
88             my ($self, %arg_hash) = @_;
89             Eve::Support::arguments(\%arg_hash, my $value);
90              
91             return
92             q{(geomfromtext('} . $value->serialize() . q{', 4001))};
93             }
94              
95             =head2 B
96              
97             Parses a geometry string representation into the appropriate
98             B object.
99              
100             =head3 Arguments
101              
102             =over 4
103              
104             =item C
105              
106             =back
107              
108             =head3 Returns
109              
110             A B object.
111              
112             =cut
113              
114             sub deserialize {
115             my ($self, %arg_hash) = @_;
116             Eve::Support::arguments(\%arg_hash, my $value);
117              
118             my $result;
119             if (defined $value) {
120             $result = Eve::Geometry->from_string(string => $value);
121             }
122              
123             return $result;
124             }
125              
126             =head1 SEE ALSO
127              
128             =over 4
129              
130             =item L
131              
132             =item L
133              
134             =item L
135              
136             =back
137              
138             =head1 LICENSE AND COPYRIGHT
139              
140             Copyright 2012 Igor Zinovyev.
141              
142             This program is free software; you can redistribute it and/or modify it
143             under the terms of either: the GNU General Public License as published
144             by the Free Software Foundation; or the Artistic License.
145              
146             See http://dev.perl.org/licenses/ for more information.
147              
148              
149             =head1 AUTHOR
150              
151             =over 4
152              
153             =item L
154              
155             =back
156              
157             =cut
158              
159             1;