App-Presto

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    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
    passed to a POST or PUT command which is then serialized based on the
    content-type of the request before being sent over the wire.

 (EXPERIMENTAL) Data::DPath integration

    As an add-on to the variable interpolated described above, you can use

README.mkdn  view on Meta::CPAN

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 passed to a POST or PUT command which is then serialized based
on the content-type of the request before being sent over the wire.

## (EXPERIMENTAL) Data::DPath integration

As an add-on to the variable interpolated described above, you can

bin/presto  view on Meta::CPAN

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>)
to be passed to a POST or PUT command which is then serialized based
on the content-type of the request before being sent over the wire.

=head2 (EXPERIMENTAL) Data::DPath integration

As an add-on to the variable interpolated described above, you can

lib/App/Presto/Client.pm  view on Meta::CPAN

sub response_data {
	my $self     = shift;
	my $response = $self->response;
	if ( my $content_type = $response->header('Content-type') ) {
		foreach my $h ( $self->content_handlers ) {
			if ( $h->can_deserialize($content_type) ) {
				return $h->deserialize( $response->content );
			}
		}
	}
	return $response->decoded_content;
}

1;

__END__

=pod

=encoding UTF-8

lib/App/Presto/Command/HTTP.pm  view on Meta::CPAN

    my($request,$response) = @_;
    print "----- REQUEST -----\n";
    print $request->dump;
    print "----- RESPONSE -----\n";
    print $response->dump;
    print "----- END -----\n";
}

sub readable_content {
    my $message = shift;
    return is_human_readable($message) ? $message->decoded_content : sprintf('[ %d bytes of binary data ]', $message->content_length || length($message->decoded_content));
}

sub is_human_readable {
    my $message = shift;
    return $message->content_type =~ m{\b(?:xml|^text|application/json|application/x-www-form-urlencoded)\b} || do {
        my $content = substr($message->decoded_content, 0, 1000);
        my $non_printable =()= $content =~ m/([^[:print:]])/g;
        $content eq '' || ($non_printable / length($content)) > 0.3;
    };
}

sub help_categories {
    return {
        desc => 'Various HTTP verb commands',
        cmds => [qw(GET POST HEAD PUT DELETE)],
    };

lib/App/Presto/Command/config.pm  view on Meta::CPAN


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 {



( run in 1.960 second using v1.01-cache-2.11-cpan-26ccb49234f )