package Catalyst::Action::Deserialize::JSON;
use Moose;
use namespace::autoclean;
use Scalar::Util qw(openhandle);
extends 'Catalyst::Action';
use JSON;
our $VERSION = '1.06';
$VERSION = eval $VERS
( $rbody ) {
my $json = JSON->new->utf8;
if (my $options = $controller->{json_options}) {
foreach my $opt (keys %$options) {
$json->$opt( $options->{$opt}
);
}
}
my $rdata = eval { $json->decode( $rbody ) };
if ($@) {
return $@;
}
$c->request->data($rdata);
} else {
$c->log->deb
package Catalyst::Action::Serialize::JSON;
use Moose;
use namespace::autoclean;
extends 'Catalyst::Action';
use JSON ();
our $VERSION = '1.06';
$VERSION = eval $VERSION;
has encoder => (
is =>
'ro',
lazy_build => 1,
);
sub _build_encoder {
my $self = shift;
return JSON->new->utf8->convert_blessed;
}
sub execute {
my $self = shift;
my ( $controller, $c ) = @_;
my $sta
erialize::JSON::XS;
use Moose;
use namespace::autoclean;
BEGIN {
$ENV{'PERL_JSON_BACKEND'} = 2; # Always use compiled JSON::XS
}
extends 'Catalyst::Action::Deserialize::JSON';
use JSON::XS ();
Serialize::JSON::XS;
use Moose;
use namespace::autoclean;
BEGIN {
$ENV{'PERL_JSON_BACKEND'} = 2; # Always use compiled JSON::XS
}
extends 'Catalyst::Action::Serialize::JSON';
use JSON::XS ();
o
lization.
=item * C<application/json> => C<JSON>
Uses L<JSON> to generate JSON output. It is strongly advised to also have
L<JSON::XS> installed. The C<text/x-json> content type is supported but i
ns to the json object.
For instance, to relax permissions when deserializing input, add:
__PACKAGE__->config(
json_options => { relaxed => 1 }
)
=item * C<text/javascript> => C<JSONP>
If a c
allback=? parameter is passed, this returns javascript in the form of: $callback($serializedJSON);
Note - this is disabled by default as it can be a security risk if you are unaware.
The usual MIME
EST-y subclass of Catalyst::Request
=head1 SYNOPSIS
if ( $c->request->accepts('application/json') ) {
...
}
my $types = $c->request->accepted_content_types();
=head1 DESCRI
# cope with invalid (missing required q parameter) header like:
# application/json; charset="utf-8"
# http://tools.ietf.org/html/rfc2616#section-14.1
unless
ing it REST methods and attributes.
=head1 SYNOPSIS
if ( $c->request->accepts('application/json') ) {
...
}
my $types = $c->request->accepted_content_types();
=head1 DESCRI
arp about old text/x-json
if ($content_type eq 'text/x-json') {
$c->log->info('Using deprecated text/x-json content-type.');
$c->log->info('Use application/json instead!');
}
ia Type" error. What gives?!
A: Most likely, you haven't set Content-type equal to "application/json", or
one of the accepted return formats. You can do this by setting it in your query
accepted re
mats. You can do this by setting it in your query string
thusly: C<< ?content-type=application%2Fjson (where %2F == / uri escaped). >>
B<NOTE> Apache will refuse %2F unless configured otherwise.
Mak
package Catalyst::Action::Serialize::JSONP;
use Moose;
use namespace::autoclean;
extends 'Catalyst::Action::Serialize::JSON';
our $VERSION = '1.06';
$VERSION = eval $VERSION;
after 'execute' => sub
.$c->res->output().');');
} else {
warn 'Callback: '.$callback_value.' will not generate valid Javascript. Falling back to JSON output';
}
}
};
__PACKAGE__->meta->make_immutable;
1;