Amon2-Lite
view release on metacpan or search on metacpan
{
"abstract" : "Sinatra-ish framework on Amon2!",
"author" : [
"Tokuhiro Matsuno <tokuhirom AAJKLFJEF@ GMAIL COM>"
],
"dynamic_config" : 0,
"generated_by" : "Minilla/v2.1.1",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
---
abstract: 'Sinatra-ish framework on Amon2!'
author:
- 'Tokuhiro Matsuno <tokuhirom AAJKLFJEF@ GMAIL COM>'
build_requires:
App::Prove: '0'
File::Temp: '0'
HTTP::Message::PSGI: '0'
HTTP::Request::Common: '0'
HTTP::Response: '0'
Plack::Test: '0'
Plack::Util: '0'
# NAME
Amon2::Lite - Sinatra-ish framework on Amon2!
# SYNOPSIS
use Amon2::Lite;
get '/' => sub {
my ($c) = @_;
return $c->render('index.tt');
};
This method enables [Plack::Middleware::Session](https://metacpan.org/pod/Plack::Middleware::Session).
`%args` would be pass to enabled to `Plack::Middleware::Session->new`.
The default state class is [Plack::Session::State::Cookie](https://metacpan.org/pod/Plack::Session::State::Cookie), and store class is [Plack::Session::Store::File](https://metacpan.org/pod/Plack::Session::Store::File).
This option enables a response filter, that adds ` Cache-Control: private ` header.
- \[EXPERIMENTAL\] `__PACKAGE__->enable_middleware($klass, %args)`
__PACKAGE__->enable_middleware('Plack::Middleware::XFramework', framework => 'Amon2::Lite');
Enable the Plack middlewares.
- `__PACKAGE__->to_app(%args)`
Create new PSGI application instance.
There is a options.
- `no_x_content_type_options : default false`
__PACKAGE__->to_app(no_x_content_type_options => 1);
Amon2::Lite puts `X-Content-Type-Options` header by default for security reason.
You can disable this feature by this option.
- `no_x_frame_options`
__PACKAGE__->to_app(no_x_frame_options => 1);
Amon2::Lite puts `X-Frame-Options: DENY` header by default for security reason.
You can disable this feature by this option.
# FAQ
- How can I configure the options for Xslate?
You can provide a constructor arguments by configuration.
Write following lines on your app.psgi.
lib/Amon2/Lite.pm view on Meta::CPAN
$klass = Plack::Util::load_class($klass, 'Plack::Middleware');
$app = $klass->wrap($app, %$args);
}
}
unless ($opts{no_x_content_type_options}) {
$class->add_trigger(AFTER_DISPATCH => sub {
my ($c, $res) = @_;
$res->header( 'X-Content-Type-Options' => 'nosniff' );
});
}
unless ($opts{no_x_frame_options}) {
$class->add_trigger(AFTER_DISPATCH => sub {
my ($c, $res) = @_;
$res->header( 'X-Frame-Options' => 'DENY' );
});
}
return $app;
};
*{"${base_class}::enable_middleware"} = sub {
my ($class, $klass, %args) = @_;
lib/Amon2/Lite.pm view on Meta::CPAN
1;
__END__
=for stopwords TinyURL
=encoding utf8
=head1 NAME
Amon2::Lite - Sinatra-ish framework on Amon2!
=head1 SYNOPSIS
use Amon2::Lite;
get '/' => sub {
my ($c) = @_;
return $c->render('index.tt');
};
lib/Amon2/Lite.pm view on Meta::CPAN
This method enables L<Plack::Middleware::Session>.
C<< %args >> would be pass to enabled to C<< Plack::Middleware::Session->new >>.
The default state class is L<Plack::Session::State::Cookie>, and store class is L<Plack::Session::Store::File>.
This option enables a response filter, that adds C< Cache-Control: private > header.
=item [EXPERIMENTAL] C<< __PACKAGE__->enable_middleware($klass, %args) >>
__PACKAGE__->enable_middleware('Plack::Middleware::XFramework', framework => 'Amon2::Lite');
Enable the Plack middlewares.
=item C<< __PACKAGE__->to_app(%args) >>
Create new PSGI application instance.
There is a options.
=over 4
=item C<< no_x_content_type_options : default false >>
__PACKAGE__->to_app(no_x_content_type_options => 1);
Amon2::Lite puts C<< X-Content-Type-Options >> header by default for security reason.
You can disable this feature by this option.
=item C<< no_x_frame_options >>
__PACKAGE__->to_app(no_x_frame_options => 1);
Amon2::Lite puts C<< X-Frame-Options: DENY >> header by default for security reason.
You can disable this feature by this option.
=back
=back
=head1 FAQ
t/400_lite/06_enable_middleware.t view on Meta::CPAN
my $app = do {
package MyApp;
use Amon2::Lite;
get '/' => sub {
my $c = shift;
return $c->create_response(200, [], ['OK']);
};
__PACKAGE__->enable_middleware('Plack::Middleware::XFramework', framework => 'Amon2::Lite');
__PACKAGE__->to_app();
};
my $mech = Test::WWW::Mechanize::PSGI->new(app => $app);
$mech->get_ok('http://localhost/');
is($mech->response->header('X-Framework'), 'Amon2::Lite', 'header');
done_testing;
t/400_lite/08_x_nantoka.t view on Meta::CPAN
is($mech->response->header('X-Frame-Options'), 'DENY');
note $mech->response->as_string;
};
subtest 'disabled' => sub {
my $app = do {
package MyApp2;
use Amon2::Lite;
get '/' => sub { shift->create_response(200, [], 'ok') };
__PACKAGE__->to_app(
no_x_content_type_options => 1,
no_x_frame_options => 1,
);
};
my $mech = Test::WWW::Mechanize::PSGI->new(app => $app);
$mech->get_ok('http://localhost/');
ok(!$mech->response->header('X-Content-Type-Options'));
ok(!$mech->response->header('X-Frame-Options'));
note $mech->response->as_string;
};
done_testing;
( run in 1.263 second using v1.01-cache-2.11-cpan-df04353d9ac )