$content = qq[<?xml version='1.0'?>\n<error>Error: $escaped</error>];
} elsif($aspect =~ /json$/smx) {
my $escaped = $self->tt_filters->{js_string}->($errstr);
$content = qq[{"error":"
::Term qw/USE_COLOR/;
use Test2::Harness::Util qw/clean_path/;
use Test2::Harness::Util::JSON qw/json_true json_false/;
use List::Util qw/max/;
our $VERSION = '2.000004';
use parent 'App::Yath::Ren
,
autofill => sub { 'summary.json' },
description => "Write out a summary json file, if no path is provided 'summary.json' will be used. The .json extension is added automatically if
long_examples => ['', '=/path/to/summary.json'],
normalize => sub {
my $val = shift;
$val .= '.json' unless $val =~ m/\.json$/;
return clean_path($val);
_default_headers => (
is => 'ro',
default => sub {
{
'Content-Type' => 'application/json',
}
},
);
sub get_default_header {
my ($self, $name) = @_;
return scalar $self->_defa
calling
#pod C<as_triple> on each sentence in the paragraph. C<as_stripped_triples> removes
#pod JSON types.
#pod
#pod =cut
sub as_triples {
[ map {; $_->as_triple } $_[0]->sentences ]
}
sub as_s
result of calling C<as_pair>
#pod on each sentence in the paragraph. C<as_stripped_pairs> removes JSON types.
#pod
#pod =cut
sub as_pairs {
[ map {; $_->as_pair } $_[0]->sentences ]
}
sub as_strip
les> removes
JSON types.
=head2 as_pairs
C<as_pairs> returns an arrayref containing the result of calling C<as_pair>
on each sentence in the paragraph. C<as_stripped_pairs> removes JSON types.
=hea
_match {
my ( $obj, %opt ) = @_;
my $json = $opt{json};
my $ref = {
id => $json->{id},
name => $json->{name},
lat => $json->{lat},
lon => $json->{lon},
};
bless( $ref, $obj );
re
my $json = $opt{json};
my $ref = {
id => $json->{stopId},
name => $json->{name},
lat => $json->{lat},
lon => $json->{lon},
};
bless( $ref, $obj );
return $ref;
}
sub TO_JSON {
m
onfiguration.
=head2 register
C<register( %items )>
Registers one or many methods into the web application.
$self->register(
json => JSON->new,
yaml => YAML->new
);
=cut
# app.psgi
use Kelp::Less;
module 'JSON';
get '/api/:user/?action' => sub {
my ( $self, $user, $action ) = @_;
my $json = {
success => \1,
use
r => $user,
action => $action // 'ask'
};
return $json;
};
run;
=head2 Using the C<kelp-generator> script
The easiest way to create the directory structure a
my $key = 'parameter_name';
# fetch parameters from query form, body form or JSON body
my $json_or_body_or_query = $self->param($key);
my $always_query = $self->res->query_pa
ub is_html
{
return $_[0]->content_type_is('text/html');
}
sub is_json
{
return $_[0]->content_type_is('application/json');
}
sub is_xml
{
return $_[0]->content_type_is('application/xml'
$self->SUPER::content(@_));
}
sub json_content
{
my $self = shift;
return undef unless $self->is_json;
return try {
$self->app->get_encoder(json => 'internal')->decode($self->con
undef;
};
}
sub param
{
my $self = shift;
if ($self->is_json && $self->app->can('json')) {
return $self->json_param(@_);
}
# safe method without calling Plack::Request::
<Kelp::Response>
object for the current route.
# Inside a route
res->code(403);
res->json->render({ message => "Forbidden" });
=head2 template
A shortcut to C<$self-E<gt>res-E<gt>templa
ule
Loads a Kelp module. The module options may be specified after the module name.
module 'JSON::XS', pretty => 1;
=head2 config
Provides procedural interface to the configuration.
get '
elf->charset || $self->app->charset);
return $self;
}
sub json
{
my $self = shift;
$self->set_content_type('application/json', $self->charset || $self->app->charset);
return $self;
}
self->content_type;
if (!$ct || $ct =~ m{^application/json}i) {
$self->json if !$ct;
return $self->app->get_encoder(json => 'internal')->encode($body);
}
else {
cr
der("<h1>It works!</h1>");
}
# Render a mysterious JSON structure
sub json {
my $self = shift;
$self->res->json->render({ why => 'no' });
}
# Render the stock 404
nd JSON responses.
=item
B<JSON encoder/decoder>. Kelp can handle JSON-formatted requests and responses
automatically, making working with JSON much more enjoyable. On top of that, it
uses L<JSON::M
Template and JSON, then a dump of
the C<loaded_modules> hash will look like this:
{
Template => Kelp::Module::Template=HASH(0x208f6e8),
JSON => Kelp::Module::JSON=HASH(0x209d4
p::Request> instance.
sub some_route {
my $self = shift;
if ( $self->req->is_json ) {
...
}
}
This attribute is a proxy to the same attribute in L</contex
|| $self->diag_headers();
return $self;
}
sub json_content
{
my $self = shift;
my $result;
my $decoder = $self->app->get_encoder(json => 'internal');
try {
$result = $deco
ormatted JSON");
};
return $result;
}
sub json_cmp
{
my ($self, $expected, $test_name) = @_;
local $Test::Builder::Level = $Test::Builder::Level + 1;
$test_name ||= "JSON structu
r('content-type'), qr/json/, 'Content-Type is JSON'
or return $self;
my $json = $self->json_content;
cmp_deeply($json, $expected, $test_name) or diag explain $json;
return $self;
}
lhost:5000',
# Modules to load
modules => [qw/JSON Template/],
# Encoders
encoders => {
json => {
internal => {
utf8 =
$self->app->path . '/../views'
]
},
# JSON
JSON => {
allow_blessed => 1,
convert_blessed => 1,
ill remove the elements from the array:
# in config.pl
{
modules => [qw/Template JSON Logger/]
}
# in test.pl
{
'-modules' => [qw/Logger/] # Remove the Logger mo
dumper {
state $default = do {
require JSON::MaybeXS;
state $json = JSON::MaybeXS->new->utf8->convert_blessed->pretty->canonical;
sub { $json->encode($_[0]); }
};
return $default;
}
lls the whole thing you get back from a JMAP server a "response"
#pod if it's an HTTP 200. Every JSON Array (of three entries -- go read the spec if
#pod you need to!) is called a L<Sentence|JMAP::Te
L<JSON::Typist>, so you may want to strip their type data before using normal
#pod Perl code on them. You can do that with:
#pod
#pod my $struct = $response->as_triples; # gets the complete JSON d
ata
#pod $jtest->strip_json_types( $struct ); # strips all the JSON::Typist types
#pod
#pod Or more simply:
#pod
#pod my $struct = $response->as_stripped_triples;
#pod
#pod There is also L<JMAP::T
ring,
(@diagnostics ? (diagnostics => \@diagnostics) : ()),
});
}
sub strip_json_types {
state $typist = JSON::Typist->new;
$typist->strip_types($_[1]);
}
no Moo;
1;
__END__
=pod
=encod
age CPAN::Testers::Schema::Result::TestReport;
our $VERSION = '0.028';
# ABSTRACT: Raw reports as JSON documents
#pod =head1 SYNOPSIS
#pod
#pod my $schema = CPAN::Testers::Schema->connect( $dsn,
hema>
#pod
#pod =cut
use CPAN::Testers::Schema::Base 'Result';
use Data::UUID;
use DateTime;
use JSON::MaybeXS;
use Mojo::Util qw( html_unescape );
table 'test_report';
__PACKAGE__->load_components(
n the report was inserted into the database.
#pod Will default to the current time.
#pod
#pod The JSON report also contains a C<created> field. This is the date/time
#pod that the report was created o
eased} )->epoch;
$_->{type} = 'cpan';
$_;
} $tx->res->json->@*;
$self->resultset( 'Upload' )->update_or_create( $_ ) for @rows;
}
n )} })
->first->id;
$_;
} $tx->res->json->@*;
# ; use Data::Dumper;
# ; say "Populate summary: " . Dumper \@rows;
err->{message};
}
my @results = $search->{version} ? ( $tx->res->json ) : $tx->res->json->@*;
my @rows = map {
delete $_->{author}; # Author is from
:Base 'ResultSet';
use Scalar::Util qw( blessed );
use Log::Any qw( $LOG );
use JSON::MaybeXS qw( decode_json encode_json );
use Data::FlexSerializer;
use CPAN::Testers::Report;
use CPAN::Testers::Fac
Data::FlexSerializer->new(
assume_compression => 1,
detect_sereal => 1,
detect_json => 1,
);
sub parse_metabase_report( $self, $row ) {
if ( $row->{fact} ) {
re
" column:
# Sometimes the `content` keys are also JSON, sometimes they aren't.
# So, if we get a simple scalar, we assume it's encoded JSON and
# decode it for normalization
for my $ke
@_;
my $json = $opt{json}{legs}[0];
my $time_zone = $opt{time_zone};
my $ref = {
id => $json->{tripId},
mode => $json->{mode},
agency => $json->{agencyN
=> $json->{routeShortName},
route_color => $json->{routeColor},
route_text_color => $json->{routeTextColor},
headsign => $json->{headsign},
is_cancelled => $json->{cancell
ed},
is_realtime => $json->{realTime},
raw_stopovers =>
[ $json->{from}, @{ $json->{intermediateStops} }, $json->{to} ],
raw_polyline => $json->{legGeometry},
time_zone => $time_zone