« lib/App/SeismicUnixGui/developer/code/sunix/sunix_package_clear.pm
↑ Summary
lib/App/SeismicUnixGui/sunix/NMO_Vel_Stk/sudmovz.pm »
| 1 | package App::SeismicUnixGui::misc::flow; | ||
| 2 | |||
| 3 | =head1 DOCUMENTATION | ||
| 4 | |||
| 5 | |||
| 6 | =head2 SYNOPSIS | ||
| 7 | |||
| 8 | PERL PROGRAM NAME: test.pl | ||
| 9 | AUTHOR: Juan Lorenzo | ||
| 10 | DATE: June 15 2021 | ||
| 11 | (original c. 2018) | ||
| 12 | |||
| 13 | |||
| 14 | DESCRIPTION | ||
| 15 | |||
| 16 | |||
| 17 | BASED ON: | ||
| 18 | |||
| 19 | =cut | ||
| 20 | |||
| 21 | =head2 USE | ||
| 22 | |||
| 23 | =head3 NOTES | ||
| 24 | |||
| 25 | =head4 Examples | ||
| 26 | |||
| 27 | |||
| 28 | =head2 CHANGES and their DATES | ||
| 29 | |||
| 30 | =cut | ||
| 31 | |||
| 32 | use Moose; | ||
| 33 | our $VERSION = '0.0.2'; | ||
| 34 | |||
| 35 | my $flow = { | ||
| 36 | _inbound => '', | ||
| 37 | _instructions => '', | ||
| 38 | _outbound => '', | ||
| 39 | _ref_PID => '', | ||
| 40 | _ref_list => '', | ||
| 41 | _this_package => '', | ||
| 42 | }; | ||
| 43 | |||
| 44 | =head2 Defaults | ||
| 45 | |||
| 46 | =cut | ||
| 47 | |||
| 48 | my $number_of_instructions_start = 2; | ||
| 49 | my $instruction_start = 'hi'; | ||
| 50 | |||
| 51 | sub BUILD { | ||
| 52 | my ($this_package_address) = @_; | ||
| 53 | |||
| 54 | $flow->{_this_package} = $this_package_address; | ||
| 55 | |||
| 56 | } | ||
| 57 | |||
| 58 | =head2 sub default_instruction_aref | ||
| 59 | Initialize array | ||
| 60 | |||
| 61 | =cut | ||
| 62 | |||
| 63 | sub _default_instruction_aref_start { | ||
| 64 | |||
| 65 | my ($self) = @_; | ||
| 66 | |||
| 67 | my @instruction = ( | ||
| 68 | $instruction_start, | ||
| 69 | $instruction_start, | ||
| 70 | ); | ||
| 71 | |||
| 72 | my $instruction_aref = \@instruction; | ||
| 73 | return ($instruction_aref); | ||
| 74 | |||
| 75 | } | ||
| 76 | |||
| 77 | =head2 Declare attributes | ||
| 78 | |||
| 79 | =cut | ||
| 80 | |||
| 81 | has 'instruction_aref' => ( | ||
| 82 | default => \&_default_instruction_aref_start, | ||
| 83 | is => 'rw', | ||
| 84 | isa => 'ArrayRef', | ||
| 85 | writer => 'set_instruction_aref', | ||
| 86 | reader => 'get_instruction_aref', | ||
| 87 | |||
| 88 | # trigger=> \&_update_instruction_aref, | ||
| 89 | ); | ||
| 90 | |||
| 91 | has 'number_of_instructions' => ( | ||
| 92 | default => $number_of_instructions_start, | ||
| 93 | is => 'rw', | ||
| 94 | isa => 'Int', | ||
| 95 | writer => 'set_number_of_instructions', | ||
| 96 | reader => 'get_number_of_instructions', | ||
| 97 | |||
| 98 | # trigger=> \&_update_number_of_instructions, | ||
| 99 | ); | ||
| 100 | |||
| 101 | =head2 sub _update_instruction_aref | ||
| 102 | |||
| 103 | update instruction_aref | ||
| 104 | |||
| 105 | =cut | ||
| 106 | |||
| 107 | sub _update_instruction_aref { | ||
| 108 | |||
| 109 | my ( $instruction, $new_current_instruction_aref, $new_prior_instruction_aref ) = @_; | ||
| 110 | |||
| 111 | my @ans = @{$new_current_instruction_aref}; | ||
| 112 | |||
| 113 | # my @ans = @{$new_prior_instruction_aref}; | ||
| 114 | |||
| 115 | # print("1. instruction,_update_instruction_aref,instruction_aref= @ans \n"); | ||
| 116 | |||
| 117 | @ans = @{ $instruction->get_instruction_aref() }; | ||
| 118 | print("2. flow,_update_instruction_aref,instruction_aref= @ans \n"); | ||
| 119 | |||
| 120 | return (); | ||
| 121 | } | ||
| 122 | |||
| 123 | =head2 sub _update_number_of_instructions | ||
| 124 | |||
| 125 | update file_name | ||
| 126 | |||
| 127 | =cut | ||
| 128 | |||
| 129 | sub _update_number_of_instructions { | ||
| 130 | |||
| 131 | my ( $flow, $new_current_number_of_instructions, $new_prior_number_of_instructions ) = @_; | ||
| 132 | |||
| 133 | my $ans = $flow->get_number_of_instructions(); | ||
| 134 | |||
| 135 | print("flow,_update_number_of_instructions, number_of_instructions= $ans \n"); | ||
| 136 | |||
| 137 | return (); | ||
| 138 | |||
| 139 | } | ||
| 140 | |||
| 141 | =head2 sub flow | ||
| 142 | Sending a list of instructions to | ||
| 143 | operating system to run | ||
| 144 | |||
| 145 | =cut | ||
| 146 | |||
| 147 | sub flow { | ||
| 148 | |||
| 149 | my ( $self, $ref_instructions ) = @_; | ||
| 150 | |||
| 151 | if ($ref_instructions) { | ||
| 152 | |||
| 153 | $flow->{_instructions} = $$ref_instructions; | ||
| 154 | |||
| 155 | # print("flow,flow, $flow->{_instructions}\n"); | ||
| 156 | system("$flow->{_instructions}"); | ||
| 157 | return (); | ||
| 158 | |||
| 159 | } else { | ||
| 160 | # print("flow,flow,missing instructions NADA \n"); | ||
| 161 | } | ||
| 162 | } | ||
| 163 | |||
| 164 | sub inbound { | ||
| 165 | my ( $flow, $inbound ) = @_; | ||
| 166 | $flow->{_inbound} = $inbound if defined($inbound); | ||
| 167 | } | ||
| 168 | |||
| 169 | =head2 sub modules | ||
| 170 | |||
| 171 | rearrange list of items | ||
| 172 | before sending to the | ||
| 173 | operating system to run | ||
| 174 | |||
| 175 | Debug using: | ||
| 176 | print "list length is $list_length\n\n"; | ||
| 177 | print("flow so far is $flow->{_ref_list}\n\n"); | ||
| 178 | |||
| 179 | =cut | ||
| 180 | |||
| 181 | sub modules { | ||
| 182 | my ( $flow, $ref_list ) = @_; | ||
| 183 | my $i; | ||
| 184 | |||
| 185 | if ( defined $ref_list | ||
| 186 | and ( scalar @$ref_list ) > 0 ) { # N.B. at least '&' exists | ||
| 187 | |||
| 188 | # print("flow so far is @$ref_list\n\n"); | ||
| 189 | my $list_length = $#$ref_list; | ||
| 190 | my $word = $$ref_list[0]; | ||
| 191 | |||
| 192 | for ( $i = 1; $i <= $list_length; $i++ ) { | ||
| 193 | $word = $word . $$ref_list[$i]; | ||
| 194 | } | ||
| 195 | |||
| 196 | $flow->{_ref_list} = $word; | ||
| 197 | return $flow->{_ref_list}; | ||
| 198 | |||
| 199 | } else { | ||
| 200 | print("flow,modules, empty ref_list\n\n"); | ||
| 201 | } | ||
| 202 | return (); | ||
| 203 | } | ||
| 204 | |||
| 205 | sub outbound { | ||
| 206 | my ( $flow, $outbound ) = @_; | ||
| 207 | $flow->{_outbound} = $outbound if defined($outbound); | ||
| 208 | } | ||
| 209 | |||
| 210 | =head2 sub system | ||
| 211 | |||
| 212 | sending a list of instructions to | ||
| 213 | operating system to run | ||
| 214 | |||
| 215 | =cut | ||
| 216 | |||
| 217 | sub system { | ||
| 218 | |||
| 219 | my ($self) = @_; | ||
| 220 | |||
| 221 | my $flow = $flow->{_this_package}; | ||
| 222 | |||
| 223 | my @instructions = @{ $flow->get_instruction_aref() }; | ||
| 224 | my $number_of_instructions = $flow->get_number_of_instructions(); | ||
| 225 | |||
| 226 | if ( $number_of_instructions > 0 ) { | ||
| 227 | |||
| 228 | for ( my $i=0; $i < $number_of_instructions; $i++ ) { | ||
| 229 | |||
| 230 | # print("flow, system,$instructions[$i]\n"); | ||
| 231 | system("$instructions[$i]"); | ||
| 232 | |||
| 233 | } | ||
| 234 | |||
| 235 | } else { | ||
| 236 | # print("flow,flow,missing instructions NADA\n"); | ||
| 237 | } | ||
| 238 | |||
| 239 | return (); | ||
| 240 | } | ||
| 241 | |||
| 242 | 1; |