1,
desc => 'Set content-type header',
args => sub { ['application/json','application/x-www-form-urlencoded'] },
proc => sub { $client->set_header( 'C
on class, which we don't have an instance of, ewwwww
# Also, naughty modules like Catalyst::View::JSON try to write to _everything_,
# so spit a warning, ignore that (and try to do the right thing any
ON = '0.009';
}
# ABSTRACT: Manage configuration for a given endpoint
use Moo;
use JSON qw(decode_json encode_json);
use File::HomeDir;
use File::Path 2.08 qw(make_path);
has endpoint => (
is =
'HASH'; },
);
sub _build_config {
my $self = shift;
my $config_file = $self->file('config.json');
if (! -e $config_file ) {
warn "creating new config file: $config_file\n";
ode_json({});
close $fh;
}
my $config;
eval {
local $/;
open( my $fh, '<', $config_file ) or die "Unable to open $config_file for reading: $!";
my $json_te
data structures to STDOUT',
args => sub {
[ 'JSON', 'Data::Dumper', 'Data::Dump', 'YAML' ];
},
proc
ngs;
use MooseX::Method::Signatures;
use Moose;
use WebService::Beeminder::Types qw(BeeBool);
use JSON::Any;
use LWP::UserAgent;
use Carp qw(croak);
our $VERSION = '0.002'; # VERSION: Generated by DZ
ult => 'https://www.beeminder.com/api/v1');
# Everything needs to be able to read/write JSON.
my $json = JSON::Any->new;
sub BUILD {
my ($self) = @_;
# Make sure we have a user-agent, if n
,"$user.json"]);
}
# Gets the datapoints for a goal
# DONE: 2011-11-25. This takes no parameters.
method datapoints(Str $goal) {
return $self->_userget( ['goals', $goal, 'datapoints.json']);
}
Loading L<MooseX::Attribute::Deflator::Moose>
will cause HashRefs and ArrayRefs to be encoded as JSON strings. However, you can simply overwrite
those deflators (and inflators) to deflate to somethin
C<benchmark.pl> tests three ways of deflating the value of a HashRef attribute
to a json encoded string (using L<JSON>).
my $obj = MyBenchmark->new( hashref => { foo => 'bar' } );
my $attr =
ate($obj);
Using the deflate attribute method, supplied by this module.
=item accessor
JSON::encode_json($obj->hashref);
If the attribute comes with an accessor, you can use this
method, to defl
ss::Accessor::Lite (
new => 1,
rw => [qw/req res stash args tx debug/]
);
use JSON qw//;
my $_JSON = JSON->new()->ascii(1);
my %_ESCAPE = (
'+' => '\\u002b', # do not eval as UTF-7
'
body );
$self->res;
}
sub render_json {
my $self = shift;
my $obj = shift;
# defense from JSON hijacking
# Copy from Amon2::Plugin::Web::JSON
if ( !$self->req->header('X-Requ
elf->halt(403,"Your request is maybe JSON hijacking.\nIf you are not a attacker, please add 'X-Requested-With' header to each request.");
}
# for IE7 JSON venularity.
# see http://www.atm
fire())},0)}function m(a){for(var b in a){if(b==="data"&&f.isEmptyObject(a[b]))continue;if(b!=="toJSON")return!1}return!0}function l(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(k,"-$1").t
{try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:f.isNumeric(d)?parseFloat(d):j.test(d)?f.parseJSON(d):d}catch(g){}f.data(a,c,d)}else d=b}return d}function h(a){var b=g[a]={},c,d;a=a.split(/\s+/);f
n!0},error:function(a){throw new Error(a)},parseJSON:function(b){if(typeof b!="string"||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(n.test(b.replace(o,"@").replace(p,"
$r{$disk}{count} = Yars::Tools->count_files($disk) if $count;
}
return $c->render_json(\%r) unless $c->param('all');
my %all = ( Yars::Tools->server_url => \%r );
for my $serve
$all{$server} = $res->json;
}
return $c->render_json(\%all);
};
=head2 POST /disk/status
Mark disks up or down. Send the disk root and state (up or down)
as JSON encoded in the body.
=c
);
}
$c->render_text($success ? "ok" : "failed" );
};
=head2 POST /check/manifest
Given JSON with 'manifest' which is a return-delimited string
of filenames and md5s (like the output of md5s
;
use WWW::Foursquare::Events;
use WWW::Foursquare::Pages;
use WWW::Foursquare::Pageupdates;
use JSON;
use LWP;
use URI::Escape;
sub new {
my ($class, %params) = @_;
my $self = {};
l" if $self->{debug};
my $res = $self->{request}->{ua}->get($result_url);
return decode_json($res->content()) if $res->code() == 200;
# throw exception
die $res->content();
}
sub _
package WWW::Foursquare::Response;
use strict;
use warnings;
use JSON;
our %ERROR_TYPE = (
invalid_auth => 'OAuth token was not provided or was invalid',
param_error => 'A re
elf, $class;
return $self;
}
sub process {
my ($self, $res) = @_;
my $data = decode_json($res->content());
my $code = $res->code();
# response is OK
return $data->{response}
se Data::Dumper;
use Try::Tiny;
use File::Path qw/mkpath/;
use File::Temp;
use File::Compare;
use JSON::XS;
use File::stat qw/stat/;
use Mojo::ByteStream qw/b/;
use strict;
use warnings;
our %Bucket2
tateFile;
return $cached if $mod_time && $mod_time == stat($StateFile)->mtime;
our $j ||= JSON::XS->new;
-e $StateFile or LOGDIE "Missing state file $StateFile";
$cached = $j->decode(M
{
my $class = shift;
my $state = shift;
my $dir = dirname($StateFile);
our $j ||= JSON::XS->new;
mkpath $dir;
my $temp = File::Temp->new(DIR => $dir, UNLINK => 0);
print $t
Point;
use Moose;
use MooseX::Storage;
our $VERSION = '0.01';
with Storage('format' => 'JSON', 'io' => 'File');
has 'x' => (is => 'rw', isa => 'Int');
has 'y' => (is => 'rw', isa => 'In
zation format
## (in this case JSON)
# pack the class into a JSON string
$p->freeze(); # { "__CLASS__" : "Point-0.01", "x" : 10, "y" : 10 }
# unpack the JSON string into a class
my $p2 = P
methods to load/store a class
## on the file system
$p->store('my_point.json');
my $p2 = Point->load('my_point.json');
=head1 DESCRIPTION
MooseX::Storage is a serialization framework for Moo
o C<1> value.
This will change the behaviour of C<HashRef> attributes.
Instead of deflating to a JSON string they will be stored as object
in ElasticSearch.
=head2 analyzer
If this attribute or L</
s;
use MooseX::Types -declare => [ qw(UriPath Boolean HTTPMethod JSONBoolean) ];
use MooseX::Types::Moose qw(Str Int Defined);
use JSON;
subtype UriPath,
as Str,
where { $_ =~ m!^/! },
me
as Int,
where { $_ eq 1 || $_ eq 0 };
subtype JSONBoolean,
as Defined,
where { JSON::is_bool($_) };
coerce Boolean,
from JSONBoolean,
via { return int($_) ? 1 : 0 },
fro
el::Document::Role::VERSION = '0.1.4';
}
use Moose::Role;
use ElasticSearchX::Model::Util ();
use JSON;
use Digest::SHA1;
use List::MoreUtils ();
use Carp;
sub _does_elasticsearchx_model_document_rol
BSTRACT: Access the Google Storage JSON API (currently experimental).
# https://developers.google.com/storage/docs/json_api/
use Moose;
use LWP::UserAgent;
use JSON;
use HTTP::Status qw(:constants);
d=$projectId");
die 'Failed to list buckets' unless $res->is_success;
my $response = decode_json($res->decoded_content);
my @buckets = map {Net::Google::Storage::Bucket->new($_)} @{$response-
OUND;
die "Failed to get bucket: $bucket_name" unless $res->is_success;
my $response = decode_json($res->decoded_content);
return Net::Google::Storage::Bucket->new($response);
}
sub insert_bu
earch;
use MooseX::Attribute::Deflator;
use MooseX::Attribute::Deflator::Moose;
use DateTime;
use JSON;
use Scalar::Util qw(blessed);
use MooseX::Types::ElasticSearch qw(:all);
use MooseX::Types -dec
ode_json($_) }, inline_as {
return '$value' if ( $_[0]->dynamic );
return 'JSON::encode_json($value)';
};
inflate [ 'ArrayRef', 'HashRef' ],
via { shift->dynamic ? $_ : decode_json($_)
}, inline_as {
return '$value' if ( $_[0]->dynamic );
return 'JSON::decode_json($value)';
};
deflate 'ArrayRef', via {$_}, inline_as {'$value'};
inflate 'ArrayRef', via {$_}, inline_as {
age Mojolicious::Plugin::BlogSpam;
use Mojo::Base 'Mojolicious::Plugin';
use Mojo::URL;
use Mojo::JSON;
use Mojo::Log;
use Mojo::UserAgent;
use Scalar::Util 'weaken';
our $VERSION = '0.05';
# Todo:
$self->{log}) {
# Serialize comment
my $msg = "[$1]: " . ($2 || '') . ' ' .
Mojo::JSON->new->encode($self->hash);
# Log error
if ($1 eq 'ERROR') {
$log->error($msg);
VERSION
version 0.05
=head1 SYNOPSIS
my $client = Net::HTTP::Spore->new_from_spec('twitter.json');
$client->enable( 'Redirection', max_redirect => 2 );
# or
$client->enable( 'Redir