ew::HTML>
For rendering HTML content, includes utility methods.
=item L<Minima::View::JSON>
For creating JSON responses.
=item L<Minima::View::PlainText>
For plain text output.
=back
=head1 MET
1 NAME
Minima::View::PlainText - Render plain text views
=head1 SYNOPSIS
use Minima::View::JSON;
my $view = Minima::View::PlainText->new;
$view->prepare_response($response);
my $b
'class';
class Minima::View::JSON :isa(Minima::View);
use JSON;
field $app :param;
method prepare_response ($response)
{
$response->content_type('application/json');
}
method render ($data =
? JSON->new->utf8->pretty->encode($data)
: encode_json $data
;
}
__END__
=head1 NAME
Minima::View::JSON - Render JSON views
=head1 SYNOPSIS
use Minima::View::JSON;
View::JSON->new(app => $app);
my $body = $view->render({ data => ... });
=head1 DESCRIPTION
Minima::View::JSON provides a view for generating JSON responses.
Internally, it utilizes L<JSON> to
';
class Minima::Controller;
use Data::Dumper;
use Encode qw(decode);
use Hash::MultiValue;
use JSON;
use Minima::View::PlainText;
use Plack::Request;
use Plack::Response;
use Scalar::Util qw(reftyp
Hash::MultiValue->new(@params);
}
method json_body
{
my $c_type = $request->content_type // '';
return undef unless $c_type =~ m|\Aapplication/json\b|i;
my $body = $request->content //
'';
return undef unless length $body;
my $data;
try {
$data = decode_json($body);
} catch ($e) {
return undef;
}
return $data;
}
method hello
{
$self->r