DBSQL/DtHandler.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 50 CC 3 SCAR 17.5
CC
3
Cov
0%
_dbsql_dthandle_string
12.0
_dbsql_dthandle_bool
2.0
_dbsql_dthandle_date
2.0
CRAP 5.8
1 =head1 NAME
2  
3 HTML::FormEngine::DBSQL::DtHandler - DBMS datatype handlers
4  
5 =head1 GENERAL INFORMATION ABOUT DATATYPE HANDLERS
6  
7 To every handler is given:
8  
9 =over
10  
11 =item
12  
13 the object reference
14  
15 =item
16  
17 a reference to the fields form configuration hash
18  
19 =item
20  
21 a reference to a hash which contains information about the column, the
22 information is extracted with the help of DBIs C<column_info> method,
23 read the documentation of DBI for more information.
24  
25 =back
26  
27 The handler then modifies the fields configuration hash and can use
28 information out of the column information hash (which he mustn't
29 modify!).
30  
31 Which handler is called for which datatype is configured by the
32 skin. The default skin is HTML::FormEngine::DBSQL::SkinClassic.
33  
34  
35 =cut
36  
37 ######################################################################
38  
39 package HTML::FormEngine::DBSQL::DtHandler;
40  
41 # Copyright (c) 2003, Moritz Sinn. This module is free software;
42 # you can redistribute it and/or modify it under the terms of the
43 # GNU GENERAL PUBLIC LICENSE, see COPYING for more information
44  
45 ######################################################################
46  
47 use Locale::gettext;
48  
49 ######################################################################
50  
51 =head1 DATATYPE HANDLERS
52  
53 =head2 _dbsql_dthandle_string
54  
55 Sets C<templ> to I<text> and tries to determine the maximal length
56 which is then assigned to C<MAXLEN>. When C<MAXLEN> is lower
57 than the default size, C<SIZE> is set to C<MAXLEN>.
58  
59 =cut
60  
61 ######################################################################
62  
63 sub _dbsql_dthandle_string {
64 my ($self,$res,$info) = @_;
65 $res->{templ} = 'text';
66 #if($info->{dtypmod} =~ m/^[0-9]+$/ && $info->{dtypmod} > 4) {
67 if($info->{COLUMN_SIZE} =~ m/^[0-9]+$/) {
68 #$res->{MAXLEN} = $info->{dtypmod} -4;
69 $res->{MAXLEN} = $info->{COLUMN_SIZE};
70 if(! defined($self->{skin_obj}->get_default('_text', 'SIZE')) || ($res->{MAXLEN} < $self->{skin_obj}->get_default('_text','SIZE'))) {
71 $res->{SIZE} = $res->{MAXLEN};
72 }
73 }
74 }
75  
76 ######################################################################
77  
78 =head2 _dbsql_dthandle_bool
79  
80 C<templ> is set to I<select>, I<Yes> or I<No> is given as options
81 which is internally represented as 1 and 0.
82  
83 =cut
84  
85 ######################################################################
86  
87 sub _dbsql_dthandle_bool {
88 my ($self,$res) = @_;
89 $res->{templ} = 'select';
90 $res->{OPTION} = [[[gettext('Yes'),gettext('No')]]];
91 $res->{OPT_VAL} = [[['1','0']]];
92 }
93  
94 ######################################################################
95  
96 =head2 _dbsql_dthandle_date
97  
98 C<templ> is set to I<text>, C<SIZE> and C<MAXLEN> to 10 because a
99 valid date value won't need more.
100  
101 =cut
102  
103 ######################################################################
104  
105 sub _dbsql_dthandle_date {
106 my($self,$res) = @_;
107 $res->{templ} = 'text';
108 $res->{MAXLEN} = 10;
109 $res->{SIZE} = 10;
110 $res->{ERROR} = 'date';
111 }
112  
113 ######################################################################
114  
115 =head2 _dbsql_dthandle_text
116  
117 C<templ> is set to I<textarea>.
118  
119 =cut
120  
121 ######################################################################
122  
123 sub _dbsql_dthandle_text {
124 my($self,$res) = @_;
125 $res->{templ} = 'textarea';
126 }
127  
128 ######################################################################
129  
130 =head2 _dbsql_dthandle_integer
131  
132 C<ERROR> is set to C<digitonly>.
133  
134 =cut
135  
136 ######################################################################
137  
138 sub _dbsql_dthandle_integer {
139 my ($self,$res) = @_;
140 $res->{templ} = 'text';
141 $res->{ERROR} = 'digitonly';
142 }
143  
144 ######################################################################
145  
146 1;
147  
148 __END__