package JSON::RPC::Dispatcher::App;
$JSON::RPC::Dispatcher::App::VERSION = '0.0508';
use Moose;
use JSON::RPC::Dispatcher;
=head1 NAME
JSON::RPC::Dispatcher::App - A base class for creating object o
ION
version 0.0508
=head1 SYNOPSIS
Create your module:
package MyApp;
use Moose;
extends 'JSON::RPC::Dispatcher::App';
sub sum {
my ($self, @params) = @_;
my $sum = 0;
$sum += $_
ented JSON-RPC applications. This is a huge benefit when writing a larger app or suite of applications rather than just exposing a procedure or two. If you build out classes of methods using JSON::RPC
package JSON::RPC::Dispatcher;
$JSON::RPC::Dispatcher::VERSION = '0.0508';
=head1 NAME
JSON::RPC::Dispatcher - A JSON-RPC 2.0 server.
=head1 VERSION
version 0.0508
=head1 SYNOPSIS
In F<app.psgi>:
use JSON::RPC::Dispatcher;
my $rpc = JSON::RPC::Dispatcher->new;
sub add_em {
my @params = @_;
my $sum = 0;
$sum += $_ for @params;
return $sum;
}
$rpc->register( 'sum', \&add
thod=sum;params=[2,3,5];id=1
Or by posting JSON to it like this:
{"jsonrpc":"2.0","method":"sum","params":[2,3,5],"id":"1"}
And you'd get back:
{"jsonrpc":"2.0","result":10,"id":"1"}
=head1 DE
package JSON::RPC::Dispatcher::Procedure;
$JSON::RPC::Dispatcher::Procedure::VERSION = '0.0508';
=head1 NAME
JSON::RPC::Dispatcher::Procedure - The data holder between RPC requests and responses.
=h
ead1 VERSION
version 0.0508
=head1 SYNOPSIS
use JSON::RPC::Dispatcher::Procedure;
my $proc = JSON::RPC::Dispatcher::Procedure->new;
$proc->error_code(300);
my $method = $proc->method;
=head
----------
=head2 invalid_request ( [ data ] )
Sets an Invalid Request error as defined by the JSON-RPC 2.0 spec.
=head3 data
Optionally set some error data for the error.
=cut
sub invalid_req
package JSON::ReadPath;
$JSON::ReadPath::VERSION = '3.01';
use strict;
use warnings;
use JSON::XS qw( encode_json decode_json );
use Mouse;
use Template;
=head1 NAME
JSON::ReadPath - In Jenkins grep
payload json data and assign to an environment
variable.
=head1 USAGE
Let's say Bitbucket pushed a payload '{"commits":{ "branch": "FooBar" }}'
And we want to grab the branch name from the payload
.
BRANCH=$(read_json.pl --env payload --path commits.branch)
=cut
has file => (
is => "ro",
isa => "Str",
);
has string => (
is => "ro",
isa => "Str",
);
has config => (
is
package JSON::Meth;
use strict;
use warnings;
our $VERSION = '1.001007'; # VERSION
use JSON::MaybeXS;
use 5.008001;
use Carp;
use Scalar::Util qw/blessed/;
require Exporter;
our @ISA = qw(Exporter)
our @EXPORT_OK = qw($json);
my $data;
use overload q{""} => sub { $data },
q{@{}} => sub { $data },
q{%{}} => sub { $data };
our ( $json, $j );
$json = $j = bless sub {
in;
my $json_obj = JSON::MaybeXS->new(
convert_blessed => 1,
allow_blessed => 1,
);
# plain data or object at root; just encode it
return $data = $json_obj->decode(
package JSON::TypeInference;
use 5.008001;
use strict;
use warnings;
our $VERSION = "1.0.2";
use List::Util qw(first);
use List::UtilsBy qw(partition_by sort_by);
use JSON::TypeInference::Type::Arr
e JSON::TypeInference::Type::Boolean;
use JSON::TypeInference::Type::Maybe;
use JSON::TypeInference::Type::Null;
use JSON::TypeInference::Type::Number;
use JSON::TypeInference::Type::Object;
use JSON:
ypeInference::Type::String;
use JSON::TypeInference::Type::Union;
use JSON::TypeInference::Type::Unknown;
use constant ENTITY_TYPE_CLASSES => [
map { join '::', 'JSON::TypeInference::Type', $_ } qw
package JSON::TypeInference::Type::Union;
use strict;
use warnings;
sub new {
my ($class, @types) = @_;
return bless { _types => \@types }, $class;
}
sub name {
my ($class) = @_;
return 'uni
ding utf-8
=head1 NAME
JSON::TypeInference::Type::Union - union type
=head1 DESCRIPTION
C< JSON::TypeInference::Type::Union > consists of one or more value types.
C< JSON::TypeInference::Type::Un
package JSON::TypeInference::Type::Atom;
use strict;
use warnings;
sub new {
my ($class) = @_;
return bless {}, $class;
}
sub signature {
my ($self) = @_;
return ref($self)->name;
}
1;
__EN
oding utf-8
=head1 NAME
JSON::TypeInference::Type::Atom - Base class for JSON value types
=head1 DESCRIPTION
C< JSON::TypeInference::Type::Atom > is a base class for JSON value type and provides s
package JSON::TypeInference::Type::Boolean;
use strict;
use warnings;
use parent qw(JSON::TypeInference::Type::Atom);
use Types::Serialiser;
sub name {
my ($class) = @_;
return 'boolean';
}
sub
D__
=encoding utf-8
=head1 NAME
JSON::TypeInference::Type::Boolean - JSON boolean type
=head1 DESCRIPTION
C< JSON::TypeInference::Type::Boolean > represents JSON boolean type.
It is a value type
package JSON::TypeInference::Type::Object;
use strict;
use warnings;
sub new {
my ($class, $properties) = @_;
return bless { properties => $properties }, $class;
}
sub name {
my ($class) = @_;
ND__
=encoding utf-8
=head1 NAME
JSON::TypeInference::Type::Object - JSON object type
=head1 DESCRIPTION
C< JSON::TypeInference::Type::Object > represents JSON object type.
It is a container typ
package JSON::TypeInference::Type::Maybe;
use strict;
use warnings;
use List::Util qw(any);
# ArrayRef[JSON::TypeInference::Type] => Bool
sub looks_like_maybe {
my ($class, $candidate_types) = @_;
return (scalar(@$candidate_types) == 2) && any { $_->isa('JSON::TypeInference::Type::Null') } @$candidate_types;
}
sub new {
my ($class, $type) = @_;
return bless { type => $type }, $class;
}
= @_;
return 0;
}
1;
__END__
=encoding utf-8
=head1 NAME
JSON::TypeInference::Type::Maybe - maybe type
=head1 DESCRIPTION
C< JSON::TypeInference::Type::Maybe > represents a possibility whether
package JSON::TypeInference::Type::String;
use strict;
use warnings;
use parent qw(JSON::TypeInference::Type::Atom);
use Scalar::Util qw(looks_like_number);
sub name {
my ($class) = @_;
return '
ND__
=encoding utf-8
=head1 NAME
JSON::TypeInference::Type::String - JSON string type
=head1 DESCRIPTION
C< JSON::TypeInference::Type::String > represents JSON string type.
It is a value type, a
package JSON::TypeInference::Type::Number;
use strict;
use warnings;
use parent qw(JSON::TypeInference::Type::Atom);
use Scalar::Util qw(looks_like_number);
sub name {
my ($class) = @_;
return '
ND__
=encoding utf-8
=head1 NAME
JSON::TypeInference::Type::Number - JSON number type
=head1 DESCRIPTION
C< JSON::TypeInference::Type::Number > represents JSON number type.
It is a value type, a
package JSON::TypeInference::Type::Unknown;
use strict;
use warnings;
use parent qw(JSON::TypeInference::Type::Atom);
sub name {
my ($class) = @_;
return 'unknown';
}
sub accepts {
my ($class,
JSON::TypeInference::Type::Unknown - unknown type
=head1 DESCRIPTION
C< JSON::TypeInference::Type::Unknown > is retuned if C<< JSON::TypeInference >> encountered a value that does not match any JSON
package JSON::TypeInference::Type::Null;
use strict;
use warnings;
use parent qw(JSON::TypeInference::Type::Atom);
sub name {
my ($class) = @_;
return 'null';
}
sub accepts {
my ($class, $data
__END__
=encoding utf-8
=head1 NAME
JSON::TypeInference::Type::Null - JSON null type
=head1 DESCRIPTION
C< JSON::TypeInference::Type::Null > represents JSON null type.
It is a value type, and so
package JSON::TypeInference::Type::Array;
use strict;
use warnings;
sub new {
my ($class, $element_type) = @_;
return bless { element_type => $element_type }, $class;
}
sub name {
my ($class)
__END__
=encoding utf-8
=head1 NAME
JSON::TypeInference::Type::Array - JSON array type
=head1 DESCRIPTION
JSON::TypeInference::Type::Array represents JSON array type.
It is a container type, an
package JSON::Schema::Generator::Handler::Array;
use strict;
use warnings;
sub process {
my ($class, $array_type, $examples, $dispatch) = @_;
return +{
type => $array_type->name,
items
ackage JSON::Schema::Generator;
use 5.008001;
use strict;
use warnings;
our $VERSION = "0.01";
use JSON::Schema::Generator::Handler::Array;
use JSON::Schema::Generator::Handler::Atom;
use JSON::Sche
ma::Generator::Handler::Maybe::Lifted;
use JSON::Schema::Generator::Handler::Object;
use JSON::Schema::Generator::Handler::Union;
use JSON::TypeInference;
sub new {
my ($class) = @_;
return bless
b generate {
my ($self) = @_;
my $inferred_type = JSON::TypeInference->infer($self->{learned_data});
return {
'$schema' => 'http://json-schema.org/draft-04/schema#',
title => 'TO
package JSON::Schema::Generator::Handler::Union;
use strict;
use warnings;
sub process {
my ($class, $union_type, $examples, $dispatch) = @_;
return +{
type => [ map { $_->name } @{$union
package JSON::Schema::Generator::Handler::Atom;
use strict;
use warnings;
sub process {
my ($class, $atom_type, $examples, $dispatch) = @_;
return +{
type => $atom_type->name,
($atom_typ
e->isa('JSON::TypeInference::Type::Unknown') ? () : (example => $examples->[0])),
};
}
1;