nd return data and code configured.
For example for : GET http://localhost/rewrite_fake_route/12.json
return code : 200
return body : {"id":12,"test":"get test"}
In configuation, if you put paramete
ke id : :id
* add possibility to request data store in a file like response_file: file/get_answer.json
=head1 INIT MODULE ROUTE
Each route configured in dancer plugin configuration are declare fakly
eq $req->{_route_pattern})
{
set serializer => uc($req_params{format}) || 'JSON';
my $response = plugin_setting->{$req->method()}->{$route}->{response};
utility class to mock the responses from Selenium server
use strict;
use warnings;
use Moo;
use JSON;
use Carp;
use Try::Tiny;
use HTTP::Response;
use Data::Dumper;
extends 'Selenium::Remote::Remot
undef;
my $json = JSON->new;
$json->allow_blessed;
my $decoded_json = $json->allow_nonref(1)->utf8(1)->decode(<$fh>);
close($fh);
$self->session_store($decoded_json);
}
sub dump_
n_store->{$path};
}
my $json = JSON->new;
$json->allow_blessed;
my $json_session = $json->allow_nonref->utf8->pretty->encode($dump);
print $fh $json_session;
close($fh);
}
sub
vailable in JSON, with the additional limitation that only simple keys
are supported.
As a result, all possible YAML Tiny documents should be able to be
transformed into an equivalent JSON document,
warnings;
use Carp;
our $VERSION = '0.04';
use utf8;
use LWP::UserAgent;
use HTTP::Request;
use JSON;
use URI;
our @namespaces = qw( Person Movie );
for (@namespaces) {
my $package = __PACKAGE_
eader( 'Accept' => 'application/json' );
my $json_response = $self->{ua}->request($request);
if ( $json_response->is_success ) {
return decode_json $json_response->content();
}
else {
croak
sprintf( "%s returned by %s", $json_response->status_line, $url );
}
}
# Checks items that will be sent to the API($input)
# $params - an array that identifies v
=head2 Remote Driver Response
Selenium::Remote::Driver uses the L<JsonWireProtocol|http://code.google.com/p/selenium/wiki/JsonWireProtocol> to communicate with the
Selenium Server. If an error oc
rver
sends back an HTTP error code with a JSON encoded reponse that indicates the
precise L<Response Error Code|http://code.google.com/p/selenium/wiki/JsonWireProtocol#Response_Status_Codes>. The mo
$self->{javascript} = JSON::true;
}
else {
$self->{javascript} = JSON::false;
}
}
else {
$self->{javascript} = JSON::true;
}
package WWW::Mailgun;
use strict;
use warnings;
use JSON;
use MIME::Base64;
require LWP::UserAgent;
BEGIN {
our $VERSION = 0.4;
}
sub new {
my ($class, $param) = @_;
my $Key = $param
tent_Type => 'multipart/form-data', Content => $msg);
_handle_response($r);
return from_json($r->decoded_content);
}
sub _get_route {
my ($self, $path) = @_;
if (ref $path eq 'ARRA
r = $self->{lc($method)}->($self,'unsubscribes',$data);
_handle_response($r);
return from_json($r->decoded_content);
}
sub complaints {
my ($self, $method, $data) = @_;
$method = $met
lt => 1,
'File::ShareDir' => '1.00',
);
features(
'JSON support', [
-default => 0,
'JSON' => '2.00',
'JSON::XS' => '2.00',
],
'YAML support', [
'YAML' => '
r an
L<Inline>-based module. This writes C<Makefile>, C<META.yml>, and
C<MYMETA.yml> (or C<MYMETA.json>) if you set an experimental
environmental variable C<X_MYMETA>.
=head2 WriteMakefile (L<Module:
mymeta_json (L<Module::Install::Metadata>)
write_mymeta_yaml;
write_mymeta_json;
B<write_mymeta_yaml> command and B<write_mymeta_json> command are to
write C<MYMETA.yml> and C<MYMETA.json> respe
mpFile('MYMETA.yml', $meta);
}
sub write_mymeta_json {
my $self = shift;
# We need JSON to write the MYMETA.json file
unless ( eval { require JSON; 1; } ) {
return 1;
}
# Generate the data
ta or return 1;
# Save as the MYMETA.yml file
print "Writing MYMETA.json\n";
Module::Install::_write(
'MYMETA.json',
JSON->new->pretty(1)->canonical->encode($meta),
);
}
sub _write_mymeta_da
json_json2 {
<<'...';
[% INCLUDE "js/json-json2.compact.js" %]
...
}
sub json_json2_internal {
<<'...';
;(function(){
var JSON;
[% INCLUDE "js/json2.compact.js" %]
[% INCLUDE "js/json-json
-internal.compact.js" %]
}());
...
}
sub json_yui {
<<'...';
[% INCLUDE "js/json-yui.compact.js" %]
...
}
sub json2 {
<<'...';
[% INCLUDE "js/json2.compact.js" %]
...
}
sub xhr_gregory {
METHODS
head2 kernel
head2 ajax_jquery
head2 ajax_xhr
head2 ajax_yui
head2 json_json2
head2 json_yui
head2 json2
head2 xhr_gregory
head2 xhr_ilinsky
head2 xxx
=head1 COPYRIGHT
Copyright (
Experimental support for MYMETA
if ( $ENV{X_MYMETA} ) {
if ( $ENV{X_MYMETA} eq 'JSON' ) {
$self->Meta->write_mymeta_json;
} else {
$self->Meta->write_mymeta_yaml;
}
}
return 1;
}
1;
I
package WWW::Mixcloud;
use Moose;
use namespace::autoclean;
use URI;
use LWP::UserAgent;
use JSON;
use DateTime::Format::Atom;
use Carp qw/ croak /;
use WWW::Mixcloud::Cloudcast;
use WWW::Mixclo
= $self->ua->get( $API_BASE . $uri->path );
if ( $res->is_success ) {
return decode_json $res->content;
}
else {
croak 'API error: ' . $res->content;
}
}
1;
__END__
S3::Client;
use DateTime;
use Try::Tiny;
use List::MoreUtils qw( uniq );
use CHI 0.50;
use JSON qw(decode_json);
sub _init {
my ( $self, $options ) = @_;
$self->{AWS_ACCESS_KEY_ID} = $option
WS_S3_TEMPLATE_CACHE_OPTIONS} && !$cache_opts ) {
try {
$cache_opts = decode_json( $ENV{TEMPLATE_CACHE_OPTIONS} );
}
catch {
$cache_opts = undef;
t variable TEMPLATE_CACHE_OPTIONS. If using the environment
variable, the values need to be L<JSON> encoded. Otherwise the value will be
an in memory store. The option send is the following:
package Net::AMQP::PP;
use strict;
use warnings;
use JSON ();
our $VERSION = '0.01';
my $data = JSON::from_json(
q[{"domain":{"delivery tag":{"type":"longlong"},"exchange name":{"type":"shortstr"},"
ple.com 105327 123.15.16.108 - apiuser@example.com [19/Dec/2009:03:12:07 +0000] "POST /api/status.json HTTP/1.1" 200 80516 "-" "-" "-"
The duration, IP, timestamp, method, HTTP version, response and
x 0
=item * user packet - apiuser@example.com assigned index 0
=item * url packet - /api/status.json assigned index 0
=item * timestamp packet - since a busy server is likely to have several reques
ellowBot::API::Response;
{
$YellowBot::API::Response::VERSION = '0.96';
}
use Moose;
use JSON qw(decode_json);
use namespace::clean -except => 'meta';
has http => (
is => 'ro',
isa => 'HTTP:
ine,
};
}
my $data = decode_json($self->http->content);
if ($ENV{API_DEBUG} and $ENV{API_DEBUG} > 2) {
warn "JSON response:\n" . $self->http->content . "\n";
}
File::ShareDir;
use JSON;
use FindBin qw/$Bin/;
Net::AMQP::Protocol->load_xml_spec(File::ShareDir::dist_dir("AnyEvent-RabbitMQ") . '/fixed_amqp0-8.xml');
my $data = JSON::to_json(\%Net::AMQP::Protoc
est suite to blow up if you require a module not listed as a
requirement in C<META.yml> or C<META.json>.
perl Build.PL
HARNESS_PERL_SWITCHES=-MModule::Mask::Deps ./Build test
Or use directly
rse::CPAN::Meta;
# Need to load these early in case we mask them later
use CPAN::Meta::YAML;
use JSON::PP;
use File::Spec::Functions qw(
file_name_is_absolute
updir
splitdir
abs2rel
et_deps
@deps = $class->get_deps()
Returns current dependencies as defined in either C<META.json> or C<META.yml>,
checked in that order. This is used internally by import and new, so there's
no
urp;
if ($mode eq 'perl') {
require JSON;
my $json = JSON->new(); #pretty => 1, delimiter => 1);
$context = $json->objToJson(eval $content );
} else {
#assume i
}
sub json_json2 {
<<'...';
[% INCLUDE "js/json-json2.js" %]
...
}
sub json_json2_internal {
<<'...';
;(function(){
var JSON;
[% INCLUDE "js/json2.js" %]
[% INCLUDE "js/json-json2-intern
al.js" %]
}());
...
}
sub json_yui {
<<'...';
[% INCLUDE "js/json-yui.js" %]
...
}
sub json2 {
<<'...';
[% INCLUDE "js/json2.js" %]
...
}
sub xhr_gregory {
<<'...';
[% INCLUDE "js/xhr-
METHODS
head2 kernel
head2 ajax_jquery
head2 ajax_xhr
head2 ajax_yui
head2 json_json2
head2 json_yui
head2 json2
head2 xhr_gregory
head2 xhr_ilinsky
head2 xxx
=head1 COPYRIGHT
Copyright (
x.get('url/data.json');
var elem = document.getElementById('some-div');
elem.innerHTML = Jemplate.process('my-template.html', data);
or:
var data = Ajax.get('url/data.json');
var ele
r simply:
Jemplate.process('my-template.html', 'url/data.json', '#some-div');
or, with jQuery.js:
jQuery.getJSON("url/data.json", function(data) {
Jemplate.process('my-template.html
g
the template code. Presto, we have full featured JavaScript
templating language!
Combined with JSON and xmlHttpRequest, Jemplate provides a really simple
and powerful way to do Ajax stuff.
=head1