package Amon2::Plugin::Web::JSON;
use strict;
use warnings;
use JSON 2 qw/encode_json/;
use Amon2::Util ();
my $_JSON = JSON->new()->ascii(1);
my %_ESCAPE = (
'+' => '\\u002b', # do not eval as
) = @_;
unless ($c->can('render_json')) {
Amon2::Util::add_method($c, 'render_json', sub {
my ($c, $stuff) = @_;
# for IE7 JSON venularity.
# see http:
//www.atmarkit.co.jp/fcoding/articles/webapp/05/webapp05a.html
my $output = $_JSON->canonical( $conf->{canonical} ? 1 : 0 )->encode($stuff);
$output =~ s!([+<>])!$_ESCAPE{$1}!g
ot generated");
}
# load plugins
__PACKAGE__->load_plugins(
'Web::FillInFormLite',
'Web::JSON',
'+<% $module %>::Web::Plugin::Session',
);
# setup view
use <% $module %>::Web::View;
{
(n=e.getAttribute(r))){try{n="true"===(i=n)||"false"!==i&&("null"===i?null:i===+i+""?+i:J.test(i)?JSON.parse(i):i)}catch(e){}Q.set(e,t,n)}else n=void 0;return n}S.extend({hasData:function(e){return Q.
l, text/xml",json:"application/json, text/javascript"},contents:{xml:/\\bxml\\b/,html:/\\bhtml/,json:/\\bjson\\b/},responseFields:{xml:"responseXML",text:"responseText",json:"responseJSON"},converters
:{"* text":String,"text html":!0,"text json":JSON.parse,"text xml":S.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(e,t){return t?Bt(Bt(e,S.ajaxSettings),t):Bt(S.ajaxSettings,e)},ajaxPr
|| $c, 'streaming', \&_streaming);
Amon2::Util::add_method(ref $c || $c, 'streaming_json', \&_streaming_json);
}
sub _streaming {
my ($self, $code) = @_;
return Amon2::Web::Response:
:Callback->new(
code => sub {
$code->(@_);
}
);
}
sub _streaming_json {
my ($self, $code) = @_;
return Amon2::Web::Response::Callback->new(
code => su
my $respond = shift;
my $writer = $respond->([200, ['Content-Type' => 'application/json;charset=utf-8']]);
my $longpoll_ctx = Amon2::Plugin::Web::Streaming::Writer->new(
ece' => '1.20',
'Plack::Middleware::ReverseProxy' => '0.09',
'JSON' => '2.50',
'Teng' => '0.18',