blib/lib/File/TVShow/Organize.pm

filter: Statementstmt 97.8% 184 / 188 Branchbran 81.8% 90 / 110 Conditioncond 65.7% 23 / 35 MC/DCmcdc 36.8% 7 / 19 Subroutinesub 100% 24 / 24 Podpod 100% 15 / 15 totaltotal 87.7% 343 / 391 CC 70 SCAR 19.2
CC
70
Cov
89%
process_new_shows
13.0
create_show_hash
9.0
move_show
9.0
CRAP 6.8
↑ Summary
1 package File::TVShow::Organize;
2  
3 6 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use File::Path qw(make_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use IPC::Cmd qw(can_run);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use File::TVShow::Info;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 require Exporter;
13  
14 6 our @ISA = qw(Exporter);
15  
16 6 our $VERSION = '0.360.1';
17  
18 # Preloaded methods go here.
19  
20 sub new
21 7 ▶{
Subroutine new: called CC=4 SCAR=13.9
Pod documented
22 7 my ($class, $args) = @_;
23 my $self = {
24 #default data and states. Other data is created and stored during
25 #program execution
26 countries => "(UK|US)",
27 delete => 0,
28 verbose => 0,
29 recursion => 0,
30 seasonFolder => 1,
31 exceptionListSource => $args->{Exceptions} || undef,
32 7 ▶ };
Condition100%2/2
$args->{'Exceptions'} || undef
l!l
34
MC/DC100%1/1
$args->{'Exceptions'} || undef
$args->{'Exceptions'}
Truth table100%2/2
A
A= $args->{'Exceptions'}
Aresult
11
00
33  
34 7 bless $self, $class;
35  
36 ## Additional constructor code goes here.
37  
38 7 ▶ if (!defined $self->{exceptionListSource}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'exceptionListSource'}) { } 4 3 7
39 ## Do nothing
40 } else {
41 # create an array of pairs seperated by | character
42 3 my @list1 = split /\|/, $self->{exceptionListSource};
43 # now split each item in the array with by the : character use the first
44 # value as the key and the second as value
45 3 foreach my $item(@list1) {
46 4 my ($key, $value) = split(/:/, $item);
47 4 $self->{_exceptionList}{$key} = $value;
48 }
49 }
50 7 return $self;
51 }
52  
53 2 ▶sub countries {
Subroutine countries: called CC=2 SCAR=6.9
Pod documented
54  
55 # Set and get countries in case you want to change or add to the defaults
56 # use | as your separator
57 2 my ($self, $countries) = @_;
58 2 ▶ $self->{countries} = $countries if defined $countries;
Branch: 1 branch
BranchTrueFalseTotal
if defined $countries 1 1 2
59 2 return $self->{countries};
60 }
61  
62 58 ▶sub show_folder {
Subroutine show_folder: called CC=5 SCAR=16.2
Pod documented
63 # Set and get path for where new shows are to be stored in the file system
64 58 my ($self, $path) = @_;
65 58 ▶ if (defined $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $path) 6 52 58
66 6 ▶ if ((-e $path) and (-d $path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $path and -d $path) { } 4 2 6
Condition66%2/3
-e $path and -d $path
!ll&&!rl&&r
204
MC/DC50%1/2
-e $path and -d $path
-e $path -d $path
Truth table66%2/3
A and B
A= -e $pathB= -d $path
ABresult
0X0
100
111
67 4 $self->{showFolder} = $path;
68 # Append / if missing from path
69 4 ▶ if ($self->{showFolder} !~ m/.*\/$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"showFolder"} =~ m[.*/$]) 4 0 4
70 4 $self->{showFolder} = $self->{showFolder} . '/';
71 }
72 } else {
73 2 $self->{showFolder} = undef;
74 }
75 }
76 58 return $self->{showFolder};
77 }
78  
79 46 ▶sub new_show_folder {
Subroutine new_show_folder: called CC=5 SCAR=16.1
Pod documented
80 # Set and get path to find new files to be moved from live
81 46 my ($self, $path) = @_;
82 46 ▶ if (defined $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $path) 8 38 46
83 8 ▶ if ((-e $path) and (-d $path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $path and -d $path) { } 6 2 8
Condition66%2/3
-e $path and -d $path
!ll&&!rl&&r
206
MC/DC50%1/2
-e $path and -d $path
-e $path -d $path
Truth table66%2/3
A and B
A= -e $pathB= -d $path
ABresult
0X0
100
111
84 6 $self->{newShowFolder} = $path;
85 # Append / if missing from path
86 6 ▶ if ($self->{newShowFolder} !~ m/.*\/$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"newShowFolder"} =~ m[.*/$]) 1 5 6
87 1 $self->{newShowFolder} = $self->{newShowFolder} . '/';
88 }
89 } else {
90 2 $self->{newShowFolder} = undef;
91 }
92 }
93 46 return $self->{newShowFolder};
94 }
95  
96 4 ▶sub create_show_hash {
Subroutine create_show_hash: called CC=9 SCAR=22.0
Pod documented
97  
98 4 my ($self) = @_;
99  
100 # exit loudly if the path has not been defined by the time this is called
101 4 ▶ croak unless defined($self->{showFolder});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"showFolder"} 0 4 4
102  
103 # Get the root path of the TV Show folder
104 4 my $directory = $self->show_folder();
105 4 my $showNameHolder;
106  
107 4 ▶ opendir(DIR, $directory) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
opendir DIR, $directory or die $! 4 0 4
108 4 ▶ while (my $file = readdir(DIR)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $file = readdir DIR)) 2380 4 2384
109 2380 ▶ next if ($file =~ m/^\./); # skip hidden files and folders
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /^\./ 1196 1184 2380
110 1184 chomp($file); # trim and end of line character
111 # create the inital hash strings are converted to lower case so
112 # "Doctor Who (2005)" becomes
113 # "doctor who (2005)" key="doctor who (2005), path="Doctor Who (2005)
114 1184 $self->{shows}{lc($file)}{path} = $file;
115 # hanle if there is US or UK in the show name
116 1184 ▶ if ($file =~ m/\s\(?$self->{countries}\)?$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\s\(?$self->{"countries"}\)?$/i) 40 1144 1184
117 40 $showNameHolder = $file;
118 # name minus country in $1 country in $2
119 40 $showNameHolder =~ s/(.*) \(?($self->{countries})\)?/$1/gi;
120 #catinate them together again with () around country
121 #This is now another key to the same path
122 40 $self->{shows}{lc($showNameHolder . " ($2)")}{path} = $file;
123 # create a key to the same path again with out country unless one has
124 # been already defined by another show
125 # this handles something like "Prey" which has a "Prey US" version
126 # and "Prey UK"
127 40 ▶ $self->{shows}{lc($showNameHolder)}{path} = $file unless (exists $self->{shows}{lc($showNameHolder)});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"shows"}{lc $showNameHolder} 28 12 40
128 }
129 # Handle shows with Year extensions in the same manner has UK|USA
130 1184 ▶ if ($file =~ m/\s\(?\d{4}\)?$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\s\(?\d{4}\)?$/i) 80 1104 1184
131 80 $showNameHolder = $file;
132 80 $showNameHolder =~ s/(.*) \(?(\d\d\d\d)\)?/$1/gi;
133 80 $self->{shows}{lc($showNameHolder . " ($2)")}{path} = $file;
134 80 $self->{shows}{lc($showNameHolder . " $2")}{path} = $file;
135 $self->{shows}{lc($showNameHolder)}{path} = $file unless
136 80 ▶ (exists $self->{shows}{lc($showNameHolder)});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"shows"}{lc $showNameHolder} 72 8 80
137 }
138 }
139 4 closedir(DIR);
140 # Does this need to return anything or can it just return $self
141 4 return $self->{shows};
142  
143 }
144  
145 1 ▶sub clear_show_hash {
Subroutine clear_show_hash: called CC=1 SCAR=0.0
Pod documented
146 1 my ($self) = @_;
147  
148 1 $self->{shows} = ();
149 1 return $self;
150 }
151  
152 121 ▶sub show_path {
Subroutine show_path: called CC=1 SCAR=0.0
Pod documented
153  
154 # Access the shows hash and return the correct directory path for the show
155 # name as passed to the funtion
156 121 my ($self, $show) = @_;
157 121 return $self->{shows}{lc($show)}{path};
158 }
159  
160 7 ▶sub process_new_shows {
Subroutine process_new_shows: called CC=13 SCAR=25.7
Pod documented
161  
162 7 my ($self, $curr_dir) = @_;
163 7 ▶ $curr_dir = $self->new_show_folder() unless defined($curr_dir);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $curr_dir 5 2 7
164  
165 7 my $destination;
166  
167 7 ▶ opendir(DIR, $curr_dir) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
opendir DIR, $curr_dir or die $! 7 0 7
168 7 ▶ while (my $file = readdir(DIR)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $file = readdir DIR)) 128 7 135
169 128 $destination = undef;
170 ## Skip hiddenfiles
171 128 ▶ next if ($file =~ m/^\./);
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /^\./ 71 57 128
172 ## Trim the file name incase of end of line marker
173 57 chomp($file);
174 ## Skip files that have been processed before. They have had .done appended
175 # to to them.
176 57 ▶ next if ($file =~ m/\.done$/);
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /\.done$/ 0 57 57
177 57 ▶ if (!$self->recursion) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->recursion) { } 32 25 57
178 32 ▶ next if -d $self->new_show_folder() . $file; ## Skip non-Files
Branch: 1 branch
BranchTrueFalseTotal
if -d $self->new_show_folder . $file 2 30 32
179 } else {
180 25 ▶ $self->process_new_shows($curr_dir . $file . "/") if -d $curr_dir . $file;
Branch: 1 branch
BranchTrueFalseTotal
if -d $curr_dir . $file 2 23 25
181 };
182 # next if ($file !~ m/s\d\de\d\d/i); # skip if SXXEXX is not present in file name
183 55 my $showData;
184 # Extract show name, Season and Episode
185 55 $showData = File::TVShow::Info->new($file);
186 55 ▶ next if !$showData->is_tv_show();
Branch: 1 branch
BranchTrueFalseTotal
unless $showData->is_tv_show 6 49 55
187 # Apply special handling if the show is in the _exceptionList
188 49 ▶ if (exists $self->{_exceptionList}{$showData->{organize_name}}) { ##Handle special cases like "S.W.A.T"
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'_exceptionList'}{$showData->{'organize_name'}}) { } 2 47 49
189 # Replace the original name value with the one found in _exceptionList
190 2 $showData->{organize_name} = $self->{_exceptionList}{$showData->{organize_name}};
191 } else {
192 # Handle normally using '.' as the space marker name "Somthing.this" becomes "Something this"
193 # Strip periods from name.
194 47 $showData->{organize_name} =~ s/\./ /g;
195 }
196  
197 # If we don't have a show_path skip. Probably an unhandled show name
198 # store it in the UnhandledFileNames hash for reporting later.
199 49 ▶ if (!defined $self->show_path($showData->{organize_name})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->show_path($showData->{"organize_name"})) 2 47 49
200 2 $self->{UnhandledFileNames}{$file} = $showData->{organize_name};
201 2 next;
202 }
203 # Create the path string for storing the file in the right place
204 47 $destination = $self->show_folder() . $self->show_path($showData->{organize_name});
205 # if this is true. Update the $destination and create the season subfolder if required.
206 # if this is false. Do not append the season folder. files should just be stored in the root of the show folder.
207 47 ▶ if($self->season_folder()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->season_folder) 45 2 47
208 45 $destination = $self->create_season_folder($destination, int($showData->{season}));
209 };
210 # Import the file. This will use rsync to copy the file into place and either rename or delete.
211 # see move_show() for implementation details
212 47 $self->move_show($destination, $curr_dir, $file);
213 }
214 7 close(DIR);
215 7 return;
216 #return $self;
217 }
218  
219 1 ▶sub were_there_errors {
Subroutine were_there_errors: called CC=4 SCAR=14.2
Pod documented
220  
221 1 my ($self) = @_;
222  
223 # Check if there has been any files that File::TVShow::Info could not handle
224 # Check that the hash UnHandledFileNames has actually been created before
225 # checking that is is not empty or you will get an error.
226 1 ▶ if ((defined $self->{UnhandledFileNames}) && (keys %{$self->{UnhandledFileNames}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"UnhandledFileNames"} and keys %{$$self{"UnhandledFileNames"};}) 1 0 1
Condition33%1/3
defined $self->{"UnhandledFileNames"} and keys %{$$self{"UnhandledFileNames"};}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $self->{"UnhandledFileNames"} and keys %{$$self{"UnhandledFileNames"};}
defined $self->{"UnhandledFileNames"} keys %{$$self{"UnhandledFileNames"};}
Truth table33%1/3
A and B
A= defined $self->{"UnhandledFileNames"}B= keys %{$$self{"UnhandledFileNames"};}
ABresult
0X0
100
111
227 1 print "\nThere were unhandled files in the directory\n";
228 1 print "consider adding them to the exceptionList\n###\n";
229 1 foreach my $key (keys %{$self->{UnhandledFileNames}}) {
230 1 print "### " . $key . " ==> " . $self->{UnhandledFileNames}{$key} . "\n";
231 }
232 1 print "###\n";
233 }
234  
235 1 return $self;
236 }
237  
238 7 ▶sub delete {
Subroutine delete: called CC=7 SCAR=19.6
Pod documented
239  
240 7 my ($self, $delete) = @_;
241  
242 7 ▶ return $self->{delete} if(@_ == 1);
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 2 5 7
243  
244 5 ▶ if (($delete =~ m/[[:alpha:]]/) || ($delete != 0) && ($delete != 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delete =~ /[[:alpha:]]/ or $delete != 0 and $delete != 1) { } 1 4 5
Condition66%4/6
$delete =~ /[[:alpha:]]/ or $delete != 0 and $delete != 1
l!l&&r!l&&!r
104
$delete != 0 and $delete != 1
!ll&&!rl&&r
130
MC/DC33%1/3
$delete =~ /[[:alpha:]]/ or $delete != 0 and $delete != 1
$delete =~ /[[:alpha:]]/ $delete != 0 $delete != 1
Truth table75%3/4
A or B and C
A= $delete =~ /[[:alpha:]]/B= $delete != 0C= $delete != 1
ABCresult
1XX1
0111
00X0
0100
245 1 print STDERR "Invalid arguments passed. Value not updated\n";
246 1 return undef;
247 } else {
248 4 ▶ if ($delete == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($delete == 1) { } 3 1 4
elsif ($delete == 0) { } 1 0 1
249 3 $self->{delete} = 1;
250 } elsif ($delete == 0) {
251 1 $self->{delete} = 0;
252 }
253  
254 # This return seems like its on a branch of code that is of litle use.
255 # Unless the return is checked on being set.
256  
257 4 return $self->{delete};
258 }
259 }
260  
261 63 ▶sub recursion {
Subroutine recursion: called CC=7 SCAR=19.6
Pod documented
262  
263 63 my ($self, $recursion) = @_;
264  
265 63 ▶ return $self->{recursion} if(@_ == 1);
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 59 4 63
266  
267 4 ▶ if (($recursion =~ m/[[:alpha:]]/) || ($recursion != 0) && ($recursion != 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recursion =~ /[[:alpha:]]/ or $recursion != 0 and $recursion != 1) { } 1 3 4
Condition66%4/6
$recursion =~ /[[:alpha:]]/ or $recursion != 0 and $recursion != 1
l!l&&r!l&&!r
103
$recursion != 0 and $recursion != 1
!ll&&!rl&&r
120
MC/DC33%1/3
$recursion =~ /[[:alpha:]]/ or $recursion != 0 and $recursion != 1
$recursion =~ /[[:alpha:]]/ $recursion != 0 $recursion != 1
Truth table75%3/4
A or B and C
A= $recursion =~ /[[:alpha:]]/B= $recursion != 0C= $recursion != 1
ABCresult
1XX1
0111
00X0
0100
268 1 print STDERR "Invalid arguments passed. Value not updated\n";
269 1 return undef;
270 } else {
271 3 ▶ if ($recursion == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($recursion == 1) { } 2 1 3
elsif ($recursion == 0) { } 1 0 1
272 2 $self->{recursion} = 1;
273 } elsif ($recursion == 0) {
274 1 $self->{recursion} = 0;
275 }
276  
277 # This return seems like its on a branch of code that is of litle use.
278 # Unless the return is checked on being set.
279 3 return $self->{recursion};
280 }
281 }
282  
283 97 ▶sub verbose {
Subroutine verbose: called CC=7 SCAR=19.6
Pod documented
284 97 my ($self, $verbose) = @_;
285  
286 97 ▶ return $self->{verbose} if(@_ == 1);
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 94 3 97
287  
288 3 ▶ if (($verbose =~ m/[[:alpha:]]/) || ($verbose != 0) && ($verbose != 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose =~ /[[:alpha:]]/ or $verbose != 0 and $verbose != 1) { } 1 2 3
Condition66%4/6
$verbose =~ /[[:alpha:]]/ or $verbose != 0 and $verbose != 1
l!l&&r!l&&!r
102
$verbose != 0 and $verbose != 1
!ll&&!rl&&r
110
MC/DC33%1/3
$verbose =~ /[[:alpha:]]/ or $verbose != 0 and $verbose != 1
$verbose =~ /[[:alpha:]]/ $verbose != 0 $verbose != 1
Truth table75%3/4
A or B and C
A= $verbose =~ /[[:alpha:]]/B= $verbose != 0C= $verbose != 1
ABCresult
1XX1
0111
00X0
0100
289 1 print STDERR "\n### Invalid arguments passed. Value not updated\n";
290 1 return undef;
291 } else {
292 2 ▶ if ($verbose == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($verbose == 1) { } 1 1 2
elsif ($verbose == 0) { } 1 0 1
293 1 $self->{verbose} = 1;
294 } elsif ($verbose == 0) {
295 1 $self->{verbose} = 0;
296 }
297 # This return seems like its on a branch of code that is of litle use.
298 # Unless the return is checked on being set.
299  
300 2 return $self->{verbose};
301 }
302 }
303  
304 53 ▶sub season_folder {
Subroutine season_folder: called CC=7 SCAR=19.6
Pod documented
305 53 my ($self, $seasonFolder) = @_;
306  
307 53 ▶ return $self->{seasonFolder} if(@_ == 1);
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 49 4 53
308  
309 4 ▶ if (($seasonFolder =~ m/[[:alpha:]]/) || ($seasonFolder != 0) && ($seasonFolder != 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seasonFolder =~ /[[:alpha:]]/ or $seasonFolder != 0 and $seasonFolder != 1) { } 1 3 4
Condition66%4/6
$seasonFolder =~ /[[:alpha:]]/ or $seasonFolder != 0 and $seasonFolder != 1
l!l&&r!l&&!r
103
$seasonFolder != 0 and $seasonFolder != 1
!ll&&!rl&&r
210
MC/DC33%1/3
$seasonFolder =~ /[[:alpha:]]/ or $seasonFolder != 0 and $seasonFolder != 1
$seasonFolder =~ /[[:alpha:]]/ $seasonFolder != 0 $seasonFolder != 1
Truth table75%3/4
A or B and C
A= $seasonFolder =~ /[[:alpha:]]/B= $seasonFolder != 0C= $seasonFolder != 1
ABCresult
1XX1
0111
00X0
0100
310 1 print STDERR "\n### Invalid arguments passed. Value not updated\n";
311 1 return undef;
312 } else {
313 3 ▶ if ($seasonFolder == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($seasonFolder == 1) { } 1 2 3
elsif ($seasonFolder == 0) { } 2 0 2
314 1 $self->{seasonFolder} = 1;
315 } elsif ($seasonFolder == 0) {
316 2 $self->{seasonFolder} = 0;
317 }
318 # This return seems like its on a branch of code that is of litle use.
319 # Unless the return is checked on being set.
320 3 return $self->{seasonFolder};
321 }
322 }
323  
324 45 ▶sub create_season_folder {
Subroutine create_season_folder: called CC=5 SCAR=16.7
Pod documented
325  
326 45 my ($self, $_path, $season) = @_;
327  
328 45 my $path = $_path . '/';
329  
330 45 ▶ if ($season == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($season == 0) { } 6 39 45
331 6 $path = $path . 'Specials'
332 } else {
333 39 $path = $path . 'Season' . $season;
334 }
335 # Show Season folder being created if verbose mode is true.
336 45 ▶ if($self->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) { } 0 45 45
337 0 ▶ make_path($path, { verbose => 1 }) unless -e $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $path 0 0 0
338 } else {
339 # Verbose mode is false so work silently.
340 45 ▶ make_path($path) unless -e $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $path 15 30 45
341 }
342 45 return $path;
343 }
344  
345  
346 47 ▶sub move_show {
Subroutine move_show: called CC=7 SCAR=22.0
Pod documented
347  
348 47 my ($self, $destination, $source, $file) = @_;
349  
350 # If the destination folder or source filder are not defined or no file is
351 # passed exit with errors
352 47 ▶ carp "Destination not passed." unless defined($destination);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $destination 0 47 47
353 47 ▶ carp "Source not passed." unless defined($source);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $source 0 47 47
354 47 ▶ carp "File not passed." unless defined($file);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 47 47
355  
356 # rewrite paths so they are rsync friendly. This means escape spaces and
357 # other special characters.
358 47 ($destination, $source) = _rsync_prep ($destination,$source);
359  
360 # create the command string to be used in system() call
361 # Set --progress if verbose is true
362  
363 # Get path to rsync using IPC::Cmd
364 47 my $command = can_run('rsync');
365 47 $command .= " -ta ";
366 47 ▶ $command = $command . "--progress " if ($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 47 47
367 47 $command = $command . $source . $file . " " . $destination;
368  
369 47 system($command);
370  
371 47 ▶ if($? == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? == 0) { } 0 47 47
372 # If delete is true unlink file.
373 0 ▶ if($self->delete) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->delete) { } 0 0 0
374 0 unlink($source . $file);
375 } else {
376 # delete is false so merely rename the file by appending .done
377 0 move($source . $file, $source . $file . ".done")
378 }
379 } else {
380 #report failed processing? Error on rsync command return code
381 47 print "## Something went very wrong. Rsync failed for some reason.\n";
382 47 print "## rsync err $?\n";
383 }
384 47 return $self;
385  
386 }
387  
388 # This interal sub-routine prepares paths for use with external rsynch command
389 # Need to escape special characters
390 47 ▶sub _rsync_prep {
Subroutine _rsync_prep: called CC=1 SCAR=0.0
391  
392 47 my ($dest, $source) = @_;
393  
394 # escape spaces and () characters to work with the rsync command.
395 47 $dest =~ s/\(/\\(/g;
396 47 $dest =~ s/\)/\\)/g;
397 47 $dest =~ s/ /\\ /g;
398 47 $dest = $dest . "/";
399  
400 47 $source =~ s/ /\\ /g;
401 #$source = $source . "/";
402  
403 47 return $dest, $source;
404 }
405  
406 6 1;
407  
408  
409 __END__
↑ Summary