data passed is
assumed to be utf8 encoded meaning that it will need to be decoded
before calling json->encode.
Additionally, the true value can be a hashref of methods that need
this treatment. Thi
ou know some of your methods have
utf8 data, while others do not.
(Note: Conversely when the non-json transport is finalized, it will
need to call decode_utf8 to make sure data is ready for the
trans
This is advisory.
=item transport
Defaults to ''. From Net::Respite::Server it defaults to C<json> (Respite),
C<form> (Post variables), and C<form-doc> (autodoc interface). From
Net::Respite::Co
data passed is
assumed to be utf8 encoded meaning that it will need to be decoded
before calling json->encode.
Additionally, the true value can be a hashref of methods that need
this treatment. Thi
hen the non-json transport is finalized, it will
need to call decode_utf8 to make sure data is ready for the
transport.)
=back
=head1 PROTOCOL
The Net::Respite::Client service is a JSON over HTTPS
be a POST request with a content type of x-application/json.
The request should be hashref (map or associative array) of properly encoded JSON.
Several meta parameters may passed as part of the req
t->json->decode(shift) }
=cut
use strict;
use warnings;
sub new {
my ($class, $args) = @_;
return bless {%{$args || {}}}, $class;
}
our $js;
sub json { $js ||= eval { require JSON; JSON->n
Could not load JSON: $@" }
our $jp;
sub jsop { $jp ||= eval { require JSON; JSON->new->utf8->allow_unknown->allow_nonref->convert_blessed->canonical->pretty } || die "Could not load JSON: $@" }
our $
*Throw_::TO_JSON = sub { +{%{$_[0]}} };
*Throw_::_str = sub { my ($s) = @_; my ($e,$p) = delete(@$s{qw(error _pretty)}); $e||="throw"; $e .= ': '.($p||$Throw::pretty?jsop():json())->encode($
_decode_utf8_recurse($args) if $enc;
$req = eval { $self->json->encode($args) } || throw "Trouble encoding $name service json", {msg => $@}, 1;
my $sign = defined($pass) ? do { my $t
0\r\n${cookie}${sign}Host: $host\r\nContent-length: ".length($req)."\r\nContent-type: application/json\r\n\r\n$req";
warn "DEBUG_Respite: Connected to http".($no_ssl?'':'s')."://$host:$port/\n
package Net::Respite::AutoDoc;
use strict;
use warnings;
use CGI::Ex::App qw(:App);
use base qw(CGI::Ex::App);
use Throw qw(throw);
use Time::HiRes ();
use JSON ();
use Scalar::Util ();
1;
ently handle args from json, form, or commandline
_encode_utf8_recurse($args) if $trp eq 'json';
} else {
_decode_utf8_recurse($args) if $trp && $trp ne 'json';
}
my $resp
Net::Server revision', {v => $Net::Server::VERSION} if $Net::Server::VERSION < 2.007;
$self->json; # vivify before fork
my $server = $class->SUPER::new(%$self, %{ $self->server_args });
@
>subprocess_env(); 1 }) {
$self->cgihandler();
} else {
warn my $err = $self->json->encode({error => "$@", type => 'mod_perl_header'});
$self->send_response($err);
}
};
my $req;
if ($ENV{'CONTENT_TYPE'} && $ENV{'CONTENT_TYPE'} =~ /\bjson\b/) {
throw 'JSON data may not be submitted via GET' if !$ENV{'REQUEST_METHOD'} || $ENV{'REQUEST_MET
;
} elsif ($ENV{'JSON'} || ! eval { require Text::PrettyTable }) {
eval { require JSON } || throw "Could not load JSON for output", {msg => $@};
my $json = JSON->new->utf8->allow_n
etty->canonical;
print "meta = ".$json->encode($meta) if $ENV{'SHOW_META'};
print "args = ".$json->encode($args);
print "data = ".$json->encode($data);
} elsif ($ENV{'PERL'
nt $p->tablify($data);
}
}
}
sub _false { require JSON; JSON::false() }
sub _null { undef }
sub _true { require JSON; JSON::true() }
sub _pod {
my ($self, $obj, $args) = @_;
my