-
-
09 Nov 2020 09:19:36 UTC
- Distribution: Amon2
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (12)
- Testers (402 / 4 / 2)
- Kwalitee
Bus factor: 1- 69.54% Coverage
- License: perl_5
- Perl: v5.10.0
- Activity
24 month- Tools
- Download (934.99KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 35 contributors-
Tokuhiro Matsuno
-
Adrian
-
Fuji, Goro
-
Geraud
-
Geraud CONTINSOUZAS
-
Hiroyuki Akabane
-
ITO Nobuaki
-
Ichito Nagata
-
Katsuhiro Konishi
-
Kazuhiro Osawa
-
Keiji, Yoshimi
-
Kentaro Kuribayashi
-
Koichi SATOH
-
Masahiro Nagano
-
Neil Bowers
-
Nishibayashi Takuji
-
Syohei YOSHIDA
-
Takafumi Ono
-
Yuki Ibe
-
Zak B. Elep
-
clicktx
-
dragon3
-
hatyuki
-
hiratara
-
hisaichi5518
-
issm
-
karupanerura
-
magnolia
-
mattn
-
moznion
-
noblejasper
-
rightgo09
-
s-aska
-
tokubass
-
wata
- Dependencies
- Digest::SHA
- Encode
- Exporter
- File::Copy::Recursive
- File::ShareDir
- File::Temp
- Getopt::Long
- HTML::FillInForm::Lite
- HTTP::Headers
- HTTP::Session2
- Hash::MultiValue
- JSON
- MIME::Base64
- Module::CPANfile
- Plack
- Plack::Request
- Plack::Response
- Plack::Session
- Plack::Util
- Pod::Usage
- Router::Boom
- Scalar::Util
- Text::Xslate
- Time::HiRes
- Try::Tiny
- URI
- URI::Escape
- URI::QueryParam
- mro
- parent
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Amon2::Web::Dispatcher::RouterBoom - Router::Boom bindings
SYNOPSIS
package MyApp2::Web::Dispatcher; use Amon2::Web::Dispatcher::RouterBoom; use MyApp::Web::C::Foo; base 'MyApp::Web::C'; get '/' => 'Foo#bar'; 1;
DESCRIPTION
This is a router class for Amon2. It's based on Router::Boom.
DSL FUNCTIONS
get($path:Str, $destnation:Str)
post($path:Str, $destnation:Str)
put($path:Str, $destnation:Str)
delete_($path:Str, $destnation:Str)
any($path:Str, $destnation:Str)
-
get '/' => 'Root#index'; get '/:user' => 'User#show'; any '/:user/update' => 'User#update'; post '/:user/blog/post' => 'Blog#post'; put '/:user/blog/put' => 'Blog#put'; delete_ '/:user/blog/:id' => 'Blog#remove';
Add routes by DSL. First argument is the path pattern in Path::Boom rules. Second argument is the destination method path.
Destination method pass is
${class}#${method}
form.The path declared with get() accepts GET and HEAD. The path declared with post() accepts POST method. The path declared with put() accepts PUT method. The path declared with delete_() accepts DELETE method. The path declared with any() accepts any methods.
base($klass:Str)
-
base 'My::App::Web::C';
You can specify the base class name for 'Root#index' style definition.
If you are write your dispatcher in following code, then the method for '/' is
My::App::Web::C::Root->index
.base 'My::App::Web::C'; get '/' => 'Root#index';
get($path:Str, $destnation:CodeRef)
post($path:Str, $destnation:CodeRef)
put($path:Str, $destnation:CodeRef)
delete_($path:Str, $destnation:CodeRef)
any($path:Str, $destnation:CodeRef)
-
get '/' => sub { my ($c) = @_; ... }; get '/:user' => sub { my ($c, $args) = @_; $c->render( 'user.tx' => { user => $args->{user}, }, ); };
Add routes by DSL. First argument is the path pattern in Path::Boom rules. Second argument is the destination code.
Callback function's first argument is the context object. Second is the captured values from the router.
ROUTING RULES
Router::Boom's routing rule is really flexible. You can embed regexp in your rule.
/foo/bar
-
String literal matches strings.
/:foo
-
:foo
matchesqr{[^/]}
. It's captured. /{foo}
-
{foo}
is same as:foo
. /{foo:.*}
-
You can use the custom regexp for capturing.
/*
-
*
is same as{*:.*}
.
EXCEPTION HANDLER
You can customize the exception handler. You can define the special named method 'handle_exception'.
package MyApp::Web::Dispatcher; sub handle_exception { my ($class, $c, $e) = @_; if (UNIVERSAL::isa($e, 'My::Exception::Validation')) { return $c->create_simple_status_page(400, 'Bad Request'); } else { return $c->res_500(); } }
SEE ALSO
Module Install Instructions
To install Amon2, copy and paste the appropriate command in to your terminal.
cpanm Amon2
perl -MCPAN -e shell install Amon2
For more information on module installation, please visit the detailed CPAN module installation guide.