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

filter: Statementstmt 0.0% 0 / 92 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 11 totaltotal 0.0% 0 / 141 CC 6 SCAR 15.8
CC
6
Cov
0%
command_line
12.0
file
6.0
send2file_name
6.0
CRAP 4.8
1 package App::SeismicUnixGui::misc::message;
2  
3 =head1 DOCUMENTATION
4  
5 =head2 SYNOPSIS
6  
7 PACKAGE NAME: message
8 AUTHOR: Juan Lorenzo
9 DATE: July 25 2015
10 DESCRIPTION:
11 Version: 0.0.1
12  
13 =head2 USE
14  
15 =head3 NOTES
16 communicate information to user
17  
18 =head4
19 Examples
20  
21 =head3 UNIX NOTES
22 =head4 CHANGES and their DATES
23 V0.0.2 April 4, 2020
24  
25  
26 =cut
27  
28 =head2 Declare
29 Modules
30  
31 =cut
32  
33 use Moose;
34 our $VERSION = '0.0.2';
35 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
36 #use namespace::autoclean; # best-practices hygiene
37 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
38  
39 =head2 Instantiation
40  
41 =cut
42  
43 my $Project = Project_config->new();
44 my $get = L_SU_global_constants->new();
45  
46 =head2 Declare
47 local variables
48  
49 =cut
50  
51 my $var = $get->var();
52 my $log_file_txt = $var->{_log_file_txt};
53 my $test_dir_name = $var->{_test_dir_name};
54 my $PL_SEISMIC = $Project->PL_SEISMIC();
55  
56 =head2 Defaults
57  
58 =cut
59  
60 my $PATH_start = $PL_SEISMIC;
61 my $file_name_start = $log_file_txt;
62 my $number_of_messages_start = 2;
63 my $message_start = 'hi';
64  
65 =head2 sub default_message_aref
66  
67 Initialize array
68  
69 =cut
70  
71 sub _default_message_aref_start {
72  
73 my ($self) = @_;
74  
75 my @message = (
76 $message_start,
77 $message_start,
78 );
79  
80 my $message_aref = \@message;
81 return ($message_aref);
82  
83 }
84  
85 =head2 private anonymous array
86  
87 =cut
88  
89 my $message = {
90 _text => '',
91 _this_package => '',
92  
93 };
94  
95 sub BUILD {
96 my ($this_package_address) = @_;
97  
98 $message->{_this_package} = $this_package_address;
99  
100 }
101  
102 =head2 Declare attributes
103  
104 =cut
105  
106 has 'PATH' => (
107 default => $PATH_start,
108 is => 'rw',
109 isa => 'Str',
110 writer => 'set_PATH',
111 reader => 'get_PATH',
112  
113 # trigger => \&_update_PATH,
114 );
115  
116 =head2 Declare attributes
117  
118 =cut
119  
120 has 'file_name' => (
121 default => $file_name_start,
122 is => 'rw',
123 isa => 'Str',
124 writer => 'set_file_name',
125 reader => 'get_file_name',
126 trigger => \&_update_file_name,
127 );
128  
129 =head2 Declare attributes
130  
131 =cut
132  
133 has 'message_aref' => (
134 default => \&_default_message_aref_start,
135 is => 'rw',
136 isa => 'ArrayRef',
137 writer => 'set_message_aref',
138 reader => 'get_message_aref',
139  
140 # trigger=> \&_update_message_aref,
141 );
142  
143 has 'number_of_messages' => (
144 default => $number_of_messages_start,
145 is => 'rw',
146 isa => 'Int',
147 writer => 'set_number_of_messages',
148 reader => 'get_number_of_messages',
149  
150 # trigger=> \&_update_number_of_messages,
151 );
152  
153 =head2 sub _update_file_name
154  
155 update file_name
156  
157 =cut
158  
159 sub _update_file_name {
160  
161 my ( $message, $new_current_file_name, $new_prior_file_name ) = @_;
162  
163 my $ans = $message->get_file_name();
164  
165 # print("message,_file_name,file_name= $ans NADA \n");
166  
167 return ();
168  
169 }
170  
171 =head2 sub _update_message_aref
172  
173 update message_aref
174  
175 =cut
176  
177 sub _update_message_aref {
178  
179 my ( $message, $new_current_message_aref, $new_prior_message_aref ) = @_;
180  
181 my @ans = @{$new_current_message_aref};
182  
183 # my @ans = @{$new_prior_message_aref};
184  
185 # print("1. message,_update_message_aref,message_aref= @ans \n");
186  
187 @ans = @{ $message->get_message_aref() };
188 print("2. message,_update_message_aref,message_aref= @ans \n");
189  
190 return ();
191 }
192  
193 =head2 sub _update_number_of_messages
194  
195 update file_name
196  
197 =cut
198  
199 sub _update_number_of_messages {
200  
201 my ( $message, $new_current_number_of_messages, $new_prior_number_of_messages ) = @_;
202  
203 my $ans = $message->get_number_of_messages();
204  
205 print("message,_update_number_of_messages, number_of_messages= $ans \n");
206  
207 return ();
208  
209 }
210  
211 =head2 subroutine clear
212  
213 sets all variable strings to ''
214  
215 =cut
216  
217 sub clear {
218 $message->{_text} = '';
219 }
220  
221 =head2 subroutine command_line
222 Send message to command_line
223  
224 =cut
225  
226 sub command_line {
227 my ($self) = @_;
228  
229 my $message = $message->{_this_package};
230  
231 if ( length( $message->{number_of_messages} ) ) {
232  
233 my $number_of_messages = $message->{number_of_messages};
234 my @message = @{ $message->get_message_aref() };
235  
236 for ( my $i = 0; $i < $number_of_messages; $i++ ) {
237  
238 if ( length( $message[$i] ) ) {
239  
240 print("$message[$i]\n");
241  
242 } else {
243 print("message,command_line, empty message\n");
244 }
245 }
246  
247 } else {
248 print("message,command_line, no messages to print\n");
249 my $ans = $message->{number_of_messages};
250 print("message,command_line, number_of_messages=$ans\n");
251 }
252  
253 }
254  
255  
256 =head2 subroutine file
257  
258 send message to file
259  
260 =cut
261  
262 sub file {
263 my ( $message, $text ) = @_;
264
265 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
266 localtime(time);
267  
268 $message->{_text} = $text if defined($text);
269 my $PATH = $message->get_PATH();
270 my $PATH_n_file = $PATH . '/' . $log_file_txt;
271 # print("\nmessage, file, PATH_n_file=$PATH_n_file\n");
272  
273 open( message_STDOUT, '>>', $PATH_n_file ) or die $!;
274 print message_STDOUT $text . "\n\n";
275 close(message_STDOUT);
276 }
277  
278 =head2 subroutine file_name
279  
280 send message to file_name
281  
282 =cut
283  
284 sub send2file_name {
285 my ($self) = @_;
286  
287 my $message = $message->{_this_package};
288 my $PATH = $message->get_PATH();
289  
290 if ( length $PATH
291 && length ($message->get_file_name()) ) {
292  
293 my $PATH_n_file = $PATH.'/' . $message->get_file_name();
294 my $text = @{ $message->get_message_aref() }[0];
295 my $send2file_name = $message->get_file_name();
296
297 # print("message, send2file_name, PATH=$PATH\n");
298 # print("message, send2file_name, PATH_n_file=$PATH_n_file\n");
299 # print("message, send2file_name, send2file_name=$send2file_name\n");
300
301 open( message_STDOUT, '>>', $PATH_n_file ) or die $!;
302 print message_STDOUT $text . "\n";
303 close(message_STDOUT);
304  
305 } else {
306 print("message,send2file_name, missing value(s)\n");
307 }
308  
309 }
310  
311 =head2 subroutine screen
312  
313 send message to screen
314  
315 =cut
316  
317 sub screen {
318 my ( $message, $text ) = @_;
319  
320 $message->{_text} = $text if defined($text);
321 print ("message,screen:\n$text\n\n");
322 }
323  
324  
325  
326 =head2 subroutine time
327  
328 send time to file
329  
330 =cut
331  
332 sub time {
333 my ($message) = @_;
334
335 my $text = localtime;
336  
337 my $PATH = $message->get_PATH();
338 my $PATH_n_file = $PATH . '/' . $log_file_txt;
339 # print("\nmessage, file, PATH_n_file=$PATH_n_file\n");
340  
341 open( message_STDOUT, '>>', $PATH_n_file ) or die $!;
342 print message_STDOUT $text . "\n\n";
343 close(message_STDOUT);
344  
345 }
346  
347 # a 1 is sent to perl to signify the end of the package
348 1;