[Bio] / Sprout / ERDBTypeRectangle.pm Repository:
ViewVC logotype

Annotation of /Sprout/ERDBTypeRectangle.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (view) (download) (as text)

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     #
4 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
5 :     # for Interpretations of Genomes. All Rights Reserved.
6 :     #
7 :     # This file is part of the SEED Toolkit.
8 :     #
9 :     # The SEED Toolkit is free software. You can redistribute
10 :     # it and/or modify it under the terms of the SEED Toolkit
11 :     # Public License.
12 :     #
13 :     # You should have received a copy of the SEED Toolkit Public License
14 :     # along with this program; if not write to the University of Chicago
15 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
16 :     # Genomes at veronika@thefig.info or download a copy from
17 :     # http://www.theseed.org/LICENSE.TXT.
18 :     #
19 :    
20 :     package ERDBTypeRectangle;
21 :    
22 :     use strict;
23 :     use Tracer;
24 :     use ERDB;
25 :     use CGI;
26 : parrello 1.2 use Rectangle;
27 : parrello 1.1 use base qw(ERDBType);
28 :    
29 :     =head1 ERDB Rectangle Descriptor Type Definition
30 :    
31 :     =head2 Introduction
32 :    
33 :     This object represents the data type for rectangular regions. The region is
34 :     described in terms of its top, left, bottom, and right coordinates. The
35 :     rectangle is represented in the database as a string of four numbers with
36 : parrello 1.3 intervening commas, and is represented in the application by a L<Rectangle>
37 : parrello 1.1 object.
38 :    
39 :     =head3 new
40 :    
41 :     my $et = ERDBTypeRectangle->new();
42 :    
43 :     Construct a new ERDBTypeRectangle descriptor.
44 :    
45 :     =cut
46 :    
47 :     sub new {
48 :     # Get the parameters.
49 :     my ($class) = @_;
50 :     # Create the ERDBTypeRectangle object.
51 :     my $retVal = { };
52 :     # Bless and return it.
53 :     bless $retVal, $class;
54 :     return $retVal;
55 :     }
56 :    
57 :     =head2 Virtual Methods
58 :    
59 :     =head3 averageLength
60 :    
61 :     my $value = $et->averageLength();
62 :    
63 :     Return the average length of a data item of this field type when it is stored in the
64 :     database. This value is used to compute the expected size of a database table.
65 :    
66 :     =cut
67 :    
68 :     sub averageLength {
69 :     return 15;
70 :     }
71 :    
72 :     =head3 prettySortValue
73 :    
74 :     my $value = $et->prettySortValue();
75 :    
76 :     Number indicating where fields of this type should go in relation to other
77 :     fields. The value should be somewhere between C<1> and C<5>. A value outside
78 :     that range will make terrible things happen.
79 :    
80 :     =cut
81 :    
82 :     sub prettySortValue() {
83 :     return 2;
84 :     }
85 :    
86 :     =head3 validate
87 :    
88 :     my $okFlag = $et->validate($value);
89 :    
90 :     Return an error message if the specified value is invalid for this field type.
91 :    
92 :     The parameters are as follows.
93 :    
94 :     =over 4
95 :    
96 :     =item value
97 :    
98 :     Value of this type, for validation.
99 :    
100 :     =item RETURN
101 :    
102 :     Returns an empty string if the specified field is valid, and an error message
103 :     otherwise.
104 :    
105 :     =back
106 :    
107 :     =cut
108 :    
109 :     sub validate {
110 :     # Get the parameters.
111 :     my ($self, $value) = @_;
112 :     # Assume it's valid until we prove otherwise.
113 :     my $retVal = "";
114 :     if (! defined $value || ref $value ne 'Rectangle') {
115 :     $retVal = "Value is not a rectangle object.";
116 :     }
117 :     # Return the determination.
118 :     return $retVal;
119 :     }
120 :    
121 :     =head3 encode
122 :    
123 :     my $string = $et->encode($value, $mode);
124 :    
125 :     Encode a value of this field type for storage in the database (or in a database load
126 :     file.)
127 :    
128 :     The parameters are as follows.
129 :    
130 :     =over 4
131 :    
132 :     =item value
133 :    
134 :     Value of this type, for encoding.
135 :    
136 :     =item mode
137 :    
138 :     TRUE if the value is being encoding for placement in a load file, FALSE if it
139 :     is being encoded for use as an SQL statement parameter. In most cases, the
140 :     encoding is the same for both modes.
141 :    
142 :     =back
143 :    
144 :     =cut
145 :    
146 :     sub encode {
147 :     # Get the parameters.
148 :     my ($self, $value, $mode) = @_;
149 :     # Declare the return variable.
150 :     my $retVal = join(",", $value->All());
151 :     # Return the result.
152 :     return $retVal;
153 :     }
154 :    
155 :     =head3 decode
156 :    
157 :     my $value = $et->decode($string);
158 :    
159 :     Decode a string from the database into a value of this field type.
160 :    
161 :     The parameters are as follows.
162 :    
163 :     =over 4
164 :    
165 :     =item string
166 :    
167 :     String from the database to be decoded.
168 :    
169 :     =item RETURN
170 :    
171 :     Returns a value of the desired type.
172 :    
173 : parrello 1.2 =back
174 :    
175 : parrello 1.1 =cut
176 :    
177 :     sub decode {
178 :     # Get the parameters.
179 :     my ($self, $string) = @_;
180 :     # Declare the return variable.
181 :     my $retVal = Rectangle->new(split /,/, $string);
182 :     # Return the result.
183 :     return $retVal;
184 :     }
185 :    
186 :     =head3 sqlType
187 :    
188 : parrello 1.4 my $typeString = $et->sqlType($dbh);
189 : parrello 1.1
190 :     Return the SQL data type for this field type.
191 :    
192 : parrello 1.4 =over 4
193 :    
194 :     =item dbh
195 :    
196 :     Open L<DBKernel> handle for the database in question. This is used when the
197 :     datatype may be different depending on the DBMS used.
198 :    
199 :     =item RETURN
200 :    
201 :     Returns the datatype string to be used when creating a field of this type in
202 :     an SQL table.
203 :    
204 :     =back
205 :    
206 : parrello 1.1 =cut
207 :    
208 :     sub sqlType {
209 :     return "VARCHAR(50)";
210 :     }
211 :    
212 :     =head3 indexMod
213 :    
214 :     my $length = $et->indexMod();
215 :    
216 :     Return the index modifier for this field type. The index modifier is the number of
217 :     characters to be indexed. If it is undefined, the field cannot be indexed. If it
218 :     is an empty string, the entire field is indexed. The default is an empty string.
219 :    
220 :     =cut
221 :    
222 :     sub indexMod {
223 :     return '';
224 :     }
225 :    
226 :     =head3 sortType
227 :    
228 :     my $letter = $et->sortType();
229 :    
230 :     Return the sorting type for this field type. The sorting type is C<n> for integers,
231 :     C<g> for floating-point numbers, and the empty string for character fields.
232 :     The default is the empty string.
233 :    
234 :     =cut
235 :    
236 :     sub sortType {
237 :     return "";
238 :     }
239 :    
240 :     =head3 documentation
241 :    
242 :     my $docText = $et->documentation();
243 :    
244 :     Return the documentation text for this field type. This should be in TWiki markup
245 :     format, though HTML will also work.
246 :    
247 :     =cut
248 :    
249 :     sub documentation() {
250 :     return 'coordinates of a rectangle';
251 :     }
252 :    
253 :     =head3 name
254 :    
255 :     my $name = $et->name();
256 :    
257 :     Return the name of this type, as it will appear in the XML database definition.
258 :    
259 :     =cut
260 :    
261 :     sub name() {
262 :     return "rectangle";
263 :     }
264 :    
265 :     =head3 default
266 :    
267 :     my $defaultValue = $et->default();
268 :    
269 :     Return the default value to be used for fields of this type if no default value
270 : parrello 1.3 is specified in the database definition or in an L<ERDBLoadGroup/Put> call
271 : parrello 1.1 during a loader operation. The default is undefined, which means an error will
272 :     be thrown during the load.
273 :    
274 :     =cut
275 :    
276 :     sub default {
277 :     return '0,0,0,0';
278 :     }
279 :    
280 :     =head3 align
281 :    
282 :     my $alignment = $et->align();
283 :    
284 :     Return the display alignment for fields of this type: either C<left>, C<right>, or
285 :     C<center>. The default is C<left>.
286 :    
287 :     =cut
288 :    
289 :     sub align {
290 :     return 'left';
291 :     }
292 :    
293 :     =head3 html
294 :    
295 :     my $html = $et->html($value);
296 :    
297 :     Return the HTML for displaying the content of a field of this type in an output
298 :     table. The default is the raw value, html-escaped.
299 :    
300 :     =cut
301 :    
302 :     sub html {
303 :     my ($self, $value) = @_;
304 :     # Convert it into a comma-separated list with enclosing angle brackets.
305 :     my $retVal = "&lt;" . join(", ", $value->All()) . "&gt;";
306 :     # Return the result.
307 :     return $retVal;
308 :     }
309 :    
310 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3