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

filter: Statementstmt 0.0% 0 / 75 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 131 CC 11 SCAR 23.6
CC
11
Cov
0%
get_file_list_aref
20.0
get_list_aref
20.0
_get_contents_aref
12.0
CRAP 10.6
1 package App::SeismicUnixGui::misc::manage_dirs_by;
2  
3 use Moose;
4 our $VERSION = '0.0.1';
5  
6 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
7  
8 my $L_SU_global_constants = L_SU_global_constants->new();
9 my $var = {_skip_directory => 'archive',};
10  
11 # manage_dirs_by class
12 # Contains methods/subroutines/functions to operate on directories
13 # V 1. March 3 2008
14 # Juan M. Lorenzo
15  
16 =head2 private hash of shared variables
17  
18 =cut
19  
20 my $manage_dirs_by = {
21  
22 _directory => '',
23  
24 };
25  
26 =head2 clear shared variable(s)
27 in memory
28  
29  
30 =cut
31  
32 sub clear {
33  
34 $manage_dirs_by->{_directory} = '';
35  
36 }
37  
38 =head2 sub _get_contents_aref
39  
40 Reference of array with contents of
41 the search directory
42  
43 =cut
44  
45 sub _get_contents_aref {
46  
47 my ($self) = @_;
48  
49 my $result_aref;
50  
51 if ( length $manage_dirs_by->{_directory} ) {
52  
53 my $SEARCH_DIR = $manage_dirs_by->{_directory};
54  
55 # print("manage_dirs_by, _get_contents_aref, SEARCH_DIR=$SEARCH_DIR\n");
56  
57 if ( opendir( DIR, $SEARCH_DIR ) ) {
58  
59 my @directory_list = readdir(DIR);
60  
61 $result_aref = \@directory_list;
62 # print("manage_dirs_by, _get_contents_aref, directory_list=@directory_list\n");
63 close(DIR);
64  
65 }
66 else {
67 # print("manage_dirs_by, _get_contents_aref,directory not found; NADA\n");
68 }
69  
70 }
71 else {
72 # print("manage_dirs_by, _get_contents_aref, missing directory; NADA\n");
73 }
74 return ($result_aref);
75 }
76  
77 sub get_file_list_aref {
78  
79 my ($self) = @_;
80  
81 my $list_aref;
82 my @filtered_directory;
83  
84 if ( length $manage_dirs_by->{_directory} ) {
85  
86 $list_aref = _get_contents_aref();
87  
88 if ( length $list_aref ) {
89  
90 my @directory_list = @$list_aref;
91  
92 foreach my $thing (@directory_list) {
93  
94 if ( $thing eq '.'
95 or $thing eq '..'
96 or $thing eq $var->{_skip_directory} )
97 {
98 # print(
99 # "manage_dirs_by, get_file_list_aref,skip directory\n");
100 # print("manage_dirs_by, get_file_list_aref,thing:$thing\n");
101 next;
102  
103 }
104 else {
105 push @filtered_directory, $thing;
106 }
107 }
108  
109 my $result_aref = \@filtered_directory;
110 # print ("manage_dirs_byfiltered directory = @filtered_directory\n");
111 return ($result_aref);
112  
113 }
114 else {
115 # print("manage_dirs_by,get_file_list_aref, empty directory list NADA\n");
116 return();
117 }
118  
119 }
120 else {
121 print("manage_dirs_by,$self,get_list_aref missing variable\n");
122 return ();
123 }
124
125 }
126  
127 sub get_list_aref {
128  
129 my ($self) = @_;
130  
131 my $list_aref;
132 my @filtered_directory;
133  
134 if ( length $manage_dirs_by->{_directory} ) {
135  
136 $list_aref = _get_contents_aref;
137  
138 if ( length $list_aref ) {
139  
140 my @directory_list = @$list_aref;
141 @filtered_directory = @directory_list;
142  
143 foreach my $thing (@directory_list) {
144  
145 if ( $thing eq '.'
146 or $thing eq '..' )
147 {
148  
149 next;
150  
151 }
152 else {
153 push @filtered_directory, $thing;
154 print("manage_dirs_by, get_list_aref,filtered_directory= $thing\n");
155 }
156 }
157  
158 my $result_aref = \@filtered_directory;
159 return ($result_aref);
160  
161 }
162 else {
163 print("empty directory list NADA\n");
164 }
165  
166 }
167 else {
168 print("manage_dirs_by,$self,get_list_aref missing variable\n");
169 return ();
170 }
171  
172 }
173  
174 sub lsc1_dir_files {
175  
176 # this function makes a list of the directory contents
177 # one file name per line
178 # leaves the list inside the directory of interest
179 # writes the list to .lsc1
180 #get directory names
181 my ($directory) = shift @_;
182 system(
183 " cd $directory; \\
184 ls -c1 > .lsc1; \\
185 "
186 );
187 }
188  
189 sub lsc1_grep_dir_files {
190  
191 # this function makes a list of the directory contents
192 # one file name per line
193 # leaves the list inside the directory of interest
194 # writes the list to .lsc1_grep
195  
196 #get directory names
197 my ($directory) = shift @_;
198 my ($pattern) = shift @_;
199  
200 #$pattern = 'asc';
201 print("pattern-$pattern\n\n");
202 print("directory-$directory\n\n");
203 system(
204 " cd $directory; \\
205 ls -c1 | grep $pattern |sort -n > .lsc1_grep;\\
206 "
207 );
208 }
209  
210 sub make_dir {
211  
212 # this function/method makes a directory
213 # if it does not exist already
214  
215 # get directory names
216 my ($self, $directory) = @_;
217  
218 # print ("\nmanage_dirs_by, make_dir, Making directories----$self, $directory---\n");
219  
220 system(
221 " \\
222 mkdir -p $directory \\
223 "
224 );
225  
226 }
227  
228 sub rm_dir {
229  
230 # this function/method deletes a directory
231  
232 #get directory names
233 my ($directory) = shift @_;
234  
235 print("\n Cleaning directory $directory \n");
236  
237 system(
238 " \\
239 rm -r $directory \\
240 "
241 );
242 }
243  
244 sub set_directory {
245  
246 my ( $self, $dir ) = @_;
247  
248 if ( length $dir ) {
249  
250 $manage_dirs_by->{_directory} = $dir;
251 # print("manage_dirs_by, set_directory, manage_dirs_by->{_directory}=$manage_dirs_by->{_directory}\n");
252  
253 }
254 else {
255 print("manage_dirs_by,self=$self, set_directory, missing variable\n");
256 }
257 return ();
258  
259 }
260  
261 sub set_suffix_type {
262  
263 my ( $self, $suffix_type ) = @_;
264  
265 if ( length $suffix_type ) {
266  
267 }
268 else {
269 print("manage_dirs_by,$self, set_suffix_type, missing variable\n");
270 }
271  
272 return ();
273 }
274  
275 1;