Amon2::Lite - Sinatra-ish framework on Amon2!
use Amon2::Lite; get '/' => sub { my ($c) = @_; return $c->render('index.tt'); }; __PACKAGE__->to_app(); __DATA__ @@ index.tt <!doctype html> <html> <body>Hello</body> </html>
This is a Sinatra-ish wrapper for Amon2.
THIS MODULE IS BETA STATE. API MAY CHANGE WITHOUT NOTICE.
any(\@methods, $path, \&code)
any($path, \&code)
Register new route for router.
get($path, $code->($c))
post($path, $code->($c))
__PACKAGE__->load_plugin($name, \%opts)
Load a plugin to the context object.
__PACKAGE__->enable_session(%args)
This method enables Plack::Middleware::Session.
%args would be pass to enabled to Plack::Middleware::Session->new.
%args
Plack::Middleware::Session->new
The default state class is Plack::Session::State::Cookie, and store class is Plack::Session::Store::File.
This option enables a response filter, that adds Cache-Control: private header.
Cache-Control: private
__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.
X-Content-Type-Options
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.
X-Frame-Options: DENY
You can provide a constructor arguments by configuration. Write following lines on your app.psgi.
__PACKAGE__->template_options( syntax => 'Kolon', );
You can use any template engine with Amon2::Lite. You can overwrite create_view method same as normal Amon2.
This is a example to use Text::MicroTemplate::File.
use Tiffany::Text::MicroTemplate::File; sub create_view { Tiffany::Text::MicroTemplate::File->new(+{ include_path => ['./tmpl/'] }) }
If you pass the 'handle_static' option to 'to_app' method, Amon2::Lite handles /static/ path to ./static/ directory.
use Amon2::Lite; __PACKAGE__->to_app(handle_static => 1);
There is a tiny TinyURL example: https://github.com/tokuhirom/MyTinyURL/blob/master/app.psgi.
You can enable session by __PACKAGE__->enable_session(). And you can access the session object by $c->session accessor.
__PACKAGE__->enable_session()
$c->session
use Amon2::Lite; get '/' => sub { my $c = shift; my $cnt = $c->session->get('cnt') || 1; $c->session->set('cnt' => $cnt+1); return $c->create_response(200, [], [$cnt]); }; __PACKAGE__->enable_session(); # __PACKAGE__->to_app();
Tokuhiro Matsuno <tokuhirom AAJKLFJEF@ GMAIL COM>
Copyright (C) Tokuhiro Matsuno
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Amon2::Lite, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Amon2::Lite
CPAN shell
perl -MCPAN -e shell install Amon2::Lite
For more information on module installation, please visit the detailed CPAN module installation guide.