blib/lib/Embperl/Form/DataSource.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 14 totaltotal 0.0% 0 / 80 CC 4 SCAR 12.0
CC
4
Cov
0%
constrain_attrs
6.0
get_option_from_value
6.0
get_value_from_option
6.0
CRAP 3.3
1  
2 ###################################################################################
3 #
4 # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
5 # Embperl - Copyright (c) 2008-2015 Gerald Richter
6 # Embperl - Copyright (c) 2015-2023 actevy.io
7 #
8 # You may distribute under the terms of either the GNU General Public
9 # License or the Artistic License, as specified in the Perl README file.
10 #
11 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
12 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
13 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14 #
15 ###################################################################################
16  
17 package Embperl::Form::DataSource ;
18  
19 use strict ;
20  
21 # ---------------------------------------------------------------------------
22 #
23 # new - create a new datasource object
24 #
25  
26  
27 sub new
28  
29 {
30 my ($class, $args) = @_ ;
31  
32 my $self = {datsrc => $args -> {datasrc}} ;
33 bless $self, $class ;
34  
35 $self -> init ($args) ;
36  
37 return $self ;
38 }
39  
40 # ---------------------------------------------------------------------------
41 #
42 # init - init the new datasource object
43 #
44  
45 sub init
46  
47 {
48 my ($self) = @_ ;
49  
50 return $self ;
51 }
52  
53 # ---------------------------------------------------------------------------
54 #
55 # values_no_cache - returns true to inhibit cacheing of values during one request
56 #
57  
58 sub values_no_cache { 0 }
59  
60 # ---------------------------------------------------------------------------
61 #
62 # constrain_attrs - returns attrs that might change the form layout
63 # if there value changes
64 #
65  
66 sub constrain_attrs
67  
68 {
69 my ($self, $req) = @_ ;
70  
71 return () if (!$self -> {constrain}) ;
72 return ($self -> {constrain}) ;
73 }
74  
75 # ---------------------------------------------------------------------------
76 #
77 # get_constrain_value - returns the constrain value that is need for a
78 # search or undef if there is no constrain
79 #
80 # in $req request data
81 # $ctrl control that will display the value
82 # ret $constrain contrain value if any
83 # $without_contrain true if also values that have no contrain value
84 # are part of the resultset
85 #
86  
87 sub get_constrain_value
88  
89 {
90 my ($self, $req, $ctrl) = @_ ;
91  
92 return ;
93 }
94
95  
96 # ---------------------------------------------------------------------------
97 #
98 # get_url_modifier - returns modifier for url for requesting datasrc values (selectdyn)
99 #
100 # in $req request data
101 # $ctrl control that will display the value
102 # ret $search
103 # $replace
104 #
105  
106 sub get_url_modifier
107  
108 {
109 my ($self, $req, $ctrl) = @_ ;
110  
111 return ;
112 }
113
114 # ---------------------------------------------------------------------------
115 #
116 # get_dbname - returns dbname to pass to control (selectdyn)
117 #
118 # in $req request data
119 # $ctrl control that will display the value
120 # ret $dbname if any
121 #
122  
123 sub get_dbname
124  
125 {
126 my ($self, $req, $ctrl) = @_ ;
127  
128 return ;
129 }
130
131 # ---------------------------------------------------------------------------
132 #
133 # sorttype - returns information how to sort this datasource values for displaying
134 #
135  
136 sub sorttype { undef }
137  
138 # ---------------------------------------------------------------------------
139 #
140 # get_values - returns the values and options
141 #
142  
143 sub get_values
144  
145 {
146 my ($self, $req) = @_ ;
147  
148 die "Please overwrite get_values in " . ref $self ;
149 }
150  
151 # ---------------------------------------------------------------------------
152 #
153 # get_option_from_value - returns the option for a given value
154 #
155 # in $value value
156 # ret option
157 #
158  
159 sub get_option_from_value
160  
161 {
162 my ($self, $value, $req, $ctrl) = @_ ;
163
164
165 my ($values, $options) = $self -> get_values ($req, $ctrl) ;
166  
167 my $i = 0 ;
168 foreach (@$values)
169 {
170 if ($_ eq $value)
171 {
172 return $options -> [$i] ;
173 }
174 $i++ ;
175 }
176  
177 return ;
178 }
179  
180 # ---------------------------------------------------------------------------
181 #
182 # get_value_from_option - returns the value for a given option
183 #
184 # in $option option
185 # ret value
186 #
187  
188 sub get_value_from_option
189  
190 {
191 my ($self, $option, $req, $ctrl) = @_ ;
192
193
194 my ($values, $options) = $self -> get_values ($req, $ctrl) ;
195  
196 my $i = 0 ;
197 foreach (@$options)
198 {
199 if ($_ eq $option)
200 {
201 return $values -> [$i] ;
202 }
203 $i++ ;
204 }
205  
206 return ;
207 }
208  
209 # ---------------------------------------------------------------------------
210 #
211 # get_value_from_id - returns the value for a given id
212 #
213 # in $id id
214 # ret value
215 #
216  
217 sub get_value_from_id
218  
219 {
220 my ($self, $option, $req, $ctrl) = @_ ;
221
222 return ;
223 }
224  
225  
226 # ---------------------------------------------------------------------------
227 #
228 # get_id_from_value - returns id for a given value
229 #
230  
231 sub get_id_from_value
232  
233 {
234 my ($self, $value, $req) = @_ ;
235  
236 return $value ;
237 }
238  
239 # ---------------------------------------------------------------------------
240 #
241 # get_datasource_controls - returns additional controls provided by the
242 # datasource object e.g. a browse button
243 #
244  
245 sub get_datasource_controls
246  
247 {
248 my ($self, $req, $ctrl) = @_ ;
249  
250 return ;
251 }
252  
253  
254 1 ;
255  
256 __END__