| 1 | #!/usr/bin/perl -w | ||||||||||
| 2 | |||||||||||
| 3 | package Apache::Sling::ContentUtil; | ||||||||||
| 4 | |||||||||||
| 5 | 5 | ▶ | use 5.008001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 5 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 5 | ▶ | use Apache::Sling::URL; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 5 | require Exporter; | |||||||||
| 12 | |||||||||||
| 13 | 5 | ▶ | use base qw(Exporter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 5 | our @EXPORT_OK = (); | |||||||||
| 16 | |||||||||||
| 17 | 5 | our $VERSION = '0.27'; | |||||||||
| 18 | |||||||||||
| 19 | #{{{sub add_setup | ||||||||||
| 20 | |||||||||||
| 21 | 5 | ▶ | sub add_setup { | ||||||||
|
Subroutine
add_setup: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 22 | 5 | my ( $base_url, $remote_dest, $properties ) = @_; | |||||||||
| 23 | 5 | ▶ | if ( !defined $base_url ) { croak 'No base URL provided!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 4 | ▶ | if ( !defined $remote_dest ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 2 | croak 'No position or ID to perform action for specified!'; | |||||||||
| 26 | } | ||||||||||
| 27 | 2 | my $property_post_vars = | |||||||||
| 28 | Apache::Sling::URL::properties_array_to_string($properties); | ||||||||||
| 29 | 2 | my $post_variables = "\$post_variables = [$property_post_vars]"; | |||||||||
| 30 | 2 | return "post $base_url/$remote_dest $post_variables"; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | #}}} | ||||||||||
| 34 | |||||||||||
| 35 | #{{{sub add_eval | ||||||||||
| 36 | |||||||||||
| 37 | 1 | ▶ | sub add_eval { | ||||||||
|
Subroutine
add_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 38 | 1 | my ($res) = @_; | |||||||||
| 39 | 1 | return ( ${$res}->code =~ /^20(0|1)$/msx ); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | #}}} | ||||||||||
| 43 | |||||||||||
| 44 | #{{{sub copy_setup | ||||||||||
| 45 | |||||||||||
| 46 | 6 | ▶ | sub copy_setup { | ||||||||
|
Subroutine
copy_setup: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 47 | 6 | my ( $base_url, $remote_src, $remote_dest, $replace ) = @_; | |||||||||
| 48 | 6 | ▶ | if ( !defined $base_url ) { croak 'No base url defined!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 5 | ▶ | if ( !defined $remote_src ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 2 | croak 'No content source to copy from defined!'; | |||||||||
| 51 | } | ||||||||||
| 52 | 3 | ▶ | if ( !defined $remote_dest ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 1 | croak 'No content destination to copy to defined!'; | |||||||||
| 54 | } | ||||||||||
| 55 | 2 | my $post_variables = | |||||||||
| 56 | "\$post_variables = [':dest','$remote_dest',':operation','copy'"; | ||||||||||
| 57 | 2 | ▶ | $post_variables .= ( defined $replace ? q{,':replace','true'} : q{} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 2 | $post_variables .= ']'; | |||||||||
| 59 | 2 | return "post $base_url/$remote_src $post_variables"; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | #}}} | ||||||||||
| 63 | |||||||||||
| 64 | #{{{sub copy_eval | ||||||||||
| 65 | |||||||||||
| 66 | 1 | ▶ | sub copy_eval { | ||||||||
|
Subroutine
copy_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 67 | 1 | my ($res) = @_; | |||||||||
| 68 | 1 | return ( ${$res}->code =~ /^20(0|1)$/msx ); | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | #}}} | ||||||||||
| 72 | |||||||||||
| 73 | #{{{sub delete_setup | ||||||||||
| 74 | |||||||||||
| 75 | 4 | ▶ | sub delete_setup { | ||||||||
|
Subroutine
delete_setup: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 76 | 4 | my ( $base_url, $remote_dest ) = @_; | |||||||||
| 77 | 4 | ▶ | if ( !defined $base_url ) { croak 'No base url defined!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 3 | ▶ | if ( !defined $remote_dest ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 2 | croak 'No content destination to delete defined!'; | |||||||||
| 80 | } | ||||||||||
| 81 | 1 | my $post_variables = q{$post_variables = [':operation','delete']}; | |||||||||
| 82 | 1 | return "post $base_url/$remote_dest $post_variables"; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | #}}} | ||||||||||
| 86 | |||||||||||
| 87 | #{{{sub delete_eval | ||||||||||
| 88 | |||||||||||
| 89 | 1 | ▶ | sub delete_eval { | ||||||||
|
Subroutine
delete_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 90 | 1 | my ($res) = @_; | |||||||||
| 91 | 1 | return ( ${$res}->code eq '200' ); | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | #}}} | ||||||||||
| 95 | |||||||||||
| 96 | #{{{sub exists_setup | ||||||||||
| 97 | |||||||||||
| 98 | 5 | ▶ | sub exists_setup { | ||||||||
|
Subroutine
exists_setup: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 99 | 5 | my ( $base_url, $remote_dest ) = @_; | |||||||||
| 100 | 5 | ▶ | if ( !defined $base_url ) { croak 'No base url defined!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | 4 | ▶ | if ( !defined $remote_dest ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 102 | 3 | croak 'No position or ID to perform exists for specified!'; | |||||||||
| 103 | } | ||||||||||
| 104 | 1 | return "get $base_url/$remote_dest.json"; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | #}}} | ||||||||||
| 108 | |||||||||||
| 109 | #{{{sub exists_eval | ||||||||||
| 110 | |||||||||||
| 111 | 1 | ▶ | sub exists_eval { | ||||||||
|
Subroutine
exists_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 112 | 1 | my ($res) = @_; | |||||||||
| 113 | 1 | return ( ${$res}->code eq '200' ); | |||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | #}}} | ||||||||||
| 117 | |||||||||||
| 118 | #{{{sub full_json_setup | ||||||||||
| 119 | |||||||||||
| 120 | 3 | ▶ | sub full_json_setup { | ||||||||
|
Subroutine
full_json_setup: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 121 | 3 | my ( $base_url, $remote_dest ) = @_; | |||||||||
| 122 | 3 | ▶ | if ( !defined $base_url ) { croak 'No base url defined!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | 2 | ▶ | if ( !defined $remote_dest ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 124 | 1 | croak 'No position or ID to retrieve full json for specified!'; | |||||||||
| 125 | } | ||||||||||
| 126 | 1 | return "get $base_url/$remote_dest.infinity.json"; | |||||||||
| 127 | } | ||||||||||
| 128 | |||||||||||
| 129 | #}}} | ||||||||||
| 130 | |||||||||||
| 131 | #{{{sub full_json_eval | ||||||||||
| 132 | |||||||||||
| 133 | 1 | ▶ | sub full_json_eval { | ||||||||
|
Subroutine
full_json_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 134 | 1 | my ($res) = @_; | |||||||||
| 135 | 1 | return ( ${$res}->code eq '200' ); | |||||||||
| 136 | } | ||||||||||
| 137 | |||||||||||
| 138 | #}}} | ||||||||||
| 139 | |||||||||||
| 140 | #{{{sub move_setup | ||||||||||
| 141 | |||||||||||
| 142 | 6 | ▶ | sub move_setup { | ||||||||
|
Subroutine
move_setup: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 143 | 6 | my ( $base_url, $remote_src, $remote_dest, $replace ) = @_; | |||||||||
| 144 | 6 | ▶ | if ( !defined $base_url ) { croak 'No base url defined!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 145 | 5 | ▶ | if ( !defined $remote_src ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 146 | 2 | croak 'No content source to move from defined!'; | |||||||||
| 147 | } | ||||||||||
| 148 | 3 | ▶ | if ( !defined $remote_dest ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 149 | 1 | croak 'No content destination to move to defined!'; | |||||||||
| 150 | } | ||||||||||
| 151 | 2 | my $post_variables = | |||||||||
| 152 | "\$post_variables = [':dest','$remote_dest',':operation','move'"; | ||||||||||
| 153 | 2 | ▶ | $post_variables .= ( defined $replace ? q{,':replace','true'} : q{} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 154 | 2 | $post_variables .= ']'; | |||||||||
| 155 | 2 | return "post $base_url/$remote_src $post_variables"; | |||||||||
| 156 | } | ||||||||||
| 157 | |||||||||||
| 158 | #}}} | ||||||||||
| 159 | |||||||||||
| 160 | #{{{sub move_eval | ||||||||||
| 161 | |||||||||||
| 162 | 1 | ▶ | sub move_eval { | ||||||||
|
Subroutine
move_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 163 | 1 | my ($res) = @_; | |||||||||
| 164 | 1 | return ( ${$res}->code =~ /^20(0|1)$/msx ); | |||||||||
| 165 | } | ||||||||||
| 166 | |||||||||||
| 167 | #}}} | ||||||||||
| 168 | |||||||||||
| 169 | #{{{sub upload_file_setup | ||||||||||
| 170 | |||||||||||
| 171 | 6 | ▶ | sub upload_file_setup { | ||||||||
|
Subroutine
upload_file_setup: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 172 | 6 | my ( $base_url, $local_path, $remote_dest, $filename ) = @_; | |||||||||
| 173 | 6 | ▶ | if ( !defined $base_url ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 174 | 1 | croak 'No base URL provided to upload against!'; | |||||||||
| 175 | } | ||||||||||
| 176 | 5 | ▶ | if ( !defined $local_path ) { croak 'No local file to upload defined!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 177 | 3 | ▶ | if ( !defined $remote_dest ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 178 | 1 | croak "No remote path to upload to defined for file $local_path!"; | |||||||||
| 179 | } | ||||||||||
| 180 | 2 | ▶ | if ( $filename eq q{} ) { $filename = './*'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 181 | 2 | my $post_variables = '$post_variables = []'; | |||||||||
| 182 | return | ||||||||||
| 183 | 2 | "fileupload $base_url/$remote_dest $filename $local_path $post_variables"; | |||||||||
| 184 | } | ||||||||||
| 185 | |||||||||||
| 186 | #}}} | ||||||||||
| 187 | |||||||||||
| 188 | #{{{sub upload_file_eval | ||||||||||
| 189 | |||||||||||
| 190 | 1 | ▶ | sub upload_file_eval { | ||||||||
|
Subroutine
upload_file_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 191 | 1 | my ($res) = @_; | |||||||||
| 192 | 1 | return ( ${$res}->code =~ /^20(0|1)$/msx ); | |||||||||
| 193 | } | ||||||||||
| 194 | |||||||||||
| 195 | #}}} | ||||||||||
| 196 | |||||||||||
| 197 | 5 | 1; | |||||||||
| 198 | |||||||||||
| 199 | __END__ | ||||||||||