#!perl
package CGI::JSONRPC::Dispatcher::Session;
use strict;
use warnings;
our $AUTOLOAD;
return 1;
sub AUTOLOAD {
my($jsonrpco, $id, $to) = splice(@_, 0, 3);
(my $method = $AUTOLOAD) =~ s
my $object = $to->jsonrpc_new($id,$jsonrpco->{session});
return unless $object;
my $result = $object->$method(@_);
$object->_jsonrpc_finish() if $object->can('_jsonrpc_finish');
ret
=head1 NAME
CGI::JSONRPC::Session::Dispatcher - Dispatch JSONRPC requests to persistant objects
=head1 SYNOPSIS
package Hello;
use CGI::JSONRPC::Session::Obj;
use base qw(CGI::JSONRPC::Session::Obj
served.
package R::Writer::Encoder;
use strict;
use warnings;
use JSON::XS (); # XXX - Remove this in the future?
our $CODER = JSON::XS->new->allow_nonref;
sub new { bless \my $c, shift }
sub en
n files and your L<DBIx::Class> Catalyst
model. A search form is also supplied, which can include JSON-powered
ExtJS comboboxes (see L<http://www.extjs.com/>).
To run the included demo application, g
...
=item infobox_order
=back
=head1 TEMPLATES
Documentation TODO
=head1 JSON
Documentation TODO
=cut
our %LOADED; # cache of eval'ed formdefs
sub new {
my ($class, $t
) = @_;
confess if (!$view);
return @{$self->{formdef}->{display}->{$view}};
}
sub stash_json_autocomplete {
my ($self, $query, $id_field, $show_field, $restrict) = @_;
my $searchcol
package CGI::JSONRPC::Session::Obj;
use strict;
our @IGNORE_KEYS = qw( _session _cgi _request );
1;
sub jsonrpc_new {
my($class, $dispatcher, $id, $session,%options) = @_;
warn __PACKAGE__
ill not be possible.";
my $session_key = "jsonrpc_$id";
if ($session and my $data = $session->param($session_key)) {
my $self = $class->_jsonrpc_restore($data);
$self->{_session} =
->{jsonrpc_ignore_keys} = [@IGNORE_KEYS];
return $self;
#return bless $self, $class;
} else {
return bless { id => $id,_session => $session, _session_key => $session_key, jsonrpc
uri => "$localfile_uri",
};
}
}
$catalyst->stash->{json}->{uploads} = \@uploads,;
$catalyst->forward("View::JSON");
}
sub end : ActionClass('RenderView') {
}
1;
re functions, execute loops.
Probably need way to handle datasets.
=item Remove JavaScript-ness
JSON and what not are probably not needed.
=item Document Way To Feed The Script To "R"
=back
=head
JSON::XS;
my $data = {
'three' => [ 1, 2, 3 ],
'four' => { 'a' => 'b' },
'five' => [ 'a', 'b', 'c' ],
};
my $json = to_json($data);
cmpthese(
-1,
{ 'to_json' => sub { to_json
($data) },
'from_json' => sub { from_json($json) },
}
);
rk qw(cmpthese);
use JSON::XS::VersionOneAndTwo;
my $data = {
'three' => [ 1, 2, 3 ],
'four' => { 'a' => 'b' },
'five' => [ 'a', 'b', 'c' ],
};
my $json = encode_json($data);
cmpthese(
-1,
{ 'encode_json' => sub { encode_json($data) },
'decode_json' => sub { decode_json($json) },
}
);
age WebService::Yelp;
use strict;
use warnings;
our $VERSION = '0.03';
use LWP::UserAgent;
use JSON;
use Scalar::Util qw/looks_like_number/;
use WebService::Yelp::Result;
use WebService::Yelp::Nei
f->base_url() || $base_url);
$self->{_uri} = $uri;
# set up the json parser
my $json = JSON->new();
$self->{_json} = $json;
return $self;
}
my %cmap = (
# review search
hat is returned by the API. The default is
WebService::Yelp::* objects. Other options are 'php', 'json', and
'pickle'. If one of these three options is specified, the raw data
will be returned by the
(%) {
my $self = shift;
my %args = @_;
$args{'location'} ||= '';
eval 'use JSON::Syck; 1' or print STDERR "ERR JSON::Syck is missing\n";
use Encode;
# use URI;
my $uri = URI->new("http://maps
.google.com/maps/geo");
$uri->query_form(q => $args{'location'}, output => 'json', key => $self->{'apikey'});
my $res = $ua->get($uri);
# Content-Type: text/javascript; charset=UTF-8; charset=
e::decode($charset, $res->content);
local $JSON::Syck::ImplicitUnicode = 1;
1 if defined $JSON::Syck::ImplicitUnicode; # prevent warning
my $data = JSON::Syck::Load($content);
my @placemark = @{
;
use JSON::XS;
my $data = {
'three' => [ 1, 2, 3 ],
'four' => { 'a' => 'b' },
'five' => [ 'a', 'b', 'c' ],
};
my $json = encode_json($data);
cmpthese(
-1,
{ 'encode_json' => s
ub { encode_json($data) },
'decode_json' => sub { decode_json($json) },
}
);
use warnings;
use Carp;
use URI;
use Web::Scraper;
use WWW::Mechanize;
use WWW::HatenaLogin;
use JSON::Syck 'Load';
our $VERSION = '0.02';
sub new {
my ($class, $args) = @_;
my $base =
get_rkm {
my $self = shift;
my $rkm;
$self->{login}->mech->get("$self->{diary}?mode=json");
eval {
$rkm = Load($self->{login}->mech->content)->{rkm};
};
$rkm;
}
sub
e entry is required')
if !$args->{uri};
$self->{login}->mech->get("$args->{uri}?mode=json");
Load($self->{login}->mech->content);
}
sub retrieve_day {
my ($self, $args) = @_;
package Net::SocialGraph;
use strict;
use JSON::Any;
use LWP::Simple qw();
use URI;
our $VERSION = '1.1';
my $url = 'http://socialgraph.apis.google.com/lookup';
=head1 NAME
Net::SocialGraph - int
turning reachable nodes.
=item pretty (boolean)
Pretty-print returned JSON.
=item callback (string matching /^[\w\.]+$/)
JSONP callback function.
You shouldn't ever have to use this but I put it
@_;
my $json = $self->get_json(@urls) || return undef;
return JSON::Any->jsonToObj($json);
}
=head2 get_json <uri[s]>
The same as above but returns raw JSON.
=cut
sub get_json {
my $s
ar::Mobile;
use strict;
use warnings;
use URI::Escape;
use LWP::UserAgent;
use HTTP::Request;
use JSON::Syck;
our $VERSION = '0.01';
my $add_template =
'<a href="%sstar.add?sid=%s&rks=%s&uri=%s&
a.com';
my $sbase = sprintf('http://s.%s/', $hatena_domain);
my $suri = $sbase . 'entries.json?';
if ($args{sid}) {
$suri .= sprintf('sid=%s&', $args{sid});
}
my $count = 0
ri);
my $res = $ua->request($req);
$res->is_success or return;
my $data = JSON::Syck::Load($res->content);
$sentries = $data->{entries};
}
for my $se (@$sentrie
gin::DumpJSON - FeedPP Plugin for generating JSON
=head1 SYNOPSIS
use XML::FeedPP;
my $feed = XML::FeedPP->new( 'index.rss' );
$feed->limit_item( 10 );
$feed->call( DumpJSON => 'inde
ates a JSON data representation.
=head1 FILE OR STRING
If a JSON filename is C<undef> or C<''>, this module returns a JSON
string instead of generating a JSON file.
$feed->call( DumpJSON => 'f
eed.json' ); # generates a JSON file
my $json = $feed->call( 'DumpJSON' ); # returns a JSON string
=head1 OPTIONS
This plugin allows some optoinal arguments following:
my %opt = (
ilms <wilms@cs.umn.edu>';
$VERSION = 0.11;
use warnings;
use strict;
use LWP::UserAgent;
use JSON::Any;
=head1 NAME
Net::Digg - Quickly consume and interface with the Digg API.
=head1 SYNOPSIS
'http%3A%2F%2Fsearch.cpan.org%2Fdist%2FNet-Digg' unless defined $conf{appkey};
$conf{type} = 'json' unless defined $conf{type};
$conf{ua} = LWP::UserAgent->new();
$conf{ua}->agent($conf{us
dle_args($queryargs);
my $req = $self->{ua}->get($url);
return ($req->is_success) ? JSON::Any->jsonToObj($req->content) : undef;
}
=pod
=head2 get_popular_stories (\%params)
Given
=over
ad3 Performance
C<GM_setValue>, C<GM_getValue> and C<GM_log> talk to the proxy using
synchronous JSONRPC - so they're a little slow. It remains to be seen
whether this is a problem for typical Grease
shift;
my $h = $self->{_html} ||= HTML::Tiny->new;
return 'var GM__global = '
. $h->json_encode(
{
host => $self->{uri}->host,
passthru => $self->get_
}
req.open(method, url, async);
req.send(data);
}
// From http://www.JSON.org/json2.js
function GM__jsonEncode(value) {
var m = { // table of character substitutions
'\b':
package HTTP::Proxy::GreaseMonkey::Redirector;
use warnings;
use strict;
use Carp;
use JSON;
use HTTP::Response;
use HTML::Tiny;
use YAML qw( DumpFile LoadFile );
use LockFile::Simple qw( lock unlock
h_internal {
my ( $self, $headers, $message, $query ) = @_;
my $result = eval {
# JSON == YAML, right?
my %handler = (
setValue => sub {
my ( $args,
{_html} ||= HTML::Tiny->new;
my $qs = $h->url_decode( $query );
my $args = from_json( $qs );
my $method = delete $args->{m}
|| die "Missing 'm' arg";
my $c
= map { $h->json_encode( $_ ) } ( $self->namespace, $self->name );
return join "\n", map {
"function GM_$_() { return GM__proxyFunction("
. join( ', ', $h->json_encode( $_
arp;
our $VERSION = 0.02;
use HTTP::Request::Common qw(GET POST);
use LWP::UserAgent;
use JSON;
sub new {
my $class = shift;
my $self = bless {}, $class;
$self->url('http://okilab.jp
', $res->status_line));
# parse result
my $json = $res->content() || return $self->error('Response content is empty.');
my $result = jsonToObj($json) || return $self->error("Can't parse response
item Can't parse response content.
It occurs when the response content is not able to parse as JSON data.
Please confirm the content of the HTTP::Request object by res().
=back
=head1 CONFIG