Router::Boom - Fast routing engine for web applications
use Router::Boom; my $router = Router::Boom->new(); $router->add('/', 'dispatch_root'); $router->add('/entrylist', 'dispatch_entrylist'); $router->add('/:user', 'dispatch_user'); $router->add('/:user/{year}', 'dispatch_year'); $router->add('/:user/{year}/{month:\d+}', 'dispatch_month'); $router->add('/download/*', 'dispatch_download'); my $dest = $router->match($env->{PATH_INFO});
Router::Boom is a fast path routing engine for Perl5.
Create new instance.
Add new route.
Matching the route. If matching successfully, this method returns 2 values.
First: The destination value, you registered. Second: Captured values from the path.
If matching was failed, this method returns empty list.
$router->add( '/foo', { controller => 'Root', action => 'foo' } );
$router->add( '/wiki/:page', { controller => 'WikiPage', action => 'show' } ); ... $router->match('/wiki/john'); # => {controller => 'WikiPage', action => 'show'}, {page => 'john'}
':name' notation matches qr{([^/]+)}.
qr{([^/]+)}
$router->add( '/download/*', { controller => 'Download', action => 'file' } ); ... $router->match('/download/path/to/file.xml'); # => {controller => 'Download', action => 'file'}, {'*' => 'path/to/file.xml'}
'*' notation matches qr{(.+)}. You will get the captured argument as the special key: *.
qr{(.+)}
*
$router->add( '/blog/{year}', { controller => 'Blog', action => 'yearly' } ); ... $router->match('/blog/2010'); # => {controller => 'Blog', action => 'yearly'}, {year => 2010}
'{year}' notation matches qr{([^/]+)}, and it will be captured.
$router->add( '/blog/{year:[0-9]+}/{month:[0-9]{2}}', { controller => 'Blog', action => 'monthly' } ); ... $router->match('/blog/2010/04'); # => {controller => 'Blog', action => 'monthly'}, {year => 2010, month => '04'}
You can specify regular expressions in named captures.
Note. You can't include normal capture in custom regular expression. i.e. You can't use {year:(\d+)} . But you can use {year:(?:\d+)}.
{year:(\d+)}
{year:(?:\d+)}
Router::Boom is pretty fast!
Rate Router::Simple Router::Boom Router::Simple 8000/s -- -90% Router::Boom 83651/s 946% --
Router::Boom's computational complexity is not linear scale, bug Router::Simple's computational complexity is linear scale.
Then, Router::Simple get slower if registered too much routes. But if you're using Router::Boom then you don't care the performance :)
Copyright (C) tokuhirom.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
tokuhirom <tokuhirom@gmail.com>
Router::Simple is my old one. But it's bit slow and complicated.
Path::Dispatcher is similar, but so complex.
Path::Router is heavy. It depends on Moose.
HTTP::Router has many dependencies. It is not well documented.
HTTPx::Dispatcher is my old one. It does not provide an OO-ish interface.
To install Router::Boom, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Router::Boom
CPAN shell
perl -MCPAN -e shell install Router::Boom
For more information on module installation, please visit the detailed CPAN module installation guide.