lib/App/SeismicUnixGui/misc/param_sunix.pm untested

filter: Statementstmt 0.0% 0 / 122 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 14 totaltotal 0.0% 0 / 206 CC 11 SCAR 15.8
CC
11
Cov
0%
set_program_name
6.0
defaults
6.0
_defaults
6.0
CRAP 4.9
1 package App::SeismicUnixGui::misc::param_sunix;
2  
3 =head1 DOCUMENTATION
4  
5 =head2 SYNOPSIS
6  
7 Perl package: param_sunix.pm
8 AUTHOR: Juan Lorenzo
9 DATE: June 22 2017
10  
11 DESCRIPTION:
12 V 0.1 June 22 2017
13 V 0.2 June 23 2017
14 change class name from sunix.pm
15
16 V 0.0.2 made in June 2022
17  
18 USED FOR:
19  
20 BASED ON:
21  
22 =cut
23  
24 use Moose;
25 our $VERSION = '0.0.2';
26  
27 =pod
28  
29 private hash_ref
30 w for widgets
31  
32 =cut
33  
34 my $param_sunix = {
35 _flow_type => '',
36 _program_name => '',
37 _label_boxes_w => '',
38 _entry_boxes_w => '',
39 _check_buttons_w => '',
40 _all_aref => '',
41 _first_idx => 0,
42 _last => '',
43 _length => '',
44 _size => '',
45 };
46  
47 #has 'program_name' => (
48 # is => 'rw',
49 # isa => 'HashRef',
50 # clearer => 'clear_program_name',
51 # predicate => 'has_program_name',
52 # reader => 'get_program_name',
53 ## writer => 'set_program_name',
54 # trigger => \&set_program_name,
55 #);
56  
57 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
58  
59 use App::SeismicUnixGui::misc::su_param '0.0.3';
60 use aliased 'App::SeismicUnixGui::misc::su_param';
61  
62 my $get = L_SU_global_constants->new();
63 my $var = $get->var();
64 my $on = $var->{_on};
65 my $off = $var->{_off};
66 my $nu = $var->{_nu};
67 my $yes = $var->{_yes};
68 my $no = $var->{_no};
69 my $empty_string = $var->{_empty_string};
70  
71 =head2 sub set_program_name
72  
73 i/p is scalar ref
74 o/p is scalar ref
75  
76 =cut
77  
78 sub set_program_name {
79 my ( $self, $program_name_sref ) = @_;
80 # print("1. param_sunix, set_program_name,is $$program_name_sref\n");
81  
82 if (
83 defined $program_name_sref
84 && $program_name_sref ne $empty_string
85 && $param_sunix->{_flow_type} ne $empty_string
86 ) {
87  
88 # print("2. param_sunix, set_program_name,is $$program_name_sref\n");
89 $param_sunix->{_program_name} = $program_name_sref;
90  
91 _defaults( $param_sunix->{_program_name} );
92  
93 } else {
94 print("param_sunix, set_program_name, name or flow_type is missing \n");
95 }
96 }
97  
98 =pod
99  
100 export all the private hash references
101  
102 =cut
103  
104 sub get_all {
105 my ($self) = @_;
106  
107 _defaults( $param_sunix->{_program_name} );
108  
109 return ();
110 }
111  
112 =head2 sub defaults
113  
114 Read a default specification file
115 Debug with
116 print ("self is $self,program is $program_name\n");
117 print("params are @$ref_CFG\n");
118 program name is a hash
119 print("params are @$ref_cfg\n");
120 print ("param_sunix,defaults:program is $$program_name_sref\n");
121  
122 =cut
123  
124 sub defaults {
125 my ($program_name_sref) = @_;
126  
127 print("param_sunix,defaults,program_name is $$program_name_sref\n");
128  
129 if ( defined $program_name_sref ) {
130  
131 my $su_param = su_param->new();
132 my ( $cfg_aref, $size );
133  
134 $cfg_aref = $su_param->get($program_name_sref);
135 $param_sunix->{_all_aref} = $cfg_aref;
136 $param_sunix->{_length} = $su_param->my_length($program_name_sref);
137  
138 print("param_sunix,defaults, length:$param_sunix->{_length}\n");
139 return ();
140 }
141 }
142  
143 =head2 sub _defaults
144  
145 accessible to only methods within this file
146 and from within the pacakge
147
148 =cut
149  
150 sub _defaults {
151 my ($program_name_sref) = @_;
152  
153 # print("param_sunix,_defaults,program_name is $$program_name_sref\n");
154 # print("param_sunix,_defaults,param_sunix->{_flow_type} is $param_sunix->{_flow_type}\n");
155  
156 if ( defined $program_name_sref
157 && $param_sunix->{_flow_type} ne $empty_string ) {
158  
159 my $su_param = su_param->new();
160 my ( $cfg_aref, $size );
161  
162 $su_param->set_flow_type( $param_sunix->{_flow_type} );
163  
164 $cfg_aref = $su_param->get($program_name_sref);
165 # print("param_sunix,_defaults,cfg_aref = @{$cfg_aref}\n");
166 $param_sunix->{_all_aref} = $cfg_aref;
167 $param_sunix->{_length} = $su_param->my_length($program_name_sref);
168  
169 # print("param_sunix,_defaults, length:$param_sunix->{_length}\n");
170 return ();
171  
172 } else {
173 print("param_sunix,_defaults, missing program_name_sref\n");
174 }
175 }
176  
177 =cut
178  
179 =head2 sub first_idx
180  
181 first usable index is set to 0
182  
183 =cut
184  
185 sub first_idx {
186  
187 my ($self) = @_;
188  
189 $param_sunix->{_first_idx} = 0;
190  
191 my $result = $param_sunix->{_first_idx};
192 return ($result);
193  
194 }
195  
196 =head2 sub get_check_buttons_settings
197  
198  
199 =cut
200  
201 sub get_check_buttons_settings {
202 my ($self) = @_;
203 my $cfg_aref = $param_sunix->{_all_aref};
204 my $length = $param_sunix->{_length};
205 my ( $i, $j );
206 my @on_off;
207 my @values;
208  
209 for ( $i = 1, $j = 0; $i < $length; $i = $i + 2, $j++ ) {
210 $values[$j] = @$cfg_aref[$i];
211  
212 # print("param_sunix, get_check_buttons_settings :index..$j..values:$values[$j]\n");
213 if ( $values[$j] eq $nu
214 || $values[$j] eq "'nu'"
215 || $values[$j] eq ''
216 || $values[$j] eq "''" ) {
217 $on_off[$j] = $off;
218 } else {
219 $on_off[$j] = $on;
220 }
221  
222 # print("param_sunix: get_check_buttons_settings :index $j setting: $on_off[$j]\n");
223 }
224 return ( \@on_off );
225 }
226  
227 =head2 sub get_half_length
228  
229 return the # values or labels which is half
230 the "length" used by param_sunix internally
231  
232 =cut
233  
234 sub get_half_length {
235  
236 my ($self) = @_;
237  
238 if ( $param_sunix->{_length} ) {
239  
240 my $half_length = ( $param_sunix->{_length} ) / 2;
241  
242 # print("param_sunix, get_length, length is $length\n");
243  
244 return ($half_length);
245 } else {
246 print("param_sunix,get_length. Warning Juan,CHECK THIS CASE\n");
247 }
248  
249 }
250  
251 =head2 sub get_length4perl_flow
252  
253 return the # values or labels which is half
254 the "length" used by param_sunix internally
255  
256 =cut
257  
258 sub get_length4perl_flow {
259  
260 my ($self) = @_;
261  
262 if ( $param_sunix->{_length} ) {
263  
264 my $length = ( $param_sunix->{_length} ) / 2;
265  
266 # print("param_sunix, get_length4perl_flow , length is $length\n");
267  
268 return ($length);
269 } else {
270 print("param_sunix,get_length4perl_flow . Warning Juan,CHECK THIS CASE\n");
271 }
272  
273 }
274  
275 =head2 sub get_length
276  
277 return the # values or labels which is half
278 the "length" used by param_sunix internally
279  
280 =cut
281  
282 sub get_length {
283  
284 my ($self) = @_;
285  
286 if ( $param_sunix->{_length} ) {
287  
288 my $length = $param_sunix->{_length};
289  
290 # print("param_sunix, get_length, length is $length\n");
291  
292 return ($length);
293 } else {
294 print("param_sunix,get_length. Warning Juan,CHECK THIS CASE\n");
295 }
296  
297 }
298  
299 =head2 sub names
300  
301  
302 =cut
303  
304 sub get_names {
305 my ($self) = @_;
306 my $cfg_aref = $param_sunix->{_all_aref};
307 my $length = $param_sunix->{_length};
308 my ( $i, $j );
309 my @names;
310  
311 # print("1. param_sunix, get_names: we have length = $length\n\n");
312 for ( $i = 0, $j = 0; $i < $length; $i = $i + 2, $j++ ) {
313 $names[$j] = @$cfg_aref[$i];
314  
315 # print(" param_sunix, get_names :index $j names: $names[$j]\n");
316 }
317 return ( \@names );
318 }
319  
320 =head2 sub values
321  
322  
323 =cut
324  
325 sub get_values {
326 my ($self) = @_;
327 my $cfg_aref = $param_sunix->{_all_aref};
328 my $length = $param_sunix->{_length};
329 my ( $i, $j );
330 my @values;
331  
332 # print("cfg_aref is @$cfg_aref\n");
333  
334 for ( $i = 1, $j = 0; $i < $length; $i = $i + 2, $j++ ) {
335 $values[$j] = @$cfg_aref[$i];
336  
337 # print("param_sunix, get_values :index $j values: $values[$j]\n");
338 # print("param_sunix, get_values :index $i values: @$cfg_aref[$i]\n"); print("param_sunix, get_values :index $j values: $values[$j]\n");
339 }
340 return ( \@values );
341 }
342  
343 sub set_flow_type {
344  
345 my ( $self, $flow_type ) = @_;
346  
347 # print("param_sunix, set_flow_type ,flow_type=$flow_type\n");
348 if ( defined $flow_type
349 && $flow_type ne $empty_string ) {
350  
351 $param_sunix->{_flow_type} = $flow_type;
352  
353 # print("param_sunix, set_flow_type ,flow_type=$param_sunix->{_flow_type}\n");
354  
355 } else {
356 print("param_sunix, set_flow_type , missing value\n");
357 }
358  
359 return ();
360 }
361  
362 =head2 sub set_half_length
363  
364 length is not the last index but one beyond
365 this subroutine will FAIL if sub defaults IS NOT called first
366  
367 =cut
368  
369 sub set_half_length {
370  
371 my @self = @_;
372  
373 if ( $param_sunix->{_length} ) {
374  
375 $param_sunix->{_length} = ( $param_sunix->{_length} ) / 2;
376  
377 # print("param_sunix, set_length, length: $param_sunix->{_length}\n");
378  
379 return ();
380 } else {
381 print("param_sunix,set_length. Warning Juan,CHECK THIS CASE\n");
382 }
383  
384 }
385  
386 =head2 sub set_length
387  
388 length is not the last index but one beyond
389 this subroutine will FAIL if sub defaults IS NOT called first
390  
391 =cut
392  
393 sub set_length {
394  
395 my @self = @_;
396  
397 if ( $param_sunix->{_length} ) {
398  
399 $param_sunix->{_length} = ( $param_sunix->{_length} ) / 2;
400  
401 print("param_sunix, set_length, length: $param_sunix->{_length}\n");
402  
403 return ();
404 } else {
405 print("param_sunix,set_length. Warning Juan,CHECK THIS CASE\n");
406 }
407  
408 }
409  
410 # removes Moose exports
411 #no Moose;
412 # # increases speed
413 #__PACKAGE__->meta->make_immutable;
414 1;