use Try::Tiny;
use Scalar::Util qw[ blessed ];
use File::ShareDir;
use File::Spec::Unix ();
use JSON::XS ();
use Plack::App::File;
use Plack::Debugger;
our $VERSION = '0.03';
our $AUTHO
debugger';
# Be *extremely* lax about our JSON, this
# might be overkill for simple cases, but
# for non-simple cases, it just makes sense.
our $JSON = JSON::XS
->new
c_app'} = Plack::App::File->new( root => $args{'static_asset_dir'} )->to_app;
$args{'_JSON'} = $JSON;
$class->SUPER::new( %args );
}
# accessors ...
sub debugger { (shift)->{'
k web applications
=head1 VERSION
version 0.03
=head1 SYNOPSIS
use Plack::Builder;
use JSON;
use Plack::Debugger;
use Plack::Debugger::Storage;
use Plack::App::Debugger;
us
panel',
serializer => sub { encode_json( shift ) },
deserializer => sub { decode_json( shift ) },
filename_fmt => "%s.json",
),
panels => [
Plack:
he necessary javascript and CSS for the debugging
UI. The second is to provide a small REST style JSON web-service that
serves up the debugging data.
=head2 C<Plack.Debugger>
This is the javascript
my $app_name = $self->app_name;
my $is_text = qr/\b(?:text|xml|javascript|json)\b/;
state $cache = {};
if ($cache->{$app_name}{$path_info}) {
L<PSGI|McBain::WithPSGI> and L<Gearman::XS|McBain::WithGearmanXS> runners,
however, are both JSON-in JSON-out interfaces.
A C<McBain> API is built of one or more B<topics>, in a hierarchical structu
in::WithPSGI> - Turn an API into a Plack based, JSON-to-JSON
RESTful web application.
=item * L<McBain::WithGearmanXS> - Turn an API into a JSON-to-JSON
Gearman worker.
=item * L<McBain::WithWebSock
t> - Turn an API into a WebSocket server.
=item * L<McBain::WithZeroMQ> - Turn an API into a JSON-to-JSON ZeroMQ REP worker.
=back
The latter four completely change the way your API is used, and ye
and pass them
# through
return $resp;
}
sub handle_json_content_type {
my ($self, $env, $resp) = @_;
# application/json responses really
# can't get injected into so we
#
);
}
elsif ( $content_type =~ m!^(?:application/json)! ) {
return $self->handle_json_content_type( $env, $resp );
}
# now be less spec
ess the stream and if a closing C<<body>> tag is found, inject
accordingly.
=item C<application/json>
While we have a specific handler for this content-type, we do not do
anything but just let it
;
my $url = URI->new(BASEHOTELURL);
$url->query_form(applicationId=> $context->appid,format=>'json',largeClassCode => $arg->{largeClassCode},middleClassCode=>$arg->{middleClassCode},smallClassCode
$cgi->set_header('myheader', 'whatever');
# change content type
$cgi->set_content_type('text/json');
# output HTTP headers, including added cookies, the CSRF cookie,
# and the new header
prin
GgpkZ4; path=/
# Date: Sun, 29 Jul 2012 04:08:06 GMT
# Myheader: whatever
# Content-Type: text/json; charset=ISO-8859-1
=head1 INSTALLATION
CGI::Plus can be installed with the usual routine:
pe
tfile';
use TntCompat::Cat::SnapMsgpack;
use TntCompat::Cat::Snap;
use TntCompat::Cat::Xlog;
use JSON::XS;
use File::Basename 'basename';
use feature 'state';
sub strhex($) {
my ($str) = @_;
$res[ $fno ];
}
} elsif ('JSON' eq uc $ftype) {
# TODO: decode str
$res[ $fno ] = JSON::XS->new->decode($res[ $fno ] );
} elsi
string $_->[2];
}
} elsif ('JSON' eq uc $type) {
# TODO: decode str
$_->[2] = JSON::XS->new->decode($_->[2] );
} else {
Send Requests to a JSON-RPC Service.
# We completely ride on the wonderful LWP Module.
{
package JRPC::Client;
#
use LWP;
use LWP::UserAgent;
use base ('LWP::UserAgent');
use JSON::XS;
use Data::Dump
er;
#our $mime;
#BEGIN {
# De-facto JSON-RPC Mime type
our $mime = 'application/json';
#};
=head1 NAME
JRPC::Client - JSON-RPC 2.0 Client
=head1 SYNOPSIS
use JRPC::Client;
my $client = JRP
so'}\n");
=head1 DESCRIPTION
JRPC::Client is a Perl LWP based JSON-RPC 2.0 Client hoping to minimize tedious boilerplate code for JSON-RPC
interaction, yet enabling advanced use cases by the power o
);
# qw(OK)
use Apache2::Const -compile => qw(:common); # 'OK', 'DECLINED'
use APR::Table ();
use JSON::XS;
use JRPC; # Import ... ?
*jdie = JRPC::createfault;
#use Storable (); # Would import store -
ache2::RequestUtil;
=head1 NAME
JRPC::Apache2 - JSON-RPC Services in Apache2 / mod_perl runtime
=head1 DESCRIPTION
This package is a mod_perl JSON-RPC handler / dispatcher. It only contains the co
SetHandler modperl
PerlResponseHandler JRPC::Apache2
</Location>
=cut
# Parse and handle JSON-RPC Request.
# reads POST body by $r->read($buffer, $len).
# if/else dispatching (of 3 meth) give
>user_agent(__PACKAGE__ . ' ' . $WebService::Desk::VERSION);
$self->content_type('application/json');
$self->base_url('https://' . $self->user . '.desk.com/api/v2');
$self->auth_type('oaut
$opts{no_capture} = 1 if !defined $opts{no_capture};
$opts{dump} = 1 if $opts{yaml} || $opts{json};
if ($opts{metrics_path}) {
Module::CPANTS::Analyse->import(@{$opts{metrics_path}});
return CPAN::Meta::YAML::Dump($thingy);
} elsif ($self->{opts}{json} && eval { require JSON::PP }) {
my $coder = JSON::PP->new->utf8;
$coder->pretty if $pretty;
return $c
st});
}
my $extension =
$self->{opts}{yaml} ? '.yml' :
$self->{opts}{json} ? '.json' :
$self->{opts}{dump} ? '.dmp' :
'.txt';
require File::Spec;
File:
erl
use Data::Dumper;
use JRPC::Client;
use JSON::XS;
use Getopt::Long;
#use threads;
use strict;
use warnings;
=head1 NAME
jrpc_client.pl - Generic JSON-RPC Client for JRPC toolkit
=head1 SYNOPSI
m * url - Service URL to send JSON-RPC request to
=item * method - JSON-RPC Method (e.g 'Pkg.meth' or just 'meth')
=item * parafile - JSON file with parameters for JSON-RPC "params" section
=back
tions (\%para, @pspec);
if (!$para{'url'}) {die("Need URL");}
#if (!$para{'parafile'}) {die("Need JSON-RPC Parameter file ('parafile')");}
if (!$para{'method'}) {die("Need 'method' (In valid format 'm
talsToBrowser warningsToBrowser/;
use JSON::XS;
use JRPC;
use strict;
use warnings;
use Scalar::Util ('reftype'); # Check base types
=head1 NAME
JRPC::CGI - JSON-RPC 2.0 Processing for CGI and HTTP:
:Server::Simple::CGI
=head1 DESCRIPTION
This package provides JSON-RPC 2.0 services processor for 2 runtimes based on:
=over 4
=item * CGI (CGI.pm) Plain old CGI scripting (or mod_perl ModPerl::Re
Keep this anywhere that may use CGI request object
sub CGI::uri {return $_[0]->script_name();}
# JSON RPC Response ID for malformed requests.
our $naid = 666666666;
=head2 JRPC::CGI::handle_cgi($cgi
package JRPC::Nginx;
use JRPC;
use JSON::XS;
# require - to avoid symbol resolution problems ?
require nginx; # nginx / Nginx ?
use strict;
use warnings;
our $VERSION = "0.9";
# See Perldoc at the e
.
#This encapsulates the
#=cut
sub handle_2nd_stage {
my ($r) = @_;
my $jr = {'id' => $$, 'jsonrpc' => '2.0', };
my $buffer = $r->request_body();
eval {
# Parse Request
my $j =
now) that do not serialize
# well. Be ready to encounter exceptions here.
my $out = JSON::XS::encode_json($jr); # Serialize as a separate step to know length
################# Nginx Outpu
qw/:config gnu_compat/;
use Pod::Usage;
GetOptions(\my %opts, qw(
help|? man verbose dump yaml json colour|color save|to_file dir=s metrics_path=s@
));
pod2usage(1) if $opts{help};
pod2usage(-exit
sult using Data::Dumper
--yaml dump result as YAML
--json dump result as JSON
--save write report (or dump) to a file
--dir
tead of displaying a report text).
=head2 --yaml
Dump the result as YAML.
=head2 --json
Dump the result as JSON.
=head3 --save
Output the result into a file instead of STDOUT.
The name of the f
strict;
use Mojo::Autobox;
# "site.com\n"
'{"html": "<a href=\"http://site.com\"></a>"}'
->json('/html')
->dom->at('a')->{href}
->url->host
->byte_stream->say;
=head1 DESCRIPTION
Usi
ackage Acme::Rando;
$Acme::Rando::VERSION = '0.1';
use strict;
use warnings;
use HTTP::Tiny;
use JSON;
use parent 'Exporter';
our @EXPORT = qw(rando);
=head1 NAME
Acme::Rando - Get a Random St
andom?source=starwars&format=json');
unless ($res->{success}) {
return "These aren't the droids you're looking for: $res->{reason}"
}
my $dat = JSON::decode_json($res->{content});
return
);
$self->strict_ssl(1);
$self->content_type('application/json');
$self->default_method('POST');
$self->extension('json');
$self->base_url('https://mandrillapp.com/api/1.0');
$
"Wrong space[$_].field[$fno] type: $type\n"
unless $type =~ /^(NUM|NUM64|STR|JSON|MONEY)$/
}
} else {
die "Wrong space[$_].fields\n";
}