e Moose;
extends 'ZeroMQ::PubSub';
use ZMQ::LibZMQ2;
use ZMQ::Constants ':all';
use JSON qw/encode_json decode_json/;
use Clone qw/clone/;
use Carp qw/croak/;
# socket to listen for client events
#
from JSON, or undef if failure.
=cut
sub recv {
my ($self) = @_;
my $msg = zmq_recv($self->publish_sock);
my $json_str = zmq_msg_data($msg);
my $json = eval { decode_json($json_str)
};
unless ($json) {
warn "Got invalid event: failed to parse JSON: $@";
return;
}
return $json;
}
=head2 broadcast($event)
Sends $event to all connected subscribers.
#!/usr/bin/env perl
use strict;
use warnings;
require JSON::XS;
require Tapper::Model;
my $or_dbh = Tapper::Model::model()->storage->dbh;
my $ar_chart_lines = $or_dbh->selectall_arrayref(
lines} ) {
my $hr_json;
eval {
$hr_json = JSON::XS::decode_json( $hr_chart_line->{chart_line_statement} );
};
if ( $@ ) {
warn "cannot parse json string: $@";
}
else {
if ( $hr_json->{where} ) {
for my $ar_where_clause ( @{$hr_json->{where}} ) {
my $s_operator = shift @{$ar_where_clause};
my $s_column =
.
=over
=cut
=item DateTime::Duration::TO_JSON
This is defined here to serialize durations as postgres intervals.
=cut
sub DateTime::Duration::TO_JSON {
my $d = shift;
return DateTime::F
urn $res unless ref $names && ref $types;
# Force all bigints into numeric context for JSON. (see JSON::XS)
my %name2type = mesh @$names, @$types;
return $res unless grep /int8/, @$types
{ type => 'text/javascript' },
"\n//<![CDATA[\n"
. "var RecaptchaOptions = "
. $h->json_encode( $options )
. ";\n//]]>\n"
) . "\n";
}
sub get_html {
my $self = shift;
my ( $
package Business::Stripe;
use strict;
use warnings;
use JSON;
use LWP::UserAgent;
use HTTP::Request::Common qw/DELETE GET POST/;
use MIME::Base64;
our $VERSION = '0.04';
use constant URL => 'https
th, $method);
}
=head3 error (I<void>)
Method returns C<0> when encounter error conditions.
The JSON object returned by Stripe can be retrieved via this method.
print $stripe->error->{message}, "\
I<void>)
When calls are successful a positive value is returned
or if possible, the ID. Stripe's JSON object can be retrieved via
this method. Specific values are defined in the Stripe API Documentat
package Net::Dropbox::API;
use common::sense;
use File::Basename qw(basename);
use JSON;
use Mouse;
use Net::OAuth;
use LWP::UserAgent;
use URI;
use HTTP::Request::Common;
use Data::Random qw(rand_ch
lls the users info from dropbox.
=cut
sub account_info {
my $self = shift;
return from_json($self->_talk('account/info'));
}
=head2 list
lists all files in the path defined:
$data =
_json({ http_response_code => 304 });
} else {
return $self->_talk_default_error_handler($resp);
}
},
};
}
return from_json(
method will be returned to the Gearman
client. This is useful to serialize Perl datastructures to JSON
before sending them back to the client.
sub do_some_job : Job : Encode : Decode {
my
ad ) = @_;
return { message => 'OK', status => 1 };
# calls 'encode' and returns JSON string: {"status":1,"message":"OK"}
}
sub custom_encoder : Job : Encode(enc_yaml) : Deco
lf, $result ) = @_;
return JSON::XS::encode_json($result);
}
sub decode {
my ( $self, $workload ) = @_;
return JSON::XS::decode_json($workload);
}
sub enc_yam
e Moose;
extends 'ZeroMQ::PubSub';
use ZMQ::LibZMQ2;
use ZMQ::Constants ':all';
use JSON qw/encode_json decode_json/;
use Carp qw/croak/;
use List::Util qw/shuffle/;
# should only be used internally
= zmq_recv($self->subscribe_sock);
my $msg_str = zmq_msg_data($msg_raw);
my $msg = decode_json($msg_str);
$self->dispatch_event($msg);
}
after 'subscribe' => sub {
my ($self, $evt, $c
re we're connected
$self->connect_publish_sock;
my $json_str = encode_json($msg);
my $res = zmq_send($self->publish_sock, $json_str);
$self->print_debug("Published $evt, res=$res");
{ type => 'text/javascript' },
"\n//<![CDATA[\n"
. "var RecaptchaOptions = "
. $h->json_encode( $options )
. ";\n//]]>\n"
) . "\n";
}
=item C<< get_options_setter_div( $pubkey,
package ZeroMQ::PubSub;
use Moose;
use ZMQ::LibZMQ2;
use JSON;
use namespace::autoclean;
with 'MooseX::Callbacks';
has 'context' => (
is => 'rw',
isa => 'ZMQ::LibZMQ2::Context',
lazy_bu
address => 'Maybe[Location]',
};
use JSON;
# note the lack of Location,
# which is fine because it
# was Maybe[Location]
my $data = decode_json(q[
{
"id": "1234-A",
o declare L<Moose> type constraints to validate nested
data structures as you may get back from a JSON web service or something along
those lines. The doctype declaration can be any arbitrarily nested
path, $settings, $remove_expiration) = @_;
# this assumes the api converts 1 and 0 to JSON::true and JSON::false accordingly
if ($remove_expiration) {
$remove_expiration = 1;
} else {
$remo
package Plack::Middleware::JSONP::Headers;
{
$Plack::Middleware::JSONP::Headers::VERSION = '0.11';
}
#ABSTRACT: Wraps JSON response with HTTP headers in JSONP
use strict;
use parent qw(Plack::Middl
eware);
use Plack::Util;
use Plack::Builder;
use URI::Escape ();
use JSON ();
use Scalar::Util 'reftype';
use HTTP::Headers ();
use Plack::Util::Accessor qw(callback_key headers template);
sub prepa
nless ($self->template) {
$self->template('{ "meta": %s, "data": %s }')
}
}
sub wrap_json {
my ($self, $status, $headers, $data) = @_;
my $meta = { status => $status };
my @
resource_list {
my ($c) = @_;
$c->getopt( 'name=s@', 'id=i@', 'active', 'free', 'json', 'verbose|v', 'help|?' );
if ( $c->options->{help} ) {
say STDERR "$0 re
" --verbose Show extended information";
say STDERR " --json Give results as json";
say STDERR " --help Show this help";
ies = $resources->all;
if ($c->options->{json}) {
require JSON;
my @json_resources;
push @json_resources, {
id => $_->
el';
use Data::Dumper;
use Data::DPath 'dpath';
use DateTime;
use JSON;
use YAML::XS;
use Data::Structure::Util 'unbless';
has debug
ta) = @_; dpath($path)->match($data); };
$Template::Stash::LIST_OPS->{to_json} = sub { JSON->new->pretty->encode(unbless $_[0]) };
$Template::Stash::LIST_OPS->{to_
Dancer ':syntax';
use Dancer::Plugin;
use Carp;
use Try::Tiny;
use Capture::Tiny qw(capture);
use JSON::XS qw();
use Scalar::Util qw(blessed);
# POE sessions will be created by Tapir::MethodCall; let
alidator;
use Tapir::MethodCall;
use Tapir::Documentation::NaturalDocs;
use File::Spec;
my $json_xs = JSON::XS->new->allow_nonref->allow_blessed;
our $VERSION = 0.04;
register setup_tapir_documenta
t->params;
# Decode the JSON payload
if ($request->content_length && $request->content_type && $request->content_type eq 'application/json' && length $request->body) {
n::Parameters>
=head3 L<Hash::Merge>
=head3 L<Hash::Merge::Simple>
=head3 L<JSON>
=head3 L<JSON::Syck>
=head3 L<JSON::XS>
=head3 L<List::AllUtils>
=head3 L<List::MoreUtils>
=head3 L<Log::Log4p
% use 5.010;
% use Tapper::Reports::DPath 'reportdata';
% use Data::Dumper;
% use Data::DPath 'dpath';
% use DateTime;
% use JSON;
% use YAML::XS;
% use Data::Structure::Util 'unbless';
pports 2.0
[NoTabsTests]
[Test::EOL]
trailing_whitespace = 0
[Test::CPAN::Meta::JSON]
[Test::CheckDeps]
[Test::Portability]
;[Test::Pod::LinkCheck] ; Both of these are b
imum_perl = 5.10.1
[CheckPrereqsIndexed]
; META maintenance
[MetaConfig]
[MetaJSON]
[MetaYAML]
[MetaNoIndex]
directory = t
directory = xt
directory = examples
these personalized modules on CPAN. I even bantered
around the idea of using L<MetaCPAN's author JSON input|https://github.com/SineSwiper/Dist-Zilla-PluginBundle-BeLike-You/blob/master/BeLike-You.pod
rowd;
our $VERSION = 0.04;
use warnings;
use Moose;
use LWP::UserAgent;
use HTTP::Request;
use JSON;
use Catalyst::Authentication::Store::Crowd::User;
has 'find_user_url' => (
is => 'ro',
t_user( $info->{username} );
if ( $response->is_success ){
my $crowd_user_info = from_json( $response->decoded_content );
return Catalyst::Authentication::Store::Crowd::User->new({
>app->{app_name},
$self->app->{password}
);
$req->header('Accept' => 'application/json');
my $response = $ua->request( $req );
return $response;
}
1;
__END__
=head1 NAME
C