GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Amon2::Web::Dispatcher::RouterBoom(3) User Contributed Perl Documentation Amon2::Web::Dispatcher::RouterBoom(3)

Amon2::Web::Dispatcher::RouterBoom - Router::Boom bindings

    package MyApp2::Web::Dispatcher;
    use Amon2::Web::Dispatcher::RouterBoom;

    use MyApp::Web::C::Foo;

    base 'MyApp::Web::C';

    get '/' => 'Foo#bar';

    1;

This is a router class for Amon2. It's based on Router::Boom.

"get($path:Str, $destnation:Str)"
"post($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';
    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 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)"
"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.

Router::Boom's routing rule is really flexible. You can embed regexp in your rule.
"/foo/bar"
String literal matches strings.
"/:foo"
":foo" matches "qr{[^/]}". It's captured.
"/{foo}"
"{foo}" is same as ":foo".
"/{foo:.*}"
You can use the custom regexp for capturing.
"/*"
"*" is same as "{*:.*}".

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();
        }
    }

Amon2
2022-04-08 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.