Apache-Sling
view release on metacpan or search on metacpan
lib/Apache/Sling/JsonQueryServlet.pm view on Meta::CPAN
#}}}
#{{{sub config
sub config {
my ( $json_query_servlet, $sling, @ARGV ) = @_;
my $json_query_servlet_config = $json_query_servlet->config_hash( $sling, @ARGV );
GetOptions(
$json_query_servlet_config, 'auth=s',
'help|?', 'log|L=s',
'man|M', 'pass|p=s',
'threads|t=s', 'url|U=s',
'user|u=s', 'verbose|v+',
'all_nodes|a'
) or $json_query_servlet->help();
return $json_query_servlet_config;
}
#}}}
#{{{sub config_hash
sub config_hash {
my ( $json_query_servlet, $sling, @ARGV ) = @_;
my $all_nodes;
my %json_query_servlet_config = (
'auth' => \$sling->{'Auth'},
'help' => \$sling->{'Help'},
'log' => \$sling->{'Log'},
'man' => \$sling->{'Man'},
'pass' => \$sling->{'Pass'},
'threads' => \$sling->{'Threads'},
'url' => \$sling->{'URL'},
'user' => \$sling->{'User'},
'verbose' => \$sling->{'Verbose'},
'all_nodes' => \$all_nodes
);
return \%json_query_servlet_config;
}
#}}}
#{{{ sub help
sub help {
print <<"EOF";
Usage: perl $0 [-OPTIONS [-MORE_OPTIONS]] [--] [PROGRAM_ARG1 ...]
The following options are accepted:
--all_nodes or -a - Return a JSON representation of all nodes in the system.
--auth (type) - Specify auth type. If ommitted, default is used.
--help or -? - view the script synopsis and options.
--log or -L (log) - Log script output to specified log file.
--man or -M - view the full script documentation.
--pass or -p (password) - Password of user performing json queries.
--threads or -t (threads) - Used with -A, defines number of parallel
processes to have running through file.
--url or -U (URL) - URL for system being tested against.
--user or -u (username) - Name of user to perform queries as.
--verbose or -v or -vv or -vvv - Increase verbosity of output.
Options may be merged together. -- stops processing of options.
Space is not required between options and their arguments.
For full details run: perl $0 --man
EOF
return 1;
}
#}}}
#{{{ sub man
sub man {
my ($json_query_servlet) = @_;
print <<'EOF';
json_query_servlet perl script. Provides a means of querying content in sling
from the command line. The script also acts as a reference implementation for
the JSON Query Servlet perl library.
EOF
$json_query_servlet->help();
print <<"EOF";
Example Usage
* Query all nodes in the system:
perl $0 -U http://localhost:8080 -a -u admin -p admin
EOF
return 1;
}
#}}}
#{{{sub run
sub run {
my ( $json_query_servlet, $sling, $config ) = @_;
if ( !defined $config ) {
croak 'No json query servlet config supplied!';
}
$sling->check_forks;
${ $config->{'remote'} } =
Apache::Sling::URL::strip_leading_slash( ${ $config->{'remote'} } );
${ $config->{'remote-source'} } = Apache::Sling::URL::strip_leading_slash(
${ $config->{'remote-source'} } );
my $authn = new Apache::Sling::Authn( \$sling );
$authn->login_user();
my $success = 1;
if ( $sling->{'Help'} ) { $json_query_servlet->help(); }
elsif ( $sling->{'Man'} ) { $json_query_servlet->man(); }
( run in 0.380 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )