nings;
package CouchDB::View::Document;
use URI::Escape;
use Data::Dump::Streamer;
use JSON::XS;
my $j = JSON::XS->new;
sub new { bless $_[1] => $_[0] }
sub code_to_string {
my ($self, $code) =
$self->code_to_string($self->{views}{$_})
} keys %{ $self->{views} },
},
};
}
sub as_json {
my ($self) = @_;
return $j->encode($self->as_hash);
}
sub uri_id { uri_escape(shift->{_id
ith a hypothetical client
$couchdb_client->put(
'/mydatabase/' . $doc->uri_id,
$doc->as_json,
);
=head1 DESCRIPTION
CouchDB::View::Document provides a Perlish interface to creating L<Cou
use strict;
use warnings;
package CouchDB::View::Server;
use JSON::XS;
use IO::Handle;
my $j = JSON::XS->new;
{
our @d;
sub dmap { push @d, [@_] }
}
sub new { bless $_[1] => $_[0] }
sub in
package POE::Component::Client::CouchDB::Database;
use Moose;
use JSON;
our $VERSION = 0.05;
has couch => (
is => 'ro',
isa => 'POE::Component::Client::CouchDB',
required => 1,
);
);
}
sub get_revinfo {
my ($self, $id, @opt) = @_;
$self->call(GET => $id, query => {revs => JSON::true}, @opt);
}
sub create {
my ($self, $doc, @opt) = @_;
$self->call(POST => q(), content
hDB docs.
=over 4
=item call I<method, path, ...>
This is L<call|POE::Component::Client::REST::JSON/METHODS> with the url and
database parts filled in - use a path such as "_all_docs" instead. You
;
use POE qw(Component::Client::REST::JSON);
use Moose;
our $VERSION = '0.05';
has rest => (
is => 'ro',
isa => 'POE::Component::Client::REST::JSON',
handles => [qw(shutdown)],
defa
ult => sub {
POE::Component::Client::REST::JSON->new(Alias => "$_[0]-REST")
},
);
has host => (
is => 'ro',
isa => 'Str',
default => 'localhost'
);
has port => (
is
1 VERSION
Version 0.05
=head1 SYNOPSIS
This class makes use of L<POE::Component::Client::REST::JSON> to provide an
asynchronous interface to the CouchDB REST API. All methods use
L<call|/METHODS>
e of the nastier details of talking to a REST
service.
use POE qw(Component::Client::REST::JSON);
# simple CouchDB example
POE::Session->create(inline_states => {
_start => sub
poe_kernel->alias_set('foo');
my $rest = $_[HEAP]->{rest} = POE::Component::Client::REST::JSON->new;
$rest->call(GET => 'http://localhost:5984/_all_dbs', callback =>
[$_[SESS
w
one (or the same one, modified). Undefined by default, but see
L<POE::Component::Client::REST::JSON>.
=item response_cooker
Similar to the above, but returns a list of things to be passed to the
package WWW::Twittervision;
use 5.008000;
use strict;
use warnings;
use Carp;
use LWP;
use JSON;
use URI::Escape;
use vars qw($VERSION $DEBUG $TVURL);
our $VERSION = '0.02';
$TVURL = 'http://api.tw
eds a screen name');
my $req_url = $self->{url} . '/user/current_status/' . $screen_name . '.json';
my $req = HTTP::Request->new(GET => $req_url);
my $ua = LWP::UserAgent->new;
m
carp('Unable to access ' . $req_url);
return undef;
}
my $json = new JSON;
my $data = $json->decode($res->content);
return $data;
}
sub update_status {
my $self =
our global vars, there is no way to escape them since CGI::Ajax doesnt support structured data ( JSON ?)
#
my $TOPOLOGY_OBJ = undef;
my $LANDMARKS_CONFIG = $SESSION->param("DOMAINS");
###check if
dering.
The available formatters are:
L<RDF::Server::Formatter::Atom>,
L<RDF::Server::Formatter::JSON>,
L<RDF::Server::Formatter::RDF>.
=for readme stop
=head1 SERVER CONFIGURATION
An RDF::Server
data {
my($self) = @_;
# we want to return a hashref tree of ourselves
# useful for JSON and other data structure style formats
my $data = XML::Simple::XMLin($self -> fetch, NSExpan
urce handler will pass in a Perl data structure. Rendering
to data serialization formats such as JSON or YAML will probably prefer
a data structure instead of RDF.
=item resource : Str
This return
t;
my $form = shift;
my $outserial_key = $self->outserial_key;
my $outserial = 'json';
if($form->{$outserial_key}) {
$outserial = $form->{$outserial_key};
} elsif($u
require YAML;
$obj = YAML::Load($content);
} else {
require JSON;
$obj = JSON::from_json($content);
}
return $obj;
}
1;
__END__
=head1 NAME
Template::Plugin:
a form or just in the url's query_string
- handles many serializations (JSON, Storable, XML::Simple, YAML)
- defaults to JSON
=head1 OVERRIDABLE METHODS
content_cleanup - gets sent a Template::Plu
query=new CGI;
my $outputformat=$query->param('outputformat')||'text';
if($outputformat=~/^(text|json)$/){
print $query->header(-type=>'text/plain');
}elsif($outputformat=~/^(xml)$/){
print $quer
my $h=$sbs->dataRequest(request=>join(',', @batchRequest));
$htot{batchsystem}=$h;
}
if(lc($outputformat) eq 'json'){
require JSON;
print JSON::objToJson(\%htot,{pretty => 1, indent => 2});
}
uri => "$localfile_uri",
};
}
}
$catalyst->stash->{json}->{uploads} = \@uploads,;
$catalyst->forward("View::JSON");
}
sub end : ActionClass('RenderView') {
}
1;
#!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
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
#!perl
package Apache2::JSONRPC;
use Apache2::Const qw(
TAKE1 OR_ALL OK HTTP_BAD_REQUEST SERVER_ERROR M_GET M_POST
);
use Apache2::RequestRec ();
use Apache2::CmdParms ();
use Apache2::RequestIO
CGI::JSONRPC::Base;
use base qw(CGI::JSONRPC::Base Apache2::Module);
our $VERSION = "0.02";
__PACKAGE__->add([ CookOptions(
[
'JSONRPC_Class',
'Perl class to dispatch JSONRPC c
_POST) {
my $json = $self->apache2_read_post($r) or return HTTP_BAD_REQUEST;
$r->content_type("text/json");
$r->print($self->run_json_request($json));
return O
package CGI::JSONRPC::Session;
use CGI::JSONRPC;
use CGI::JSONRPC::Dispatcher::Session;
use base qw(CGI::JSONRPC);
1;
sub new {
my($class,%args) = @_;
%args = __PACKAGE__->init_session(%ar
eaders_json {
my $self = shift;
$self->{session}->header('Content-Type' => "text/json");
}
sub default_dispatcher {
'CGI::JSONRPC::Dispatcher::Session'
}
=pod
=head1 NAME
CGI::JSONRPC::S
ession - Persistant CGI handler for JSONRPC
=head1 SYNOPSIS
use CGI;
use MyDispatcher
my $cgi = new CGI;
MyDispatcher->handler($cgi);
exit;
package MyDispatcher;
sub init_session
#!perl
package CGI::JSONRPC;
use strict;
use warnings;
use CGI::JSONRPC::Dispatcher;
use CGI::JSONRPC::Base;
use base qw(CGI::JSONRPC::Base);
use CGI;
our $VERSION = "0.11";
return 1;
sub headers
lf = shift;
$self->{cgi}->header("text/javascript");
}
sub headers_json {
my $self = shift;
$self->{cgi}->header("text/json");
}
sub handler {
my($class, $cgi,@args) = @_;
$cgi ||
f($method eq 'POST') {
my $json = $cgi->param('POSTDATA') or die "No POST data was sent!";
print $self->headers_json(), $self->run_json_request($json);
return 1;
} else {
package CGI::JSONRPC::Obj;
use strict;
1;
sub jsonrpc_new {
my($class, $id, $dispatcher) = @_;
return bless { id => $id, dispatcher => $dispatcher }, $class;
}
sub jsonrpc_js_name {
my
my $name = shift || $self->jsonrpc_js_name();
return '';
}
sub jsonrpc_javascript {
my $self = shift;
return $self->js_class
}
=pod
=head1 NAME
CGI::JSONRPC::Obj - Base class for easy
e MyHandler;
use CGI::JSONRPC::Obj;
sub jsonrpc_javascript {
my $js;
# construct javascript object
return
}
sub do_something {
# handler that jsonrpc will call...
}
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