| 1 | package App::Followme::UploadLocal; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use 5.008005; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 2 | ▶ | use lib '../..'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 2 | ▶ | use base qw(App::Followme::ConfiguredObject); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 2 | ▶ | use File::Copy; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 2 | ▶ | use File::Path qw(remove_tree); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 2 | ▶ | use File::Spec::Functions qw(abs2rel splitdir catfile); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 2 | our $VERSION = "2.03"; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | #---------------------------------------------------------------------- | ||||||||||||||||||||
| 18 | # Read the default parameter values | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 12 | ▶ | sub parameters { | ||||||||||||||||||
|
Subroutine
parameters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 21 | 12 | my ($pkg) = @_; | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | return ( | ||||||||||||||||||||
| 24 | 12 | remote_directory => '', | |||||||||||||||||||
| 25 | permissions => 0644, | ||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | #---------------------------------------------------------------------- | ||||||||||||||||||||
| 30 | # Add a directory to the remote site | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 2 | ▶ | sub add_directory { | ||||||||||||||||||
|
Subroutine
add_directory: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 33 | 2 | my ($self, $dir) = @_; | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 2 | my $new_dir = catfile($self->{remote_directory}, $dir); | |||||||||||||||||||
| 36 | 2 | my $status = mkdir($new_dir); | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 2 | ▶ | if ($status) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | 2 | my $permissions = $self->{permissions} | 0111; | |||||||||||||||||||
| 40 | 2 | chmod($permissions, $new_dir); | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 2 | return $status; | |||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | #---------------------------------------------------------------------- | ||||||||||||||||||||
| 47 | # Add a file to the remote site | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 8 | ▶ | sub add_file { | ||||||||||||||||||
|
Subroutine
add_file: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 50 | 8 | my ($self, $local_filename, $remote_filename) = @_; | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 8 | my $new_file = catfile($self->{remote_directory}, $remote_filename); | |||||||||||||||||||
| 53 | 8 | my $status = copy($local_filename, $new_file); | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 8 | ▶ | chmod($self->{permissions}, $new_file) if $status; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 8 | return $status; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | #---------------------------------------------------------------------- | ||||||||||||||||||||
| 60 | # Close the connection | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 1 | ▶ | sub close { | ||||||||||||||||||
|
Subroutine
close: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 63 | 1 | my ($self) = @_; | |||||||||||||||||||
| 64 | 1 | return; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | #---------------------------------------------------------------------- | ||||||||||||||||||||
| 68 | # Delete a directory from the remote site | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 1 | ▶ | sub delete_directory { | ||||||||||||||||||
|
Subroutine
delete_directory: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 71 | 1 | my ($self, $dir) = @_; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 1 | my $err; | |||||||||||||||||||
| 74 | 1 | my $new_dir = catfile($self->{remote_directory}, $dir); | |||||||||||||||||||
| 75 | 1 | remove_tree($new_dir, {error => $err}); | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 1 | ▶ | my $status = ! ($err && @$err); | ||||||||||||||||||
|
Condition33%1/3
$err && @$err
MC/DC0%0/2
$err && @$err
$err
@$err
Truth table33%1/3
A && B
A= $errB= @$err
| |||||||||||||||||||||
| 78 | 1 | return $status; | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | #---------------------------------------------------------------------- | ||||||||||||||||||||
| 82 | # Delete a file from the remote site | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 1 | ▶ | sub delete_file { | ||||||||||||||||||
|
Subroutine
delete_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 85 | 1 | my ($self, $filename) = @_; | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 1 | my $new_file = catfile($self->{remote_directory}, $filename); | |||||||||||||||||||
| 88 | 1 | my $status = unlink($new_file); | |||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 1 | return $status; | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | #---------------------------------------------------------------------- | ||||||||||||||||||||
| 94 | # Open the connection to the remote site | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 1 | ▶ | sub open { | ||||||||||||||||||
|
Subroutine
open: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||
| 97 | 1 | my ($self, $user, $password) = @_; | |||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | # Check existence of remote directory | ||||||||||||||||||||
| 100 | 1 | ▶ | my $found = $self->{remote_directory} && -e $self->{remote_directory}; | ||||||||||||||||||
|
Condition33%1/3
$self->{'remote_directory'} && -e $self->{'remote_directory'}
MC/DC0%0/2
$self->{'remote_directory'} && -e $self->{'remote_directory'}
$self->{'remote_directory'}
-e $self->{'remote_directory'}
Truth table33%1/3
A && B
A= $self->{'remote_directory'}B= -e $self->{'remote_directory'}
| |||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 1 | ▶ | die "Could not find remote_directory: $self->{remote_directory}" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 103 | unless $found; | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 1 | return; | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 2 | 1; | |||||||||||||||||||
| 109 | __END__ | ||||||||||||||||||||