« lib/App/SeismicUnixGui/misc/oop_declaration_defaults.pm
↑ Summary
lib/App/SeismicUnixGui/sunix/par/mkparfile.pm »
| 1 | package App::SeismicUnixGui::misc::oop_instantiation_defaults; | ||
| 2 | |||
| 3 | use Moose; | ||
| 4 | our $VERSION = '0.0.2'; | ||
| 5 | |||
| 6 | =head2 Default perl lines for oop_instantiation_defaults | ||
| 7 | of imported packages V 0.0.1 | ||
| 8 | ew | ||
| 9 | V 0.0.2 July 24 2018 include data_in, include data_out | ||
| 10 | V 0.0.3 4-5-19 remove duplicate program names | ||
| 11 | |||
| 12 | =cut | ||
| 13 | |||
| 14 | =head2 program parameters | ||
| 15 | |||
| 16 | private hash | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | my $oop_instantiation_defaults = { _prog_names_aref => '', }; | ||
| 21 | use aliased 'App::SeismicUnixGui::misc::manage_files_by2'; | ||
| 22 | |||
| 23 | sub section { | ||
| 24 | my ($self) = @_; | ||
| 25 | |||
| 26 | my $ref_instantiation_lines = _get_instantiation(); | ||
| 27 | return ($ref_instantiation_lines); | ||
| 28 | } | ||
| 29 | |||
| 30 | =head2 sub _get_instantiation | ||
| 31 | |||
| 32 | filter duplicates 4-5-2019 | ||
| 33 | |||
| 34 | =cut | ||
| 35 | |||
| 36 | sub _get_instantiation { | ||
| 37 | |||
| 38 | my ($self) = @_; | ||
| 39 | |||
| 40 | if ( $oop_instantiation_defaults->{_prog_names_aref} ) { | ||
| 41 | |||
| 42 | my @unique_progs; | ||
| 43 | my $unique_progs_ref; | ||
| 44 | my $num_unique_progs; | ||
| 45 | my @prog_name = @{ $oop_instantiation_defaults->{_prog_names_aref} }; | ||
| 46 | my $length = scalar @prog_name; | ||
| 47 | my @oop_instantiation_defaults; | ||
| 48 | my $filter = manage_files_by2->new(); | ||
| 49 | |||
| 50 | # default programs | ||
| 51 | $oop_instantiation_defaults[0] = | ||
| 52 | "\n\t" . 'my $log' . "\t\t\t\t\t" . '= message->new();'; | ||
| 53 | |||
| 54 | $oop_instantiation_defaults[1] = | ||
| 55 | "\t" . 'my $run' . "\t\t\t\t\t" . '= flow->new();'; | ||
| 56 | print("\n"); | ||
| 57 | |||
| 58 | # user-defined programs | ||
| 59 | # remove repeated programs from the list | ||
| 60 | $unique_progs_ref = $filter->unique_elements( \@prog_name ); | ||
| 61 | @unique_progs = @{$unique_progs_ref}; | ||
| 62 | $num_unique_progs = scalar @unique_progs; | ||
| 63 | |||
| 64 | for ( my $i = 0, my $j = 2 ; $i < $num_unique_progs ; $i++ ) { | ||
| 65 | |||
| 66 | # if(($prog_name[$i] ne 'data_out') ) { # exclude data_out module removed in V 0.0.2 | ||
| 67 | # print("2. instantiation,set_prog_names_aref, prog_name=$prog_name[$i]\n"); | ||
| 68 | $oop_instantiation_defaults[$j] = | ||
| 69 | "\t" . 'my $' | ||
| 70 | . $unique_progs[$i] | ||
| 71 | . "\t\t\t\t" | ||
| 72 | .'= ' | ||
| 73 | . $unique_progs[$i] . '->new();'; | ||
| 74 | |||
| 75 | # print $oop_instantiation_defaults[$j]; | ||
| 76 | $j++; | ||
| 77 | |||
| 78 | #} | ||
| 79 | } | ||
| 80 | return ( \@oop_instantiation_defaults ); | ||
| 81 | |||
| 82 | } | ||
| 83 | else { | ||
| 84 | print( | ||
| 85 | "instantiation,_get_instantiation, missing instantiation->{_prog_names_aref} \n" | ||
| 86 | ); | ||
| 87 | } | ||
| 88 | |||
| 89 | } | ||
| 90 | |||
| 91 | =head2 sub set_prog_names_aref | ||
| 92 | |||
| 93 | =cut | ||
| 94 | |||
| 95 | sub set_prog_names_aref { | ||
| 96 | my ( $self, $hash_aref ) = @_; | ||
| 97 | |||
| 98 | if ($hash_aref) { | ||
| 99 | $oop_instantiation_defaults->{_prog_names_aref} = | ||
| 100 | $hash_aref->{_prog_names_aref}; | ||
| 101 | |||
| 102 | } | ||
| 103 | else { | ||
| 104 | print("instantiation, set_prog_names_aref, missing hash_aref\n"); | ||
| 105 | } | ||
| 106 | |||
| 107 | return (); | ||
| 108 | } | ||
| 109 | |||
| 110 | 1; |