/usr/share/perl5/Poet/Mason/Plugin/Request.pm is in libpoet-perl 0.16-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | package Poet::Mason::Plugin::Request;
$Poet::Mason::Plugin::Request::VERSION = '0.16';
use Mason::PluginRole;
use Poet qw($conf $poet);
use Poet::Plack::Response;
use JSON::XS;
use Try::Tiny;
has 'req' => ( is => 'ro', required => 1, isa => 'Object' );
has 'res' => ( is => 'ro', required => 1, isa => 'Object' );
around 'run' => sub {
my $orig = shift;
my $self = shift;
my $result = $self->$orig(@_);
$self->res->status(200) if !$self->res->status;
$self->res->content_type( $conf->get( 'server.default_content_type' => 'text/html' ) )
if !$self->res->content_type();
$self->res->content( $result->output );
return $result;
};
around 'construct_page_component' => sub {
my $orig = shift;
my $self = shift;
my ( $compc, $args ) = @_;
if ( blessed($args) && $args->can('get_all') ) {
my $orig_args = $args;
$args = $orig_args->as_hashref;
# TODO: cache this
my @array_attrs =
map { $_->name }
grep { $_->has_type_constraint && $_->type_constraint->is_a_type_of('ArrayRef') }
$compc->meta->get_all_attributes;
foreach my $attr (@array_attrs) {
if ( my @values = $orig_args->get_all($attr) ) {
$args->{$attr} = \@values;
}
}
}
$self->$orig( $compc, $args );
};
override 'catch_abort' => sub {
my ( $self, $code ) = @_;
my $retval;
try {
$retval = $code->();
}
catch {
my $err = $_;
if ( $self->aborted($err) ) {
$retval = $err->aborted_value;
}
else {
local $SIG{__DIE__} = undef;
die $err;
}
};
return $retval;
};
before 'abort' => sub {
my ( $self, $retval ) = @_;
$self->res->status($retval) if defined($retval);
};
method redirect () {
$self->res->redirect(@_);
$self->clear_and_abort();
}
method not_found () {
$self->clear_and_abort(404);
}
method session () {
$self->req->session;
}
method send_json ($data) {
$self->clear_buffer;
$self->print( JSON::XS::encode_json($data) );
$self->res->content_type("application/json");
$self->abort();
}
1;
|