se Test::More;
use File::Basename qw(dirname);
use IPC::Open3;
use MVC::Neaf::Util qw(JSON encode_json decode_json);
my $lib = dirname(__FILE__)."/../lib";
my $pid = open3( \*SKIP_IN, \*CGI_OUT, \*C
table => 'session',
id_as => 'session_name',
content_as => 'json_data', # optional but recommended
expire_as => 'expires', # optional, u
Fast;
use Time::HiRes ();
use Sys::Hostname ();
use Digest::MD5 qw(md5);
use MVC::Neaf::Util qw( JSON http_date run_all_nodie canonize_path encode_b64 );
use MVC::Neaf::Upload;
use MVC::Neaf::Excepti
B<WARNING> Encodings other than UTF-8 are not supported as of yet.
=head2 body_json()
Get decoded request body in JSON format.
In case of errors, error 422 is thrown.
=head2 body_raw()
Returns req
ntent_type
return decode_utf8( $self->body_raw );
});
my $codec = JSON->new->utf8->allow_nonref;
_helper_fallback( body_json => sub {
my ($self, $validator) = @_;
# TODO add validator su
canonize_path
check_path
data_fh
decode_json
encode_b64 decode_b64
encode_json
extra_missing
http_date
JSON
make_getters
maybe_list
path_prefixes
r
ex
run_all
run_all_nodie
supported_methods
);
our @CARP_NOT;
# use JSON::MaybeXS; # not now, see JSON() below
# Alphabetic order, please
=head2 caller_info()
Returns first caller(n) th
};
=head2 JSON()
Because JSON::MaybeXS is not available on all systems, try to load it
or emulate it.
=head2 encode_json
=head2 decode_json
These two are reexported from whatever JSON module we
lement,
and the location (if any) as its one and only C<< <i> >> element.
This page used to be a JSON but it turned out hard to debug
when dealing with javascript.
=cut
sub make_reply {
my ($se
file} line $self->{-line}"
: ''
};
=head2 TO_JSON()
Converts exception to JSON, so that it doesn't frighten View::JS.
=cut
sub TO_JSON {
my $self = shift;
return { %$self };
};
=h
iew::JS;
use strict;
use warnings;
our $VERSION = '0.2901';
=head1 NAME
MVC::Neaf::View::JS - JSON-based view for Not Even A Framework.
=head1 SYNOPSIS
See L<MVC::Neaf>.
use MVC::Neaf;
he default as of 0.20
-jsonp => 'my.jsonp.callback', # this is optional
}
};
Will result in your application returning raw data in JSON/JSONP format
instead or rendering a tem
=head1 METHODS
=cut
use Carp;
use MVC::Neaf::Util qw(JSON);
use parent qw(MVC::Neaf::View);
my $js_id_re = qr/[A-Z_a-z][A-Z_a-z\d]*/;
my $jsonp_re = qr/^$js_id_re(?:\.$js_id_re)*$/;
=head2 new( %
sub fetch { ... };
1;
=head1 METHODS
=cut
use Carp;
use MVC::Neaf::Util qw(encode_json decode_json);
use parent qw(MVC::Neaf::X::Session);
=head2 new( %options )
%options may include:
=ov
ode_json( $data ) };
carp "Failed to encode session data: $@"
if $@;
return $str;
};
=head2 decode
=cut
sub decode {
my ($self, $data) = @_;
my $obj = eval { decode_json( $d
MVC::Neaf::X::Session>.
It will store session data inside a single directory.
The file format is JSON but MAY change in the future.
Uses flock() to avoid collisions.
If session_ttl was specified, o
use Fcntl qw(:flock :seek);
use URI::Escape qw(uri_escape);
use MVC::Neaf::Util qw(JSON encode_json decode_json);
use parent qw(MVC::Neaf::X::Session);
=head2 new( %options )
Constructor. %option
Currently JSON is used.
=cut
sub encode_content {
my ($self, $data) = @_;
return encode_json( $data );
};
sub decode_content {
my ($self, $raw) = @_;
return decode_json( $raw );
use warnings;
use Test::More;
use File::Basename qw(dirname);
use MVC::Neaf::Util qw(JSON encode_json decode_json);
my $perl = $^X;
my $root = dirname(__FILE__)."/..";
my $script = "$root/example
.0) Gecko/20100101 Firefox/5.0";
$ENV{PATH_INFO}="/02/request/and/beyond";
$ENV{QUERY_STRING}="as_json=1";
$ENV{REMOTE_ADDR}="127.0.0.1";
$ENV{REMOTE_PORT}="63555";
$ENV{REQUEST_METHOD}="GET";
$ENV{RE
like $rawhead, qr/^Status: 200\s/s, "Status = 200";
like $rawhead, qr/Content-Type: application\/json/, "Content type present";
my %head = split /:\s*|\s*\n/, $rawhead;
is $head{'Content-Length'},