Router::PathInfo - PATH_INFO router, based on search trees
Allows balancing PATH_INFO to static and controllers. It has a simple and intuitive interface.
Version less than 0.05 is depricated.
use Router::PathInfo; # or use Router::PathInfo as => singletone; # this allow to call after new: instance, clear_singleton my $r = Router::PathInfo->new( static => { allready => { path => '/path/to/static', first_uri_segment => 'static' } }, cache_limit => 300 ); $r->add_rule( connect => '/foo/:enum(bar|baz)/:name(year):re(^\d{4}$)/:any', action => $some_thing, mthods => ['GET','DELETE'], match_callback => $code_ref ); my $env = {PATH_INFO => '/foo/bar/2011/baz', REQUEST_METHOD => 'GET'}; my $res = $r->match($env); # or my $res = $r->match('/foo/bar/2011/baz'); # GET by default # $res = { # type => 'controller', # action => $some, # result call $code_ref->($match, $env) # name_segments => {'year' => 2011} # } $env = {PATH_INFO => '/static/img/some.jpg'}; $res = $r->match($env); # $res = { # type => 'static', # file => '/path/to/static/img/some.jpg', # mime => 'image/jpeg' # }
See more details Router::PathInfo::Controller, Router::PathInfo::Static
Mode as singletone. By default - 0. You can pick up directly, or:
use Router::PathInfo as => singletone; # or require Router::PathInfo; Router::PathInfo->import(as => singletone); # or $Router::PathInfo::as_singleton = 1
If you decide to work in singletone mode, raise the flag before the call to new.
new
When you work in a mode singletone, you have access to methods: instance and clear_singleton
instance
clear_singleton
Constructor. All arguments optsioanlny.
static - it hashref arguments for the constructor Router::PathInfo::Static
cache_limit - limit of matches stored by the rules contain tokens :re and :any, statics and errors. By default - 200. All matches (that occur on an accurate description) cached without limit.
:re
:any
See add_rule from Router::PathInfo::Controller
add_rule
Search match. Initially checked for matches on static, then according to the rules of the controllers. In any event returns hashref coincidence or an error.
Example:
{ type => 'error', code => 400, desc => '$env->{PATH_INFO} not defined' } { type => 'error', code => 404, desc => sprintf('not found for PATH_INFO = %s with REQUEST_METHOD = %s', $env->{PATH_INFO}, $env->{REQUEST_METHOD}) } { type => 'controller', action => $action, name_segments => $hashref_of_names_segments } { type => 'static', file => $serch_file, mime => $mime_type }
git@github.com:mrRico/p5-Router-Path-Info.git
Router::PathInfo::Static, Router::PathInfo::Controller
mr.Rico <catamoose at yandex.ru>
To install Router::PathInfo, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Router::PathInfo
CPAN shell
perl -MCPAN -e shell install Router::PathInfo
For more information on module installation, please visit the detailed CPAN module installation guide.