Test::JSON::RPC::Autodoc::Response;
use strict;
use warnings;
use HTTP::Message::PSGI;
use parent qw/HTTP::Response/;
use Data::Recursive::Encode;
use Encode qw/decode_utf8 encode_utf8/;
use JSON qw//
onse::from_json {
my $self = shift;
my $content = $self->content();
return unless $content;
return JSON::from_json(decode_utf8($content));
}
sub HTTP::Response::pretty_json {
my $
t;
my $content = $self->content();
return unless $content;
my $data = JSON::from_json(decode_utf8($content));
my $json = JSON::to_json($data, { pretty => 1 });
return $json;
}
1;
ckage Test::JSON::RPC::Autodoc::Request;
use strict;
use warnings;
use parent qw/HTTP::Request/;
use Clone qw/clone/;
use JSON qw/to_json/;
use Test::Builder;
use Try::Tiny;
use Test::JSON::RPC::Autod
oc::Response;
use Test::JSON::RPC::Autodoc::Validator;
use Plack::Test::MockHTTP;
sub new {
my ($class, %opt) = @_;
my $self = $class->SUPER::new();
$self->uri($opt{path} || '/');
$se
t{label} || undef;
return $self;
}
sub json_rpc_method {
my ($self, $name) = @_;
return $self->{json_rpc_method} unless $name;
$self->{json_rpc_method} = $name;
return $name;
}
s
package Test::JSON::RPC::Autodoc::Validator;
use strict;
use warnings;
use parent qw/Data::Validator/;
1;
package Test::JSON::RPC::Autodoc;
use 5.008001;
use strict;
use warnings;
use File::ShareDir;
use Path::Tiny qw/path/;
use Text::Xslate;
use Test::JSON::RPC::Autodoc::Request;
our $VERSION = "0.15";
, $class;
return $self;
}
sub new_request {
my ($self, $label) = @_;
my $req = Test::JSON::RPC::Autodoc::Request->new(
app => $self->{app},
path => $self->{path},
File::ShareDir::dist_dir('Test-JSON-RPC-Autodoc') unless -d $dir;
return Text::Xslate->new( path => $dir );
}
1;
__END__
=encoding utf-8
=head1 NAME
Test::JSON::RPC::Autodoc - Testing tools f
::JSON::PerRequest;
use Moo;
use CatalystX::InjectComponent;
use Catalyst::View::JSON::_PerRequest;
our $VERSION = 0.009;
our $DEFAULT_JSON_CLASS = 'JSON::MaybeXS';
our $DEFAULT_VIEW_MODEL = 'JSON::
ViewData';
our %JSON_INIT_ARGS = (
utf8 => 1,
convert_blessed => 1);
extends 'Catalyst::View';
with 'Catalyst::Component::InstancePerContext';
has json => (
is=>'ro',
required=>1,
init_arg
$self = shift;
eval "use ${\$self->json_class}; 1" ||
die "Can't use ${\$self->json_class}, $@";
return $self->json_class->new(
$self->json_init_args);
});
sub HANDLE_ENCODE_E
package Catalyst::Model::JSON::ViewData;
use Moo;
extends 'Catalyst::Model';
with 'Catalyst::Component::InstancePerContext';
with 'Data::Perl::Role::Collection::Hash';
sub build_per_context_insta
nce {
my ($self, $c, %args) = @_;
return $self->new(%args);
}
sub TO_JSON { +{shift->elements} }
sub AUTOLOAD {
my ($self, @args) = @_;
my $key = our $AUTOLOAD;
$key =~ s/.*:://;
retur
@args)
: $self->get($key);
}
1;
=head1 NAME
Catalyst::Model::JSON::ViewData - Default model for Catalyst::View::JSON::PerRequest
=head1 SYNOPSIS
sub root :Chained(/) CaptureArgs(0) {
package Catalyst::View::JSON::_PerRequest;
use HTTP::Status;
use Scalar::Util;
sub data {
my ($self, $data) = @_;
if($data) {
if($self->{data}) {
die "Can't set view data attribute if
a) unless ref $data;
#die "Model $data does not do a required method 'TO_JSON'"
# unless $data->can('TO_JSON');
return $self->{data} = $data;
}
} else {
return $self->{da
self->{ctx}->stats->profile(begin => "=> JSON->send". ($status ? "($status)": ''))
if $self->{ctx}->debug;
my $res = $self->{ctx}->response;
my $json = $self->render($self->data);
$res->h
Test::JSON::More;
use strict;
use warnings;
use Test::Differences;
use parent 'Test::Builder::Module';
our $VERSION = '0.02';
my $JSON;
sub import {
my $class = shift;
my $json_modul
e = shift || 'JSON';
my $caller = caller;
for my $func (qw/ ok_json cmp_json parsed_json ok_json_schema /) {
no strict 'refs'; ## no critic
*{"${caller}::$func"} = \&{"${clas
s}::$func"};
}
$JSON = _load_module($json_module)->new;
}
sub _load_module {
my $module = shift;
my $lib = $module;
$lib =~ s!::!/!g;
require "$lib.pm"; ## no critic
$li
package Dancer::Session::JSON;
# ABSTRACT: JSON session backend for Dancer
$Dancer::Session::JSON::VERSION = '0.002';
use Carp;
use base 'Dancer::Session::Abstract';
use JSON;
use Fcntl ':flock';
use
ng';
use Dancer::FileUtils qw(path set_file_mode);
# static
my %session_dir_initialized;
my $json = JSON->new;
sub init {
my $self = shift;
$self->SUPER::init(@_);
# default value for
t
# representing that session
sub create {
my ($class) = @_;
my $self = Dancer::Session::JSON->new;
$self->flush;
return $self;
}
# deletes the dir cache
sub reset {
my ($class)
package JSON::JSend;
use 5.006;
use strict;
use JSON;
use warnings FATAL => 'all';
=head1 NAME
JSON::JSend - Simple JSON responses (see: labs.omniti.com/labs/jsend)
=head1 VERSION
Version 0.02
=
cut
our $VERSION = '0.02';
=head1 SYNOPSIS
use JSON::JSend;
my $jsend = JSON::JSend->new();
$jsend->success();
$jsend->success({
"post" => {
id => 1,
=head1 SUBROUTINES/METHODS
=head2 new ( [$options] )
$jsend = JSON::JSend->new();
$jsend = JSON::JSend->new(
json_options => { convert_blessed => 1 }
);
Creates a new JSend obj
package Text::Tradition::Parser::JSON;
use strict;
use warnings;
use JSON qw/ from_json /;
=head1 NAME
Text::Tradition::Parser::JSON
=head1 SYNOPSIS
use Text::Tradition;
my $tradition = Te
'name' => 'my text',
'input' => 'JSON',
'string' => $json_encoded_utf8,
);
=head1 DESCRIPTION
Parser module for Text::Tradition to read a JSON alignment table format such
as that pro
option_hash must contain either a 'file' or a
'string' argument with the JSON structure to be parsed.
The structure of the JSON is thus:
{ alignment => [ { witness => "SIGIL",
package Alien::pdf2json;
$Alien::pdf2json::VERSION = '0.002';
use strict;
use warnings;
use parent 'Alien::Base';
use File::Spec;
sub pdf2json_path {
my ($self) = @_;
File::Spec->catfile( $self-
>dist_dir , 'bin', 'pdf2json' );
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Alien::pdf2json
=head1 VERSION
version 0.002
=head1 METHODS
=head2 pdf2json_path
Returns a C<Str> which contai
ns the absolute path
to the C<pdf2json> binary.
=head1 NAME
Alien::pdf2json - Alien package for the pdf2json PDF extraction library
=head1 LICENSE
pdf2json is licensed under GNU GPL v2.
=head1 SE
package Data::Format::Pretty::JSON;
our $DATE = '2016-03-11'; # DATE
our $VERSION = '0.12'; # VERSION
use 5.010001;
use strict;
use warnings;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_
= qw(format_pretty);
sub content_type { "application/json" }
sub format_pretty {
my ($data, $opts) = @_;
$opts //= {};
state $json;
my $interactive = (-t STDOUT);
my $pretty =
equire JSON::Color;
JSON::Color::encode_json($data, {pretty=>$pretty, linum=>$linum})."\n";
} else {
if (!$json) {
require JSON::MaybeXS;
$json = JSON::Mayb
:JSON::XS;
use strict;
use warnings;
use parent qw(Mojolicious::Plugin);
use MojoX::Renderer::JSON::XS;
sub register {
my ($self, $app, $args) = @_;
$app->renderer->add_handler(
json
X::Renderer::JSON::XS->build,
);
}
1;
__END__
=head1 NAME
Mojolicious::Plugin::JSON::XS - MojoX::Renderer::JSON::XS plugin for Mojolicious
=head1 SYNOPSIS
$app->plugin('JSON::XS');
=hea
jolicious::Plugin::JSON::XS plugs L<MojoX::Renderer::JSON::XS> into L<Mojolicious> application.
=head1 METHODS
=head2 register
Registers JSON handler from L<MojoX::Renderer::JSON::XS>.
=head1 SEE
package WebService::SOP::Auth::V1_1::Request::PUT_JSON;
use strict;
use warnings;
use Carp ();
use JSON::XS qw(encode_json);
use HTTP::Request::Common qw(PUT);
use WebService::SOP::Auth::V1_1::Util qw
nt = encode_json($params);
my $sig = create_signature($content, $app_secret);
my $req = PUT $uri, Content => $content;
$req->headers->header('content-type' => 'application/json');
$re
Service::SOP::Auth::V1_1::Request::PUT_JSON
=head1 DESCRIPTION
To create a valid L<HTTP::Request> object for C<PUT> request with content type C<application/json>.
=head1 FUNCTIONS
=head2 $class->c
enderer::JSON::XS;
use 5.010;
use strict;
use warnings;
our $VERSION = "0.07";
use JSON::XS;
use Mojo::Exception ();
use Mojo::Util qw(monkey_patch);
monkey_patch 'Mojo::Exception', TO_JSON => \&Moj
ur $JSON = JSON::XS->new->utf8->convert_blessed;
sub build {
sub { ${$_[2]} = $JSON->encode($_[3]{json}); };
}
1;
__END__
=encoding utf-8
=head1 NAME
MojoX::Renderer::JSON::XS - Fast JSON::X
plugin('JSON::XS');
# Or manually
$app->renderer->add_handler(
json => MojoX::Renderer::JSON::XS->build,
);
}
=head1 DESCRIPTION
MojoX::Renderer::JSON::XS pr
package WebService::SOP::Auth::V1_1::Request::POST_JSON;
use strict;
use warnings;
use Carp ();
use JSON::XS qw(encode_json);
use HTTP::Request::Common qw(POST);
use WebService::SOP::Auth::V1_1::Util
t = encode_json($params);
my $sig = create_signature($content, $app_secret);
my $req = POST $uri, Content => $content;
$req->headers->header('content-type' => 'application/json');
$re
ebService::SOP::Auth::V1_1::Request::POST_JSON
=head1 DESCRIPTION
To create a valid L<HTTP::Request> object for given C<POST> request parameters to send JSON data.
=head1 METHODS
=head2 $class->cr
package PERLANCAR::JSON::Match;
our $DATE = '2016-02-18'; # DATE
our $VERSION = '0.02'; # VERSION
use 5.010001;
use strict;
use warnings;
#use Data::Dumper;
require Exporter;
our @ISA = qw(E
xporter);
our @EXPORT_OK = qw(match_json);
our $MATCH_JSON = qr{
(?&VALUE) (?{ $_ = $^R->[1] if 0 })
(?(DEFINE)
(?<OBJECT>
#(?{ [$^R, {}] })
\{\s*
(?: (?&KV) # [[$^R, {}], $k, $v]
# (
h_json {
state $re = qr/\A$MATCH_JSON\z/;
shift =~ $re ? 1:0;
}
1;
# ABSTRACT: Match JSON string using regex
__END__
=pod
=encoding UTF-8
=head1 NAME
PERLANCAR::JSON::Match - Match JSON
package JSON::MergePatch;
use 5.008001;
use strict;
use warnings;
our $VERSION = "0.04";
use parent 'Exporter';
use JSON::MaybeXS qw/encode_json decode_json/;
use List::MoreUtils qw/uniq/;
use Test:
ur @EXPORT = qw/json_merge_patch json_merge_diff/;
sub patch {
my ($class, $target, $patch, $opt) = @_;
if (defined $target && !$opt->{repeat}) {
$target = decode_json($target);
}
}
}
return ref $target ? encode_json($target) : $target;
}
return ref $patch ? encode_json($patch) : $patch;
}
sub diff {
my ($class, $source, $target,
ge Qudo::Hook::Serialize::JSON;
use strict;
use warnings;
use base 'Qudo::Hook';
use JSON::XS;
sub load {
my ($class, $klass) = @_;
$klass->hooks->{serialize}->{json} = sub {
my $arg
{arg} = encode_json($args->{arg});
};
$klass->hooks->{deserialize}->{json} = sub {
my $job = shift;
$job->arg_origin = $job->arg;
$job->arg = decode_json($job->arg);
};
}
sub unload {
my ($class, $klass) = @_;
delete $klass->hooks->{serialize}->{json};
delete $klass->hooks->{deserialize}->{json};
}
1;