App-Presto
view release on metacpan or search on metacpan
Boolean, when enabled response body is parsed based on the
Content-Type header (defaults to "1")
* pretty_printer
Must be one of the supported modules (i.e. Data::Dumper or JSON). Use
tab completion to see currently supported values (defaults to
"JSON").
* binmode
Used to set encoding of STDIN and STDOUT handles (defaults to "utf8")
TODO: provide a means for aliasing endpoints so that configuration is
shared across multiple endpoints.
History and Scripting
Just like configuration, command history is maintained separately for
each endpoint specified on the command-line and is persisted across
http://my-server.com> GET /products 'created_on=$(PROMPT[Created on (YYYY-MM-DD):])'
# you can also specify initial values
http://my-server.com> GET /products 'status=$(PROMPT[Product status:][active])'
You may also specify a local file to use as an argument to a command.
An example:
http://my-server.com> POST /products $(FILE[my-product.xml])
The file is assumed to be in the same encoding as the binmode
configuration. If it is using a different character set, you can
specify that in a second bracketed parameter:
http://my-server.com> POST /products $(FILE[my-product.xml][latin-1])
The contents of the file will be slurped, decoded and included as an
argument to the command as if you had typed it on the command-line
directly.
TODO: Allow data structure references (from STASH or even BODY) to be
README.mkdn view on Meta::CPAN
- deserialize\_response
Boolean, when enabled response body is parsed based on the `Content-Type`
header (defaults to "1")
- pretty\_printer
Must be one of the supported modules (i.e. Data::Dumper or JSON).
Use tab completion to see currently supported values (defaults to "JSON").
- binmode
Used to set encoding of STDIN and STDOUT handles (defaults to "utf8")
**TODO:** provide a means for aliasing endpoints so that configuration
is shared across multiple endpoints.
## History and Scripting
Just like configuration, command history is maintained separately for each
endpoint specified on the command-line and is persisted across sessions
README.mkdn view on Meta::CPAN
# or use a value that was prompted for directly (without stashing it)
http://my-server.com> GET /products 'created_on=$(PROMPT[Created on (YYYY-MM-DD):])'
# you can also specify initial values
http://my-server.com> GET /products 'status=$(PROMPT[Product status:][active])'
You may also specify a local file to use as an argument to a command. An example:
http://my-server.com> POST /products $(FILE[my-product.xml])
The file is assumed to be in the same encoding as the `binmode`
configuration. If it is using a different character set, you can specify
that in a second bracketed parameter:
http://my-server.com> POST /products $(FILE[my-product.xml][latin-1])
The contents of the file will be slurped, decoded and included as an
argument to the command as if you had typed it on the command-line
directly.
**TODO:** Allow data structure references (from `STASH` or even `BODY`)
=item * deserialize_response
Boolean, when enabled response body is parsed based on the C<Content-Type>
header (defaults to "1")
=item * pretty_printer
Must be one of the supported modules (i.e. Data::Dumper or JSON).
Use tab completion to see currently supported values (defaults to "JSON").
=item * binmode
Used to set encoding of STDIN and STDOUT handles (defaults to "utf8")
=back
B<TODO:> provide a means for aliasing endpoints so that configuration
is shared across multiple endpoints.
=head2 History and Scripting
# or use a value that was prompted for directly (without stashing it)
http://my-server.com> GET /products 'created_on=$(PROMPT[Created on (YYYY-MM-DD):])'
# you can also specify initial values
http://my-server.com> GET /products 'status=$(PROMPT[Product status:][active])'
You may also specify a local file to use as an argument to a command. An example:
http://my-server.com> POST /products $(FILE[my-product.xml])
The file is assumed to be in the same encoding as the C<binmode>
configuration. If it is using a different character set, you can specify
that in a second bracketed parameter:
http://my-server.com> POST /products $(FILE[my-product.xml][latin-1])
The contents of the file will be slurped, decoded and included as an
argument to the command as if you had typed it on the command-line
directly.
B<TODO:> Allow data structure references (from C<STASH> or even C<BODY>)
lib/App/Presto.pm view on Meta::CPAN
if(my $endpoint = shift(@args)){
$self->config( $config = App::Presto::Config->new( endpoint => $endpoint ) );
} else {
die "Base endpoint (i.e. http://some-host.com) must be specified as command-line argument\n";
}
$config->init_defaults;
$self->command_factory->install_commands($self);
my $binmode = $config->get('binmode');
binmode(STDOUT,":encoding($binmode)");
binmode(STDIN,":encoding($binmode)");
my $term = $self->term;
return $term->run;
}
1;
__END__
=pod
lib/App/Presto/ArgProcessor.pm view on Meta::CPAN
if($param =~ m/^(BODY|HEADER)\b(.*)/){
$replacement = $self->_expand_response_param($1,$2);
} elsif($param =~ m/^STASH($RE{balanced}{-parens => '[]'})(\/.*)?/){
my ($key, $dpath) = ($2, $3);
$replacement = $self->stash(substr($key,1,-1));
if($dpath){
$replacement = _apply_dpath($replacement, $dpath)
}
} elsif($param =~ m/^FILE($RE{balanced}{-parens => '[]'})($RE{balanced}{-parens => '[]'})?/){
my $file = substr($1, 1, -1);
my $encoding = $2 ? substr($2, 1, -1) : $self->config->get('binmode') || 'utf8';
$replacement = read_file( $file, { binmode => ":encoding($encoding)" } );
} elsif($param =~ m/^PROMPT($RE{balanced}{-parens => '[]'})($RE{balanced}{-parens => '[]'})?/){
my($prompt,$default) = ($1, $2);
$replacement = $self->term->readline( substr( $prompt, 1, -1 ) . ' ', ($default ? substr( $default, 1, -1 ) : () ) );
}
return defined $replacement ? $replacement : $orig;
}
sub _expand_response_param {
my $self = shift;
my $section = shift;
lib/App/Presto/Command/config.pm view on Meta::CPAN
with 'App::Presto::InstallableCommand','App::Presto::CommandHasHelp','App::Presto::WithPrettyPrinter';
sub install {
my $self = shift;
my %opts = (minargs => 0, maxargs => 1);
$self->term->add_commands(
{
config => {
desc => 'get/set config values',
cmds => {
binmode => {
desc => 'control how output is encoded and input is decoded',
args => 'anything that will work in binmode(STDOUT, :encoding(<CONFIG VALUE>)) (i.e. "utf8")',
proc => $self->_mk_proc_for_config(
'binmode',
sub {
my $e = shift;
eval {
binmode( STDOUT, ":encoding($e)" );
binmode( STDIN, ":encoding($e)" );
1;
} or do {
warn $@;
};
}
),
%opts,
},
verbose => {
desc => 'dump request/response to STDOUT',
lib/App/Presto/Command/config.pm view on Meta::CPAN
print $self->pretty_print( $self->config->config );
}
},
}
);
}
sub help_categories {
return {
desc => 'Get/Set/List config values',
cmds => [sort map { "config $_" } 'pretty_printer', 'deserialize_response', 'verbose', 'binmode','--unset'],
};
}
sub _mk_proc_for_config {
my $self = shift;
my $key = shift;
my $cb = shift;
return sub {
if(@_ == 1){
$self->config->set($key, $_[0]);
lib/App/Presto/Config.pm view on Meta::CPAN
sub write_config {
my $self = shift;
my $config_file = $self->file('config.json');
open(my $fh, '>', $config_file) or die "Unable to open $config_file for writing: $!";
print $fh encode_json($self->config);
close $fh;
return;
}
my %DEFAULTS = (
binmode => 'utf8',
pretty_printer => 'JSON',
deserialize_response => 1,
);
sub init_defaults {
my $self = shift;
foreach my $k(CORE::keys %DEFAULTS){
unless($self->is_set($k)){
$self->set($k, $DEFAULTS{$k});
}
}
t/00-compile.t view on Meta::CPAN
open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!";
my @warnings;
for my $lib (@module_files)
{
# see L<perlfaq8/How can I capture STDERR from an external command?>
my $stderr = IO::Handle->new;
my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]");
binmode $stderr, ':crlf' if $^O eq 'MSWin32';
my @_warnings = <$stderr>;
waitpid($pid, 0);
is($?, 0, "$lib loaded ok");
shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
and not eval { require blib; blib->VERSION('1.01') };
if (@_warnings)
{
warn @_warnings;
t/00-compile.t view on Meta::CPAN
{ SKIP: {
open my $fh, '<', $file or warn("Unable to open $file: $!"), next;
my $line = <$fh>;
close $fh and skip("$file isn't perl", 1) unless $line =~ /^#!\s*(?:\S*perl\S*)((?:\s+-\w*)*)(?:\s*#.*)?$/;
my @flags = $1 ? split(' ', $1) : ();
my $stderr = IO::Handle->new;
my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, @flags, '-c', $file);
binmode $stderr, ':crlf' if $^O eq 'MSWin32';
my @_warnings = <$stderr>;
waitpid($pid, 0);
is($?, 0, "$file compiled ok");
shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
and not eval { require blib; blib->VERSION('1.01') };
# in older perls, -c output is simply the file portion of the path being tested
if (@_warnings = grep { !/\bsyntax OK$/ }
grep { chomp; $_ ne (File::Spec->splitpath($file))[2] } @_warnings)
( run in 0.339 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )