Eve/PgSqlType/Geometry.pm

filter: Statementstmt 100% 3 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 100% 4 / 4 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
CRAP 1.0
« Eve/PgSqlType/DriverNative.pm ↑ Summary Eve/PgSqlType/Integer.pm »
1 package Eve::PgSqlType::Geometry;
2  
3 2 ▶use parent qw(Eve::PgSqlType);
Subroutine BEGIN: called CC=1 SCAR=0.0
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<Eve::PgSqlType::Geometry> - 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<Eve::PgSqlType::Geometry> is a generic PostGIS type that allows
26 basic conversion from PostGIS internal format to a simple
27 B<Eve::Geometry> object.
28  
29 =head1 METHODS
30  
31 =head2 B<get_type()>
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<wrap()>
44  
45 Wraps an expression with CAST statement.
46  
47 =head3 Arguments
48  
49 =over 4
50  
51 =item C<expression>
52  
53 =back
54  
55 =head3 Returns
56  
57 CAST (C<expression> 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<serialize()>
69  
70 Formats a B<Eve::Geometry> object into the appropriate string
71 representation.
72  
73 =head3 Arguments
74  
75 =over 4
76  
77 =item C<value>
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<deserialize()>
96  
97 Parses a geometry string representation into the appropriate
98 B<Eve::Geometry> object.
99  
100 =head3 Arguments
101  
102 =over 4
103  
104 =item C<value>
105  
106 =back
107  
108 =head3 Returns
109  
110 A B<Eve::Geometry> 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<Eve::Geometry>
131  
132 =item L<DBD::Pg>
133  
134 =item L<Eve::PgSqlType>
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<Igor Zinovyev|mailto:zinigor@gmail.com>
154  
155 =back
156  
157 =cut
158  
159 1;
« Eve/PgSqlType/DriverNative.pm ↑ Summary Eve/PgSqlType/Integer.pm »