| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::Followme::UploadLocal; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 634 | use 5.008005; | 
|  | 2 |  |  |  |  | 7 |  | 
| 4 | 2 |  |  | 2 |  | 11 | use strict; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 41 |  | 
| 5 | 2 |  |  | 2 |  | 10 | use warnings; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 68 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 2 |  |  | 2 |  | 475 | use lib '../..'; | 
|  | 2 |  |  |  |  | 662 |  | 
|  | 2 |  |  |  |  | 11 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 2 |  |  | 2 |  | 263 | use base qw(App::Followme::ConfiguredObject); | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 521 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 2 |  |  | 2 |  | 1178 | use File::Copy; | 
|  | 2 |  |  |  |  | 4786 |  | 
|  | 2 |  |  |  |  | 126 |  | 
| 12 | 2 |  |  | 2 |  | 15 | use File::Path qw(remove_tree); | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 116 |  | 
| 13 | 2 |  |  | 2 |  | 14 | use File::Spec::Functions qw(abs2rel splitdir catfile); | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 1011 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | our $VERSION = "2.02"; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | #---------------------------------------------------------------------- | 
| 18 |  |  |  |  |  |  | # Read the default parameter values | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | sub parameters { | 
| 21 | 12 |  |  | 12 | 1 | 22 | my ($pkg) = @_; | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | return ( | 
| 24 | 12 |  |  |  |  | 34 | remote_directory => '', | 
| 25 |  |  |  |  |  |  | permissions => 0644, | 
| 26 |  |  |  |  |  |  | ); | 
| 27 |  |  |  |  |  |  | } | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | #---------------------------------------------------------------------- | 
| 30 |  |  |  |  |  |  | # Add a directory to the remote site | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | sub add_directory { | 
| 33 | 2 |  |  | 2 | 1 | 9 | my ($self, $dir) = @_; | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 2 |  |  |  |  | 12 | my $new_dir = catfile($self->{remote_directory}, $dir); | 
| 36 | 2 |  |  |  |  | 133 | my $status = mkdir($new_dir); | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 2 | 50 |  |  |  | 12 | if ($status) { | 
| 39 | 2 |  |  |  |  | 8 | my $permissions = $self->{permissions} | 0111; | 
| 40 | 2 |  |  |  |  | 39 | chmod($permissions, $new_dir); | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 2 |  |  |  |  | 12 | return $status; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | #---------------------------------------------------------------------- | 
| 47 |  |  |  |  |  |  | # Add a file to the remote site | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | sub add_file { | 
| 50 | 8 |  |  | 8 | 1 | 1664 | my ($self, $local_filename, $remote_filename) = @_; | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 8 |  |  |  |  | 73 | my $new_file = catfile($self->{remote_directory}, $remote_filename); | 
| 53 | 8 |  |  |  |  | 32 | my $status = copy($local_filename, $new_file); | 
| 54 |  |  |  |  |  |  |  | 
| 55 | 8 | 50 |  |  |  | 2749 | chmod($self->{permissions}, $new_file) if $status; | 
| 56 | 8 |  |  |  |  | 48 | return $status; | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | #---------------------------------------------------------------------- | 
| 60 |  |  |  |  |  |  | # Close the connection | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | sub close { | 
| 63 | 1 |  |  | 1 | 1 | 658 | my ($self) = @_; | 
| 64 | 1 |  |  |  |  | 154 | return; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | #---------------------------------------------------------------------- | 
| 68 |  |  |  |  |  |  | # Delete a directory from the remote site | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | sub delete_directory { | 
| 71 | 1 |  |  | 1 | 1 | 689 | my ($self, $dir) = @_; | 
| 72 |  |  |  |  |  |  |  | 
| 73 | 1 |  |  |  |  | 3 | my $err; | 
| 74 | 1 |  |  |  |  | 6 | my $new_dir = catfile($self->{remote_directory}, $dir); | 
| 75 | 1 |  |  |  |  | 280 | remove_tree($new_dir, {error => $err}); | 
| 76 |  |  |  |  |  |  |  | 
| 77 | 1 |  | 33 |  |  | 8 | my $status = ! ($err && @$err); | 
| 78 | 1 |  |  |  |  | 5 | return $status; | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | #---------------------------------------------------------------------- | 
| 82 |  |  |  |  |  |  | # Delete a file from the remote site | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | sub delete_file { | 
| 85 | 1 |  |  | 1 | 1 | 653 | my ($self, $filename) = @_; | 
| 86 |  |  |  |  |  |  |  | 
| 87 | 1 |  |  |  |  | 6 | my $new_file = catfile($self->{remote_directory}, $filename); | 
| 88 | 1 |  |  |  |  | 415 | my $status = unlink($new_file); | 
| 89 |  |  |  |  |  |  |  | 
| 90 | 1 |  |  |  |  | 9 | return $status; | 
| 91 |  |  |  |  |  |  | } | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | #---------------------------------------------------------------------- | 
| 94 |  |  |  |  |  |  | # Open the connection to the remote site | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | sub open { | 
| 97 | 1 |  |  | 1 | 1 | 4 | my ($self, $user, $password) = @_; | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | # Check existence of remote directory | 
| 100 | 1 |  | 33 |  |  | 24 | my $found = $self->{remote_directory} && -e $self->{remote_directory}; | 
| 101 |  |  |  |  |  |  |  | 
| 102 | 1 | 50 |  |  |  | 4 | die "Could not find remote_directory: $self->{remote_directory}" | 
| 103 |  |  |  |  |  |  | unless $found; | 
| 104 |  |  |  |  |  |  |  | 
| 105 | 1 |  |  |  |  | 2 | return; | 
| 106 |  |  |  |  |  |  | } | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | 1; | 
| 109 |  |  |  |  |  |  | __END__ | 
| 110 |  |  |  |  |  |  | =encoding utf-8 | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | =head1 NAME | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | App::Followme::UploadLocal - Upload files through file copy | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | my $uploader = App::Followme::UploadLocal->new(\%configuration); | 
| 119 |  |  |  |  |  |  | $uploader->open(); | 
| 120 |  |  |  |  |  |  | $uploader->add_directory($dir); | 
| 121 |  |  |  |  |  |  | $uploader->add_file($filename); | 
| 122 |  |  |  |  |  |  | $uploader->delete_directory($dir); | 
| 123 |  |  |  |  |  |  | $uploader->delete_file($filename); | 
| 124 |  |  |  |  |  |  | $uploader->close(); | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | L<App::Followme::UploadSite> splits off methods that do the actual uploading | 
| 129 |  |  |  |  |  |  | into a separate package, so it can support more than one method. This package | 
| 130 |  |  |  |  |  |  | uploads files to the server using a simple file copy. | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | =head1 METHODS | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | The following are the public methods of the interface. The return value | 
| 135 |  |  |  |  |  |  | indicates if the operation was successful. | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | =over 4 | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | =item $flag = $self->add_directory($dir); | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | Create a new directory | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | =item $flag = $self->add_file($filename); | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | Upload a new file. If it already exists, delete it. | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | =item $self->close(); | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | Close the connection to the remote site. | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | =item $flag = $self->delete_directory($dir); | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | Delete a directory, including any files it might hold. | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | =item $flag = $self->delete_file($filename); | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | Delete a file on the remote site. | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | =item $self->open(); | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | Open the connection to the remote site | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  | =item $self->setup(); | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | Set up computed fields in the new object | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | =back | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | =head1 CONFIGURATION | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | The following parameters are used from the configuration. | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | =over 4 | 
| 174 |  |  |  |  |  |  |  | 
| 175 |  |  |  |  |  |  | =item remote_directory | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | The top directory of the website the files are being copied to | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | =item permissions | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | The permissions to put on the remote file. | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | =back | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | =head1 LICENSE | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | Copyright (C) Bernie Simon. | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | This library is free software; you can redistribute it and/or modify | 
| 190 |  |  |  |  |  |  | it under the same terms as Perl itself. | 
| 191 |  |  |  |  |  |  |  | 
| 192 |  |  |  |  |  |  | =head1 AUTHOR | 
| 193 |  |  |  |  |  |  |  | 
| 194 |  |  |  |  |  |  | Bernie Simon E<lt>bernie.simon@gmail.comE<gt> | 
| 195 |  |  |  |  |  |  |  | 
| 196 |  |  |  |  |  |  | =cut |