Blog

Released Router::Simple 0.01

http://github.com/tokuhirom/p5-router-simple

my $router = router {
  connect '/' => {controller => 'Router', action => 'index'};
  submapper('/entry/{id:[0-9]+}', controller => 'Entry')
    ->connect('/show', {action => 'show'})
     ->connect('/edit', {action => 'edit'});
};

my $psgi_app = sub {
     my $env = shift;
     if (my $p = $router->match($env)) {
         "MyApp::C::$p->{controller}"->can($p->{action})->($env, $p->{args});
    } else {
        return [404, [], ['not found']];
    }
}

I released Router::Simple 0.01 to CPAN.

This is PSGI friendly, fast, lightweight, documented, few deps, and powerful web application dispatcher for Perl5.

The rules are taken from routes.py.

fast?

HTTP::Router: 0.05
Router::Simple: 0.01
HTTPx::Dispatcher: 0.07

                    Rate HTTPx-Dispatcher      HTTP-Router    Router-Simple
HTTPx-Dispatcher   649/s               --             -83%             -99%
HTTP-Router       3794/s             485%               --             -93%
Router-Simple    56776/s            8653%            1397%               --

Yes, Fast!

see. http://github.com/tokuhirom/p5-router-simple/blob/master/tools/benchmark.pl

few dependencies?

Yes!Router::Simple only depend to List::Util and parent.pm.

List::Util was first released with perl 5.007003
parent was first released with perl 5.010001

less memory?

Yes!This module don't load much modules.

backward compatibility with HTTPx::Dispatcher?

rules are upper compatible.You can move to Router-Simple very easy!

conclusion

I hope this module is useful for you. Enjoy!