lib/App/SeismicUnixGui/developer/code/sunix/sunix_package.pm untested

filter: Statementstmt 0.0% 0 / 218 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 30 Podpod 0.0% 0 / 16 totaltotal 0.0% 0 / 297 CC 8 SCAR 12.6
CC
8
Cov
0%
set_package_name
6.0
set_param_names
6.0
set_param_values
6.0
CRAP 3.5
1 package App::SeismicUnixGui::developer::code::sunix::sunix_package;
2 use Moose;
3 our $VERSION = '0.0.1';
4  
5  
6 =head2 declare modules
7  
8 =cut
9  
10 use aliased 'App::SeismicUnixGui::developer::code::sunix::sunix_package_header';
11 use aliased
12 'App::SeismicUnixGui::developer::code::sunix::sunix_package_pod_header';
13  
14 # use App::SeismicUnixGui::developer::code::sunix::sunix_package_instantiation';
15 use aliased
16 'App::SeismicUnixGui::developer::code::sunix::sunix_package_declaration';
17 use aliased 'App::SeismicUnixGui::developer::code::sunix::sunix_package_pod';
18 use aliased
19 'App::SeismicUnixGui::developer::code::sunix::sunix_package_encapsulated';
20 use aliased
21 'App::SeismicUnixGui::developer::code::sunix::sunix_package_subroutine';
22 use aliased 'App::SeismicUnixGui::developer::code::sunix::sunix_package_use';
23 use aliased 'App::SeismicUnixGui::developer::code::sunix::sunix_package_Step';
24 use aliased 'App::SeismicUnixGui::developer::code::sunix::sunix_package_note';
25 use aliased 'App::SeismicUnixGui::developer::code::sunix::sunix_package_clear';
26 use aliased 'App::SeismicUnixGui::developer::code::sunix::sunix_package_tail';
27 use aliased 'App::SeismicUnixGui::developer::code::sunix::sunix_spec';
28 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
29  
30  
31 =head2 Instantiate modules
32  
33 =cut
34  
35 my $L_SU_global_constants = L_SU_global_constants->new();
36  
37 =head2 Extract values from
38 modules
39  
40 =cut
41 my $var = $L_SU_global_constants->var();
42 my $format = $var->{_config_file_format};
43  
44  
45 =head2 initialize shared anonymous hash
46  
47 key/value pairs
48  
49 =cut
50  
51 my $sunix_package = {
52 _config_file_out => '',
53 _spec_file_out => '',
54 _file_in => '',
55 _file_out => '',
56 _length => '',
57 _package_name => '',
58 _num_lines => '',
59 _path_out4configs => '',
60 _path_out4developer => '',
61 _path_out4specs => '',
62 _path_out4sunix => '',
63 _sudoc => '',
64 _outbound_pm => '',
65 };
66  
67 =head2 sub get_file_out
68  
69
70 =cut
71  
72 sub get_file_out {
73 my ($self) = @_;
74 my $file_out = $sunix_package->{_file_out};
75  
76 # print("1. sunix_package,get_file_out is $sunix_package->{_file_out}\n");
77 return ($file_out);
78 }
79  
80 =head2 sub set_config_file_out
81  
82 print("sunix_package,config_file_out,_config_file_out: $sunix_package->{_config_file_out}\n");
83  
84 =cut
85  
86 sub set_config_file_out {
87 my ( $self, $file_aref ) = @_;
88 $sunix_package->{_config_file_out} = @$file_aref[0];
89 }
90  
91 =head2 sub set_file_in
92  
93 print("file_in is $sunix_package->{_file_in}\n");
94  
95 =cut
96  
97 sub set_file_in {
98 my ( $self, $file_aref ) = @_;
99 $sunix_package->{_file_in} = @$file_aref[0];
100 }
101  
102 =head2 sub set_file_out
103  
104 print("1. sunix_package,file_out is $sunix_package->{_file_out}\n");
105  
106 =cut
107  
108 sub set_file_out {
109 my ( $self, $file_aref ) = @_;
110 $sunix_package->{_file_out} = @$file_aref[0];
111 }
112  
113 =head2 sub set_package_name
114  
115  
116  
117 =cut
118  
119 sub set_package_name {
120 my ( $self, $file_aref ) = @_;
121  
122 if ($file_aref) {
123  
124 $sunix_package->{_package_name} = @$file_aref[0];
125 print(
126 "sunix_package, set_package_name is $sunix_package->{_package_name}\n"
127 );
128 }
129 else {
130 print("sunix_package,set_package name, missing package name\n");
131 }
132  
133 }
134  
135 =head2 sub set_path_out4configs
136  
137
138 =cut
139  
140 sub set_path_out4configs {
141 my ( $self, $file_aref ) = @_;
142  
143 $sunix_package->{_path_out4configs} = @$file_aref[0];
144  
145 print(
146 "sunix_package,set_path_out4configs,path_out is $sunix_package->{_path_out4configs}\n"
147 );
148 }
149  
150 =head2 sub set_path_out4developer
151  
152
153 =cut
154  
155 sub set_path_out4developer {
156 my ( $self, $file_aref ) = @_;
157  
158 $sunix_package->{_path_out4developer} = @$file_aref[0];
159  
160 # print("sunix_package,set_path_out4developer,path_out is $sunix_package->{_path_out4developer}\n");
161 }
162  
163 =head2 sub set_path_out4specs
164  
165
166 =cut
167  
168 sub set_path_out4specs {
169 my ( $self, $file_aref ) = @_;
170  
171 $sunix_package->{_path_out4specs} = @$file_aref[0];
172  
173 # print(
174 #"sunix_package,set_path_out4specs,path_out is $sunix_package->{_path_out4specs}\n"
175 # );
176 }
177  
178 =head2 sub set_path_out4sunix
179  
180
181 =cut
182  
183 sub set_path_out4sunix {
184 my ( $self, $file_aref ) = @_;
185  
186 $sunix_package->{_path_out4sunix} = @$file_aref[0];
187  
188 print(
189 "sunix_package,set_path_out4sunix,path_out is $sunix_package->{_path_out4sunix}\n"
190 );
191 }
192  
193 =head2 sub set_param_names
194  
195  
196 =cut
197  
198 sub set_param_names {
199  
200 my ( $self, $names_aref ) = @_;
201  
202 if ($names_aref) {
203  
204 $sunix_package->{_param_names} = $names_aref;
205 $sunix_package->{_length} = scalar @{ $sunix_package->{_param_names} };
206  
207 # print("sunix_package,set_param_names,names: @{$names_aref}\n");
208 # print("sunix_package,set_param_names,length:$sunix_package->{_length} \n");
209  
210 }
211 else {
212 print("sunix_package,set_param_names,param_names are missing\n");
213 }
214  
215 }
216  
217 =head2 sub set_param_values
218  
219 print("sunix_package,param_values @{$sunix_package->{_param_values}}\n");
220  
221 =cut
222  
223 sub set_param_values {
224  
225 my ( $self, $values_aref ) = @_;
226  
227 if ($values_aref) {
228  
229 $sunix_package->{_param_values} = $values_aref;
230 $sunix_package->{_length} = scalar @$values_aref;
231  
232 # print("sunix_package,set_param_values,values: @{$values_aref}\n");
233 # print("sunix_package,set_param_values,length:$sunix_package->{_length} \n");
234  
235 }
236 else {
237 print("sunix_package,set_param_values,param_values are missing\n");
238 }
239 }
240  
241 =head2 sub set_spec_file_out
242  
243  
244  
245 =cut
246  
247 sub set_spec_file_out {
248 my ( $self, $file_aref ) = @_;
249 $sunix_package->{_spec_file_out} = @$file_aref[0];
250  
251 #print("sunix_package,set_spec_file_out,_spec_file_out: $sunix_package->{_spec_file_out}\n");
252 }
253  
254 =head2 sub set_sudoc_aref
255  
256 print("sunix_package,sudoc @{$sunix_package->{_sudoc_aref}}\n");
257  
258 =cut
259  
260 sub set_sudoc_aref {
261 my ( $self, $sudoc_aref ) = @_;
262  
263 if ($sudoc_aref) {
264  
265 $sunix_package->{_sudoc_aref} = $sudoc_aref;
266  
267 # my $length = scalar @$sudoc_aref;
268 # for (my $i=0; $i < $length; $i++) {
269 #
270 # print ("@{$sudoc_aref}[$i]\n");
271 #
272 # }
273 $sunix_package->{_num_lines} = scalar @$sudoc_aref;
274  
275 }
276 else {
277 print("sunix_package,missing set_sudoc_aref\n");
278 }
279  
280 }
281  
282 =pod sub write_config
283  
284 open and write configuration
285 file
286  
287 =cut
288  
289 sub write_config {
290 my ($self) = shift;
291  
292 if ( $sunix_package->{_config_file_out} && $sunix_package->{_length} )
293 { # avoids errors
294  
295 my $OUT;
296 my $outbound = $sunix_package->{_path_out4configs} . '/'
297 . $sunix_package->{_config_file_out};
298  
299 # print ("sunix_package,write_config $outbound\n");
300 print("sunix_package,write_config length=$sunix_package->{_length}\n");
301 my $i;
302 open $OUT, '>', $outbound or die;
303 for ( $i = 0 ; $i < ( $sunix_package->{_length} - 1 ) ; $i++ ) {
304 printf $OUT
305 $format."\n",
306 @{ $sunix_package->{_param_names} }[$i], '= ',
307 @{ $sunix_package->{_param_values} }[$i];
308 }
309  
310 # make last line not include a "return" which produces an annoying final empty line
311 # in the configuration file
312 # print("sunix_package,write_config length, last line=$i\n");
313 printf $OUT
314 $format,
315 @{ $sunix_package->{_param_names} }[$i], '= ',
316 @{ $sunix_package->{_param_values} }[$i];
317 close($OUT);
318 }
319 }
320  
321 =pod sub write_pm
322  
323 open and write
324 to the package
325  
326 =cut
327  
328 sub write_pm {
329 my ($self) = shift;
330  
331 print(
332 "sunix_package, write_pm: sunix_package->{_file_out}= $sunix_package->{_file_out}\n"
333 );
334 print(
335 "sunix_package, write_pm: sunix_package->{_length}= $sunix_package->{_length}\n"
336 );
337  
338 if ( $sunix_package->{_file_out} && $sunix_package->{_length} >= 0 )
339 { # avoids errors
340  
341 my $name = $sunix_package->{_package_name};
342 my $OUT;
343  
344 my $header = sunix_package_header->new();
345 my $pod_header = sunix_package_pod_header->new();
346 my $declaration = sunix_package_declaration->new();
347  
348 # TODO following 2 are both instantiations
349 my $encapsulated = sunix_package_encapsulated->new();
350  
351 # my $instantiation = sunix_package_instantiation->new();
352 my $pod = sunix_package_pod->new();
353 my $use = sunix_package_use->new();
354 my $Step = sunix_package_Step->new();
355 my $note = sunix_package_note->new();
356 my $clear = sunix_package_clear->new();
357 my $subroutine = sunix_package_subroutine->new();
358 my $tail = sunix_package_tail->new();
359  
360 # set up header
361 $header->set_package_name($name);
362 $use->make_section();
363  
364 # $instantiation ->set_package_name($name);
365 # $instantiation->make_section();
366  
367 # set up pod_header
368 $pod_header->set_prog_docs_aref( $sunix_package->{_sudoc_aref} );
369 $pod_header->set_header();
370  
371 #$declaration ->set_package_name($name);
372 $declaration->make_section();
373  
374 # set up encapsulated
375 $encapsulated->set_package_name($name);
376 $encapsulated->set_param_names( $sunix_package->{_param_names} );
377  
378 # set up Step
379 $Step->set_package_name($name);
380 $Step->set_sub_Step();
381  
382 # set up note
383 $note->set_package_name($name);
384 $note->set_sub_note();
385  
386 # set up clear
387 $clear->set_package_name($name);
388 $clear->set_param_names( $sunix_package->{_param_names} );
389  
390 # set up pod
391 # $pod->sunix_package_name($name);
392 # $pod->sudoc( $sunix_package->{_sudoc_aref} );
393  
394 # set up subroutine package_name
395 $subroutine->set_name($name);
396  
397 # HERE starts THE output PRODUCT!
398 $sunix_package->{_outbound_pm} =
399 $sunix_package->{_path_out4sunix} . '/' . $sunix_package->{_file_out};
400 print(
401 "sunix_package,write_pm, outbound=$sunix_package->{_outbound_pm}\n"
402 );
403 open $OUT, '>', $sunix_package->{_outbound_pm} or die;
404  
405 # prints out to file: package name
406 print $OUT @{ $header->get_package_name_section() };
407  
408 # prints out to file: Sunix documentation
409 print $OUT @{ $pod_header->get_section() };
410  
411 # print @{ $pod_header->get_section() };
412 # # print $OUT @{ $pod->header( $sunix_package->{_sudoc_aref} ) };
413 # # print ("sunix_package, write_pm, su documentation: @{$sunix_package->{_sudoc_aref}}[0]\n");
414  
415 # prints out to file: call to Moose
416 print $OUT @{ $header->get_Moose_section() };
417  
418 # prints out to file: Version
419 print $OUT @{ $header->get_version_section() };
420  
421 # prints out 'use...' (import packages)
422 print $OUT @{ $pod->get_use };
423 print $OUT @{ $use->get_section };
424  
425 # print @{ $pod->get_use };
426 # print @{ $use->get_section };
427  
428 # # prints out instantiation of modules (="... new..")
429 # # print $OUT @{ $instantiation->get_section };
430 ## print @{ $instantiation->get_section };
431  
432 # prints out declared variables ("my ...")
433 print $OUT @{ $pod->get_instantiation };
434 print $OUT @{ $declaration->get_section };
435  
436 # print @{ $pod->get_instantiation };
437 # print @{ $declaration->get_section };
438  
439 # prints out a private hash
440 print $OUT @{ $pod->get_encapsulated() };
441 print $OUT @{ $encapsulated->get_section() };
442  
443 # print @{ $pod->get_encapsulated() };
444 # print @{ $encapsulated->get_section() };
445  
446 # prints out a private hash
447 ## print $OUT @{ $pod->get_instantiation };
448 ## print $OUT @{ $declaration->get_section() };
449  
450 # prints out Step subroutine and pod
451 print $OUT @{ $Step->get_section() };
452  
453 # print @{ $Step->get_section() };
454  
455 # prints out note subroutine and pod
456 print $OUT @{ $note->get_section() };
457  
458 # print @{ $note->get_section() };
459  
460 # prints out clear subroutine
461 print $OUT @{ $pod->get_clear() };
462 print $OUT @{ $clear->get_section() };
463  
464 # print @{ $pod->get_clear() };
465 # print @{ $clear->get_section() };
466  
467 for ( my $i = 0 ; $i < $sunix_package->{_length} ; $i++ ) {
468  
469 $subroutine->set_param_name_aref(
470 \@{ $sunix_package->{_param_names} }[$i] );
471 $pod->subroutine_name( \@{ $sunix_package->{_param_names} }[$i] );
472  
473 print $OUT @{ $pod->section };
474 print $OUT @{ $subroutine->section };
475  
476 # print @{ $pod->section };
477 # print @{ $subroutine->section };
478 }
479  
480 # prints out sub get_max_index and '1;'
481 print $OUT @{ $tail->section };
482  
483 # print @{ $tail->section };
484  
485 # print ("sunix_package outbound $sunix_package->{_outbound_pm}\n");;
486 close($OUT);
487  
488 }
489 else {
490 print(
491 "sunix_package,write_pm, missing: sunix_package->{_file_out} and sunix_package->{_length}\n"
492 );
493 }
494  
495 }
496  
497 =pod sub write_spec
498  
499 open and write specification file
500 file
501
502 TODO
503  
504 =cut
505  
506 sub write_spec {
507 my ($self) = shift;
508
509 my $sunix_spec = sunix_spec->new();
510
511 $sunix_spec->set_path_out4specs($sunix_package->{_path_out4specs});
512
513 my $name = $sunix_package->{_package_name};
514 $sunix_spec->set_package_name($name);
515 my $header = $sunix_spec->get_header_section();
516 my $body = $sunix_spec->get_body_section();
517 my $subs = $sunix_spec->get_subroutine_section();
518 my $tail = $sunix_spec->get_tail_section();
519  
520 if ( $sunix_package->{_spec_file_out} ) { # avoids errors
521  
522 my $outbound_spec = $sunix_package->{_path_out4specs} . '/'
523 . $sunix_package->{_spec_file_out};
524  
525 # print ("sunix_package,write_spec outbound_spec= $outbound_spec \n");
526 # print ("sunix_package,write_spec, header=\n @{$header}\n");
527 # print ("sunix_package,write_spec, body=\n @{$body}\n");
528
529 open( my $OUT, '>', $outbound_spec )
530 or die "Could not open file '$outbound_spec' $!";
531  
532 my @header = @{$header};
533 for (my $j=0; $j < scalar @header; $j++ ){
534 print $OUT ("$header[$j]");
535 }
536  
537 print $OUT @{ $sunix_spec->get_body_section() };
538 print $OUT @{ $sunix_spec->get_subroutine_section() };
539 print $OUT @{$tail};
540 close $OUT;
541 }
542 }
543  
544 1;