weight::VERSION = '1.03';
use 5.006;
use JSON 2.00 (); # works with JSON::XS
use Moose::Role;
use namespace::autoclean;
use Scalar::Util ();
my $JSON = JSON->new->utf8->canonical;
our %INSTANCES;
| ref( $args[0] ) ne 'HASH' )
? $class->BUILDARGS(@args)
: $args[0];
return $JSON->encode($args);
}
1;
__END__
=pod
=head1 NAME
MooseX::Role::Flyweight - Automatically memoiz
/*
* JSON streaming support
*
* Copyright IBM, Corp. 2009
*
* Authors:
* Anthony Liguori <aliguori@us.ibm.com>
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or late
#ifndef QEMU_JSON_STREAMER_H
#define QEMU_JSON_STREAMER_H
#include "qapi/qmp/qlist.h"
#include "qapi/qmp/json-lexer.h"
typedef struct JSONMessageParser
{
void (*emit)(struct JSONMessageParser
QList *tokens);
JSONLexer lexer;
int brace_count;
int bracket_count;
QList *tokens;
uint64_t token_size;
} JSONMessageParser;
void json_message_parser_init(JSONMessageParser *pars
as occurred"
#define QERR_JSON_PARSE_ERROR \
ERROR_CLASS_GENERIC_ERROR, "JSON parse error, %s"
#define QERR_JSON_PARSING \
ERROR_CLASS_GENERIC_ERROR, "Invalid JSON syntax"
#define QERR_KVM_
ERSION = '1.140440';
}
# ABSTRACT: Interface to http://www.omdbapi.com/
use LWP::UserAgent;
use JSON;
use constant BASE_URL => 'http://www.omdbapi.com/';
sub search {
my ( $s, $options ) = @_;
nse = _get( 's', $s, $options );
if ( $response->is_success ) {
my $content = decode_json( $response->content );
return $content->{Search};
}
else {
die $response-
nse = _get( 'i', $i, $options );
if ( $response->is_success ) {
my $content = decode_json( $response->content );
return $content;
}
else {
die $response->status_li
package WWW::NHKProgram::API::Provider::Genre;
use strict;
use warnings;
use utf8;
use JSON ();
use WWW::NHKProgram::API::Area qw/fetch_area_id/;
use WWW::NHKProgram::API::Genre qw/fetch_genre_id
:Provider::Common::call(
$context,
"genre/%(area)s/%(service)s/%(genre)s/%(date)s.json",
{
area => $area,
service => $service,
genre =>
$genre,
date => $date,
},
$raw,
);
return $content if $raw;
return JSON::decode_json($content)->{list}->{$service};
}
1;
package WWW::NHKProgram::API::Provider::Now;
use strict;
use warnings;
use utf8;
use JSON ();
use WWW::NHKProgram::API::Area qw/fetch_area_id/;
use WWW::NHKProgram::API::Service qw/fetch_service_id
a)s/%(service)s.json",
{
area => $area,
service => $service,
},
$raw,
);
return $content if $raw;
return JSON::decode_json($content)->{no
package WWW::NHKProgram::API::Provider::Info;
use strict;
use warnings;
use utf8;
use JSON ();
use WWW::NHKProgram::API::Area qw/fetch_area_id/;
use WWW::NHKProgram::API::Service qw/fetch_service_i
s.json",
{
area => $area,
service => $service,
id => $id,
},
$raw,
);
return $content if $raw;
return JSON::decode_json(
$client->genre_raw()
=item * $client->info_raw()
=item * $client->now_on_air_raw()
Returns raw JSON response of each API.
=back
=head1 FOR DEVELOPERS
Tests which are calling web API directly in
package WWW::NHKProgram::API::Provider::Common;
use strict;
use warnings;
use utf8;
use Carp;
use JSON ();
use Text::Sprintf::Named qw/named_sprintf/;
use constant API_ENDPOINT => "http://api.nhk.or.
ess) {
if ($raw) {
croak $res->{content};
}
my $fault = JSON::decode_json($res->{content})->{fault};
my $fault_str = $fault->{faultstring};
my $faul
lient = Net::HTTP::Spore->new_from_spec('api.json');
$client->enable(
header_name => 'Content-Type',
header_value => 'application/json'
);
=head1 DESCRIPTION
This module is
strict;
use utf8;
use warnings;
use warnings qw(FATAL utf8); # Fatalize encoding glitches.
use JSON::XS;
use Try::Tiny;
# We don't use Moo because we isa CGI::Snapp.
our $VERSION = '2.04';
# --
hes: " . scalar @$response);
# Warning: Do not use ... new -> utf8 -> encode...
$response = JSON::XS -> new -> encode($response);
$self -> param('db') -> simple -> commit;
}
catch
{
my($
log the error despite the error.
$self -> log(error => "System error: $error");
$response = JSON::XS -> new -> encode([$self -> param('system_error')]);
};
return $response;
} # End of displ
n, and will simply reference the novel with a
'novel' attribute.
=back
Let's look at a possible JSON representation of a novel - "The Valley of
Fear" by Sir Arthur Conan Doyle:
# in the 'novels' c
atabase (as described in L<MongoDBx::Class/"CAVEATS AND THINGS TO CONSIDER">).
So, looking at the JSON representations from before, we need to modify
the representations like so:
# in the 'novels' c
to the API
use strict;
use warnings;
our $VERSION = '0.04'; # VERSION
use Moo;
use Carp;
use JSON;
use REST::Client;
has 'request' => (
is => 'ro',
isa => sub {
croak "request s
_key );
$cli->addHeader( 'Content-Type' => 'application/json' );
$cli->addHeader( 'Accept' => 'application/json' );
return $cli;
}
sub create {
my ( $self, %data ) =
esponse(
$self->_rest_cli->POST(
'/' . $self->request->route . '.json',
encode_json( { $self->action => \%data } ),
)
);
}
sub all {
my ( $self, %optio
as defined in L<http://www.mongodb.org/display/DOCS/Database+References>,
for example (this is a JSON example):
{ "$ref": "collection_name", "$id": ObjectId("4cbca90d3a41e35916720100") }
=cut
wit
command will POST to MYREDMINE_SERVER/time_entries.json
#{time_entry => {issue_id => 3, activity_id => 9, hours => 1, comments => 'test'}} in JSON format
$c->time_entries->time_entry->create(i
nicate with Redmine thought the REST::Api.
Any result will be a perl HASH, transformation of the json response into a perl HASH.
=head1 NOTES
The Redmine API is not fully complete, and you should u
warnings-are-a-ticking-time-bomb.html
use warnings NONFATAL => 'all';
use Carp ();
use URI;
use JSON;
use HTTP::Headers;
use LWP::UserAgent;
use LWP::Protocol::https;
use URI::QueryParam;
has 'api_
', is => 'ro', default => sub { 'https://www.dogeapi.com/wow/' };
has 'json', is => 'ro', default => sub {
my $j = JSON->new; $j->allow_nonref; $j
};
has 'ua', is => 'ro', default =>
sub {
my $headers = HTTP::Headers->new;
$headers->header( 'Content-Type' => 'application/json' );
LWP::UserAgent->new(
ssl_opts => { verify_hostname => 1 },
default_
=> 1, # include results
t => 'XML', # or JSON
u => 'http://yourdomain.foo/opensearch/',
b => 'AND', #
return undef unless -f -r -s $passworddb;
require Haineko::JSON;
try {
$credential = Haineko::JSON->loadfile( $passworddb );
} catch {
$exceptions =
psgi.
=head1 SYNOPSIS
use Haineko::HTTPD::Auth;
use Haineko::JSON;
$Haineko::HTTPD::Auth::PasswordDB = Haineko::JSON->loadfile('/path/to/password');
builder {
enable 'Auth::B
md', { title => 'My Project' });
=head1 DESCRIPTION
B<WWW::GoodData> is the client for GoodData JSON-based API
built atop L<WWW::GoodData::Agent> client agent, with focus
on usefullness and correctn
per funcitons for common actions.
=cut
use strict;
use warnings;
use WWW::GoodData::Agent;
use JSON;
use URI;
our $VERSION = '1.11';
our $root = new URI ('https://secure.gooddata.com/gdc');
=head
shift;
my $project = shift;
my $file = shift;
# Parse the manifest
my $upload_info = decode_json (slurp_file ($file));
die "$file: not a SLI manifest"
unless $upload_info->{dataSetSLIManifest
{
my $class = shift;
my $ctype = shift || 'plain';
my $types = {
'json' => 'application/json',
'html' => 'text/html; charset=utf-8',
'plain' => 'text/plain; char
);
}
sub json {
my $self = shift;
my $code = shift || 200;
my $data = shift; # (Ref->[HASH|ARRAY]) or JSON as a string
my $json = q();
require Haineko::JSON;
$json = ref $d
o::JSON->dumpjson( $data ) : $data;
$self->code( $code );
return $self->_res( $json, 'json' );
}
sub _res {
my $self = shift;
my $text = shift || q();
my $type = shift || 'json';