ic: HTTP wrappers
## $obj_or_undef = $cli->jget($url,\%query_form,$class)
## + wrapper for http json GET requests
sub jget {
my ($cli,$url,$form,$class) = @_;
my $uri = URI->new($url // $cli->{u
>content_ref;
return $class->loadJsonString($cref,utf8=>!utf8::is_utf8($$cref));
}
## $obj_or_undef = $cli->jpost($url,\%query_form,$class)
## + wrapper for json http POST requests
sub jpost {
m
} = $rsp->status_line;
return undef;
}
my $cref = $rsp->content_ref;
return $class->loadJsonString($cref,utf8=>!utf8::is_utf8($$cref));
}
##-------------------------------------------------
ute condition for all kinds of headers, loaded automatically.
=item L<Mojolicious::Plugin::JSONConfig>
JSON configuration files.
=item L<Mojolicious::Plugin::Mount>
Mount whole L<Mojolicious> appl
package Mojolicious::Sessions;
use Mojo::Base -base;
use Mojo::JSON;
use Mojo::Util qw(b64_decode b64_encode);
has [qw(cookie_domain encrypted secure)];
has cookie_name => 'mojolicious';
has
padding are no longer a concern)
sub _deserialize { Mojo::JSON::decode_json($_[0] =~ s/\}\KZ*$//r) }
sub _serialize { Mojo::JSON::encode_json($_[0]) }
1;
=encoding utf8
=head1 NAME
Mojolicious::S
anages sessions based on signed cookies for L<Mojolicious>. All data gets serialized with
L<Mojo::JSON> and stored Base64 encoded on the client-side, but is protected from unwanted changes with a HMAC
Very fun and minimalistic HTML/XML DOM parser with CSS selector support.
=item L<Mojo::JSON>
Minimalistic JSON implementation that just works.
=item L<Mojo::Server::Daemon>
Full featured, highly p
jolicious::Plugins>
=back
=item * L<Mojo::Exception>
=item * L<Mojo::Headers>
=item * L<Mojo::JSON::Pointer>
=item * L<Mojo::Parameters>
=item * L<Mojo::Path>
=item * L<Mojo::Promise>
=item *
Plugin>
=over 2
=item * L<Mojolicious::Plugin::Config>
=over 2
=item * L<Mojolicious::Plugin::JSONConfig>
=over 2
=item * L<Mojolicious::Plugin::NotYAMLConfig>
=back
=back
=item * L<Mojolicio
package Mojo::JSON;
use Mojo::Base -strict;
use Carp qw(croak);
use Exporter qw(import);
use JSON::PP ();
use Mojo::Util qw(decode encode monkey_patch);
use Scalar::Util qw(blessed)
;
# For better performance Cpanel::JSON::XS is required
use constant JSON_XS => $ENV{MOJO_NO_JSON_XS}
? 0
: !!eval { require Cpanel::JSON::XS; Cpanel::JSON::XS->VERSION('4.09'); 1 };
use constan
unimport('experimental::builtin') if CORE_BOOLS;
}
our @EXPORT_OK = qw(decode_json encode_json false from_json j to_json true);
# Escaped special character map
my %ESCAPE
= ('"' => '"', '\\' => '\
ho
=head2 JSON
JSON is the most commonly used data-interchange format for web services. L<Mojolicious> loves JSON and comes with the
possibly fastest pure-Perl implementation L<Mojo::JSON> built rig
h is accessible through
L<Mojo::Message/"json"> as well as the reserved stash value C<json>.
use Mojolicious::Lite -signatures;
# Modify the received JSON document and return it
put '/reverse'
q->json;
$hash->{message} = reverse $hash->{message};
$c->render(json => $hash);
};
app->start;
You can send JSON documents from the command line with L<Mojolicious::Command::get>.
$
::ByteStream qw(b);
use Mojo::Collection qw(c);
use Mojo::DOM;
use Mojo::File qw(path);
use Mojo::JSON qw(j);
use Mojo::URL;
use Mojo::Util qw(dumper monkey_patch);
# Silent one-liners
$ENV{MOJO_LOG_
unctions, which are automatically exported.
=head2 a
my $app = a('/hello' => sub { $_->render(json => {hello => 'world'}) });
Create a route with L<Mojolicious::Lite/"any"> and return the current
cept => '*/*'} => form => {a => 'b'});
my $res = d('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
Perform C<DELETE> request with L<Mojo::UserAgent/"delete"> and return resulting
w::Config;
use v5.40;
use Mojo::Base -base;
# NAME
# ====
#
# Daje::Workflow::Config - Loads the JSON based configs and put them in a hash
#
# SYNOPSIS
# ========
#
# use Daje::Workflow::Config;
#
nfig->param($parameter);
#
# DESCRIPTION
# ===========
#
# Daje::Config is loading workflows from JSON files in a set folder
#
# LICENSE
# =======
#
# Copyright (C) janeskil1525.
#
# This library is f
elf->path . $filename);
my $tag = substr($path->basename(), 0, index($path->basename(), '.json'));
$self->config($config->{$tag});
} catch($e) {
$self->error($e);
};
===================================================
## JSON: load
$data = PACKAGE::loadJsonString( $string,%opts);
$data = PACKAGE::loadJsonFile($filename_or_handle,%opts);
##=================
=======================================================
## JSON: save
$str = PACKAGE::saveJsonString($data);
$bool = PACKAGE::saveJsonFile($data,$filename_or_handle,%opts);
##=================
qw(fcflags fcgetfl fcread fcwrite fctrunc fccreat fcperl fcopen)],
json => [qw(loadJsonString loadJsonFile saveJsonString saveJsonFile)],
sort => [qw(csort_to csortuc_to sortCmd)],
run => [qw(c
package Net::Cloudflare::DNS;
use 5.006;
use strict;
use warnings;
use JSON;
use URI;
use LWP::UserAgent;
use LWP::Protocol::https;
sub new {
my $class = shift;
my %args = @_;
my $ua
Type' => 'application/json',
'Authorization' => "Bearer $args{api_token}",
);
} else {
%headers = (
'Content-Type' => 'application/json',
'X-Aut
ode_json($res->decoded_content);
} else {
die $res->status_line, $res->decoded_content;
}
}
sub create_record {
my $self = shift;
my %args = @_;
my $data = encode_json(\%
->param('name');
$self->res->headers->cache_control('max-age=1, no-cache');
$self->render(json => {hello => $name});
}
=head1 DESCRIPTION
L<Mojolicious::Controller> is the base class for y
ub ($c, $msg) {
$c->app->log->debug("Message: $msg");
});
# Receive JSON object via WebSocket message
$c->on(json => sub ($c, $hash) {
$c->app->log->debug("Test: $hash->{test}");
});
= $c->render(data => $bytes);
my $bool = $c->render(text => 'Hello!');
my $bool = $c->render(json => {foo => 'bar'});
my $bool = $c->render(handler => 'something');
my $bool = $c->render('foo
o::JSON;
use Mojo::Promise;
use POSIX ();
has deserialize => sub { \&Mojo::JSON::decode_json };
has ioloop => sub { Mojo::IOLoop->singleton }, weak => 1;
has serialize => sub { \&Mojo::JSON::e
ncode_json };
sub exit_code { shift->{exit_code} }
sub pid { shift->{pid} }
sub run {
my ($self, @args) = @_;
$self->ioloop->next_tick(sub { $self->_start(@args) });
return $self;
}
sub run_
e(sub {...});
A callback used to deserialize subprocess return values, defaults to using L<Mojo::JSON>.
$subprocess->deserialize(sub ($bytes) { return [] });
=head2 ioloop
my $loop = $subpr
Agent;
use HTTP::CookieJar::LWP;
use Cpanel::JSON::XS;
use File::Basename;
use IO::File;
has json => (
is => 'ro',
default => sub {
return Cpanel::JSON::XS->new->utf8->pretty(1)->allow_nonref;
}
_parse_response {
my ($self, $response) = @_;
if ($response->is_success) {
return $self->json->decode($response->decoded_content);
} else {
return { ok => 0, error => $response->status_l
en it as one
return $cli->open_rcfile($cli->{url},%opts)
if (!-d $path && !-e "$path/header.json");
$cli->{db} = DiaColloDB->new(%dbopts,dbdir=>$path)
or $cli->logconfess("open_file() fai
erimental::signatures';
# Package name.
my $my_package = 'JSON::Relaxed';
# Program name and version.
my ($my_name, $my_version) = qw( rrjson 0.02 );
################ Command line parameters #######
#########
use Getopt::Long 2.13;
# Command line options.
my $mode = "rrjson";
my $execute; # direct JSON from command line
my $schema; # schema (optional)
# Parser options.
my $strict;
my $pret
n/../lib";
use JSON::Relaxed;
use JSON::PP;
use File::LoadLines;
use Encode qw(decode_utf8);
binmode STDOUT => ':utf8';
binmode STDERR => ':utf8';
if ( $schema ) {
my $parser = JSON::Relaxed::Par
ge DiaColloDB::EnumFile;
use DiaColloDB::Persistent;
use DiaColloDB::Utils qw(:fcntl :file :pack :json :regex);
use Fcntl qw(:DEFAULT :seek);
use strict;
##===========================================
upgrades applied to $dbdir
## + list is created by parsing "upgraded" field from "$dbdir/header.json"
## + if the upgrade-item "by" keyword inherits from DiaColloDB::Upgrade::Base,
## a new obje
plied to C<$dbdir>.
Returned list is created by parsing C<"upgraded"> field from C<"$dbdir/header.json">.
If the upgrade-item C<"by"> keyword is the name of a package inheriting from L<DiaColloDB::Upg
= Test::Mojo->new('Celestial');
# Post a JSON document
$t->post_ok('/notifications' => json => {event => 'full moon'})
->status_is(201)
->json_is('/message' => 'notification created');
t->put_ok('/bees' => json => {type => 'worker', name => 'Karl'})
->status_is(202)
->json_has('/id');
# Pull out the id from the response
my $newbee = $t->tx->res->json('/id');
# Make a
est with data from the previous response
$t->get_ok("/bees/$newbee")
->status_is(200)
->json_is('/name' => 'Karl');
The L<Test::Mojo> object is I<stateful>. As long as we haven't started a
our %EXPORT_TAGS;
$EXPORT_TAGS{all} = [@EXPORT_OK];
# [PTR_LENGTH, PTR_PAIR, SZ, JSON_PTR_LENGTH, JSON_PTR_PAIR, JSON_SZ, U8ARRAY_PTR_LENGTH, U8ARRAY_]
sub new {
my ($class, $name, $input_types,