| 1 | #!/usr/bin/perl -w | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Apache::Sling::Content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Getopt::Long qw(:config bundling); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Apache::Sling; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Apache::Sling::ContentUtil; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use Apache::Sling::Print; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Apache::Sling::Request; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | our @EXPORT_OK = qw(command_line); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | our $VERSION = '0.27'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | #{{{sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | my ( $class, $authn, $verbose, $log ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | ▶ | if ( !defined $authn ) { croak 'no authn provided!'; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | my $response; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | ▶ | $verbose = ( defined $verbose ? $verbose : 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | my $content = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | BaseURL => ${$authn}->{'BaseURL'}, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | Authn => $authn, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | Message => q{}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | Response => \$response, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | Verbose => $verbose, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | Log => $log | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 4 | bless $content, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | return $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | #{{{sub set_results | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | sub set_results { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_results: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | my ( $content, $message, $response ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | $content->{'Message'} = $message; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | $content->{'Response'} = $response; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | #{{{sub add | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=2 SCAR=13.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | my ( $content, $remote_dest, $properties ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | my $res = Apache::Sling::Request::request( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | \$content, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | Apache::Sling::ContentUtil::add_setup( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | $content->{'BaseURL'}, $remote_dest, $properties | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $success = Apache::Sling::ContentUtil::add_eval($res); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my $message = "Content addition to \"$remote_dest\" "; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | $message .= ( $success ? 'succeeded!' : 'failed!' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $content->set_results( "$message", $res ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | return $success; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | #{{{ sub command_line | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub command_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_line: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my ( $content, @ARGV ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $sling = Apache::Sling->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $config = $content->config( $sling, @ARGV ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | return $content->run( $sling, $config ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | #{{{sub config | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | sub config { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | my ( $content, $sling, @ARGV ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | my $content_config = $content->config_hash( $sling, @ARGV ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | GetOptions( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | $content_config, 'auth=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 'help|?', 'log|L=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 'man|M', 'pass|p=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 'threads|t=s', 'url|U=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 'user|u=s', 'verbose|v+', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 'add|a', 'additions|A=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 'copy|c', 'delete|d', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 'exists|e', 'filename|n=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 'local|l=s', 'move|m', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 'property|P=s', 'remote|r=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 'remote-source|S=s', 'replace|R', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 'view|V' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ) or $content->help(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | return $content_config; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | #{{{sub config_hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | ▶ | sub config_hash { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config_hash: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | my ( $content, $sling, @ARGV ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | my $add; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | my $additions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | my $copy; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | my $delete; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | my $exists; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | my $filename; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | my $local; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | my $move; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | my @property; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | my $remote; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | my $remote_source; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | my $replace; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | my $view; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | my %content_config = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 'auth' => \$sling->{'Auth'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 'help' => \$sling->{'Help'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 'log' => \$sling->{'Log'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 'man' => \$sling->{'Man'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 'pass' => \$sling->{'Pass'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 'threads' => \$sling->{'Threads'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 'url' => \$sling->{'URL'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 'user' => \$sling->{'User'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | 'verbose' => \$sling->{'Verbose'}, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 'add' => \$add, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 'additions' => \$additions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 'copy' => \$copy, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 'delete' => \$delete, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 'exists' => \$exists, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 'filename' => \$filename, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 'local' => \$local, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 'move' => \$move, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 'property' => \@property, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 'remote' => \$remote, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 'remote-source' => \$remote_source, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 'replace' => \$replace, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 'view' => \$view | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | return \%content_config; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | #{{{sub copy | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | ▶ | sub copy { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
copy: called CC=2 SCAR=13.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | my ( $content, $remote_src, $remote_dest, $replace ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | my $res = Apache::Sling::Request::request( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | \$content, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | Apache::Sling::ContentUtil::copy_setup( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | $content->{'BaseURL'}, $remote_src, $remote_dest, $replace | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my $success = Apache::Sling::ContentUtil::copy_eval($res); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my $message = "Content copy from \"$remote_src\" to \"$remote_dest\" "; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | $message .= ( $success ? 'completed!' : 'did not complete successfully!' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $content->set_results( "$message", $res ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | return $success; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | #{{{sub check_exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | ▶ | sub check_exists { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_exists: called CC=2 SCAR=13.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | my ( $content, $remote_dest ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | my $res = Apache::Sling::Request::request( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | \$content, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | Apache::Sling::ContentUtil::exists_setup( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | $content->{'BaseURL'}, $remote_dest | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my $success = Apache::Sling::ContentUtil::exists_eval($res); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my $message = "Content \"$remote_dest\" "; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | $message .= ( $success ? 'exists!' : 'does not exist!' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | $content->set_results( "$message", $res ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | return $success; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | #{{{sub del | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | ▶ | sub del { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
del: called CC=2 SCAR=13.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | my ( $content, $remote_dest ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | my $res = Apache::Sling::Request::request( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | \$content, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | Apache::Sling::ContentUtil::delete_setup( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | $content->{'BaseURL'}, $remote_dest | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | my $success = Apache::Sling::ContentUtil::delete_eval($res); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my $message = "Content \"$remote_dest\" "; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | $message .= ( $success ? 'deleted!' : 'was not deleted!' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $content->set_results( "$message", $res ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | return $success; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | #{{{ sub help | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | ▶ | sub help { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
help: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | print <<"EOF"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | Usage: perl $0 [-OPTIONS [-MORE_OPTIONS]] [--] [PROGRAM_ARG1 ...] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | The following options are accepted: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | --additions or -A (file) - File containing list of content to be uploaded. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | --add or -a - Add content. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | --auth (type) - Specify auth type. If ommitted, default is used. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | --copy or -c - Copy content. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | --delete or -d - Delete content. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | --filename or -n (filename) - Specify file name to use for content upload. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | --help or -? - view the script synopsis and options. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | --local or -l (localPath) - Local path to content to upload. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | --log or -L (log) - Log script output to specified log file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | --man or -M - view the full script documentation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | --move or -m - Move content. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | --pass or -p (password) - Password of user performing content manipulations. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | --property or -P (property) - Specify property to set on node. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | --remote or -r (remoteNode) - specify remote destination under JCR root to act on. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | --remote-source or -S (remoteSrc) - specify remote source node under JCR root to act on. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | --replace or -R - when copying or moving, overwrite remote destination if it exists. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | --threads or -t (threads) - Used with -A, defines number of parallel | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | processes to have running through file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | --url or -U (URL) - URL for system being tested against. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | --user or -u (username) - Name of user to perform content manipulations as. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | --verbose or -v or -vv or -vvv - Increase verbosity of output. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | --view or -V (actOnGroup) - view details for specified group in json format. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | Options may be merged together. -- stops processing of options. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | Space is not required between options and their arguments. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | For full details run: perl $0 --man | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | #{{{ sub man | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | sub man { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
man: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my ($content) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | print <<'EOF'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | content perl script. Provides a means of uploading content into sling from the | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | command line. The script also acts as a reference implementation for the | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | Content perl library. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $content->help(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | print <<"EOF"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | Example Usage | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | * Authenticate and add a node at /test: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | perl $0 -U http://localhost:8080 -a -r /test -u admin -p admin | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | * Authenticate and add a node at /test with property p1 set to v1: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | perl $0 -U http://localhost:8080 -a -r /test -P p1=v1 -u admin -p admin | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | * Authenticate and add a node at /test with property p1 set to v1, and p2 set to v2: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | perl $0 -U http://localhost:8080 -a -r /test -P p1=v1 -P p2=v2 -u admin -p admin | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | * View json for node at /test: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | perl $0 -U http://localhost:8080 -V -r /test | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | * Check whether node at /test exists: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | perl $0 -U http://localhost:8080 -V -r /test | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | * Authenticate and copy content at /test to /test2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | perl $0 -U http://localhost:8080 -c -S /test -r /test2 -u admin -p admin | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | * Authenticate and move content at /test to /test2, replacing test2 if it already exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | perl $0 -U http://localhost:8080 -m -S /test -r /test2 -R -u admin -p admin | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | * Authenticate and delete content at /test | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | perl $0 -U http://localhost:8080 -d -r /test -u admin -p admin | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | #{{{sub move | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | ▶ | sub move { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
move: called CC=2 SCAR=13.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 1 | my ( $content, $remote_src, $remote_dest, $replace ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | my $res = Apache::Sling::Request::request( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | \$content, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | Apache::Sling::ContentUtil::move_setup( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 1 | $content->{'BaseURL'}, $remote_src, $remote_dest, $replace | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | my $success = Apache::Sling::ContentUtil::move_eval($res); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | my $message = "Content move from \"$remote_src\" to \"$remote_dest\" "; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | $message .= ( $success ? 'completed!' : 'did not complete successfully!' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | $content->set_results( "$message", $res ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | return $success; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | #{{{sub run | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 2 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=18 SCAR=45.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 2 | my ( $content, $sling, $config ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 2 | ▶ | if ( !defined $config ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | croak 'No content config supplied!'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 1 | $sling->check_forks; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | ${ $config->{'remote'} } = | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | Apache::Sling::URL::strip_leading_slash( ${ $config->{'remote'} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | ${ $config->{'remote-source'} } = Apache::Sling::URL::strip_leading_slash( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 1 | ${ $config->{'remote-source'} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | my $authn = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | defined $sling->{'Authn'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 1 | ▶ | ? ${ $sling->{'Authn'} } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | : Apache::Sling::Authn->new( \$sling ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 1 | my $success = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | if ( $sling->{'Help'} ) { $content->help(); } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | elsif ( $sling->{'Man'} ) { $content->man(); } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 1 | elsif ( defined ${ $config->{'additions'} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | my $message = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | "Adding content from file \"" . ${ $config->{'additions'} } . "\":\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | Apache::Sling::Print::print_with_lock( "$message", $sling->{'Log'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | my @childs = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | for my $i ( 0 .. $sling->{'Threads'} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | my $pid = fork; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | if ($pid) { push @childs, $pid; } # parent | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | elsif ( $pid == 0 ) { # child | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | # Create a new separate user agent per fork in order to | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # ensure cookie stores are separate, then log the user in: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | $authn->{'LWP'} = $authn->user_agent( $sling->{'Referer'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | $authn->login_user(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | my $content = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | Apache::Sling::Content->new( \$authn, $sling->{'Verbose'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | $sling->{'Log'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | $content->upload_from_file( ${ $config->{'additions'} }, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $i, $sling->{'Threads'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | croak "Could not fork $i!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | foreach (@childs) { waitpid $_, 0; } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 1 | $authn->login_user(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 1 | ▶ | if ( defined ${ $config->{'local'} } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
Condition33%1/3
defined ${$$config{"local"};} and defined ${$$config{"remote"};}
MC/DC0%0/2
defined ${$$config{"local"};} and defined ${$$config{"remote"};}
defined ${$$config{"local"};}
defined ${$$config{"remote"};}
Truth table33%1/3
A and B
A= defined ${$$config{"local"};}B= defined ${$$config{"remote"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | && defined ${ $config->{'remote'} } ) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | $content = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | Apache::Sling::Content->new( \$authn, $sling->{'Verbose'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | $sling->{'Log'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | $success = $content->upload_file( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ${ $config->{'local'} }, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ${ $config->{'remote'} }, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ${ $config->{'filename'} } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 1 | elsif ( defined ${ $config->{'exists'} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | $content = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | Apache::Sling::Content->new( \$authn, $sling->{'Verbose'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | $sling->{'Log'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | $success = $content->check_exists( ${ $config->{'remote'} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 1 | elsif ( defined ${ $config->{'add'} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | $content = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | Apache::Sling::Content->new( \$authn, $sling->{'Verbose'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | $sling->{'Log'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | $success = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | $content->add( ${ $config->{'remote'} }, $config->{'property'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 1 | elsif ( defined ${ $config->{'copy'} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | $content = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | Apache::Sling::Content->new( \$authn, $sling->{'Verbose'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | $sling->{'Log'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | $success = $content->copy( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ${ $config->{'remote-source'} }, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ${ $config->{'remote'} }, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | ${ $config->{'replace'} } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 1 | elsif ( defined ${ $config->{'delete'} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | $content = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | Apache::Sling::Content->new( \$authn, $sling->{'Verbose'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | $sling->{'Log'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | $success = $content->del( ${ $config->{'remote'} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 1 | elsif ( defined ${ $config->{'move'} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | $content = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | Apache::Sling::Content->new( \$authn, $sling->{'Verbose'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | $sling->{'Log'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | $success = $content->move( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ${ $config->{'remote-source'} }, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ${ $config->{'remote'} }, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | ${ $config->{'replace'} } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 1 | elsif ( defined ${ $config->{'view'} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | $content = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | Apache::Sling::Content->new( \$authn, $sling->{'Verbose'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | $sling->{'Log'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | $success = $content->view( ${ $config->{'remote'} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 1 | $content->help(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | Apache::Sling::Print::print_result($content); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | return $success; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | #{{{sub upload_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 1 | ▶ | sub upload_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upload_file: called CC=4 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 1 | my ( $content, $local_path, $remote_path, $filename ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 1 | ▶ | $filename = defined $filename ? $filename : q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | my $res = Apache::Sling::Request::request( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | \$content, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | Apache::Sling::ContentUtil::upload_file_setup( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 1 | $content->{'BaseURL'}, $local_path, $remote_path, $filename | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | my $success = Apache::Sling::ContentUtil::upload_file_eval($res); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | my $basename = $local_path; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | $basename =~ s/^(.*\/)([^\/]*)$/$2/msx; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | my $remote_dest = | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | $remote_path . ( $filename ne q{} ? "/$filename" : "/$basename" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | my $message = "Content: \"$local_path\" upload to \"$remote_dest\" "; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | $message .= ( $success ? 'succeeded!' : 'failed!' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | $content->set_results( "$message", $res ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | return $success; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | #{{{sub upload_from_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 3 | ▶ | sub upload_from_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upload_from_file: called CC=9 SCAR=26.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 3 | my ( $content, $file, $fork_id, $number_of_forks ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 3 | ▶ | $fork_id = defined $fork_id ? $fork_id : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 3 | ▶ | $number_of_forks = defined $number_of_forks ? $number_of_forks : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 3 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 3 | ▶ | if ( !defined $file ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 1 | croak 'File to upload from not defined'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 2 | ▶ | if ( open my ($input), '<', $file ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 1 | ▶ | while (<$input>) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 1 | ▶ | if ( $fork_id == ( $count++ % $number_of_forks ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 1 | chomp; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 1 | ▶ | $_ =~ /^(\S.*?),(\S.*?)$/msx | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | or croak 'Problem parsing content to add'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | my $local_path = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | my $remote_path = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | $content->upload_file( $local_path, $remote_path, q{} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | Apache::Sling::Print::print_result($content); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | close $input or croak 'Problem closing input!'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 1 | croak "Problem opening file: '$file'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | #{{{sub view | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 1 | ▶ | sub view { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
view: called CC=2 SCAR=13.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | my ( $content, $remote_dest ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | my $res = Apache::Sling::Request::request( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | \$content, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | Apache::Sling::ContentUtil::exists_setup( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 1 | $content->{'BaseURL'}, $remote_dest | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | my $success = Apache::Sling::ContentUtil::exists_eval($res); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | my $message = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | $success | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | ? ${$res}->content | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | : "Problem viewing content: \"$remote_dest\"" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | $content->set_results( "$message", $res ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | return $success; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | #{{{sub view_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 1 | ▶ | sub view_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
view_file: called CC=3 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 1 | my ( $content, $remote_dest ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 1 | ▶ | if ( !defined $remote_dest ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 1 | croak 'No file to view specified!'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | my $res = Apache::Sling::Request::request( \$content, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | "get $content->{ 'BaseURL' }/$remote_dest" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | my $success = Apache::Sling::ContentUtil::exists_eval($res); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | my $message = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | $success | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | ? ${$res}->content | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | : "Problem viewing content: \"$remote_dest\"" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | $content->set_results( "$message", $res ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | return $success; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | #{{{sub view_full_json | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | ▶ | sub view_full_json { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
view_full_json: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | my ( $content, $remote_dest ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | ▶ | if ( !defined $remote_dest ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | croak 'No file to view specified!'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | my $res = Apache::Sling::Request::request( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | \$content, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | Apache::Sling::ContentUtil::full_json_setup( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | $content->{'BaseURL'}, $remote_dest | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | my $success = Apache::Sling::ContentUtil::full_json_eval($res); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | my $message = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | $success | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | ? ${$res}->content | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | : "Problem viewing json: \"$remote_dest\"" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | $content->set_results( "$message", $res ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | return $success; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||