Pinwheel::Mapper
use Pinwheel::Mapper; my $mapper = Pinwheel::Mapper->new(); # TODO, add a meaningful synopsis
Handles the routing functionality.
Constructor method. Creates an empty mapper.
Empties the mapper.
TODO, document me.
The PATH is tidied.
'defaults' is removed from OPTIONS and kept (default: {})
'requirements' is removed from OPTIONS and kept (default: {})
If PATH is absolute (^\w+://) then the '_static=1' is added to OPTIONS.
target = {}
defaults are merged in from OPTIONS except for keys that begin with "_". (Special keys seem to be: _static _base _filter).
Big scary regex parser replacement thing:
find optional "/" or "." ("prefix") ":" or "*" (type) optional "(" [a-z][a-z0-9_]* ("name") optional ")" push name onto matchkeys if name = "controller" or "action", set the appropriate 'target' to '*' if name "id", defaults{id}||=undef quotemeta prefix if type = "*": pattern = prefix."(.*)" elsif there is a "requirements" for name, use it (it's a regex): pattern = prefix."($requirement)" elsif prefix was "." pattern = prefix.'([^/.][^/]*)' # i.e. .repr is allowed to contain "." else pattern = prefix.'([^/.]+)' # i.e. /:foo is not allowed to contain "." make optional if a default exists for this name: (?:pattern)?
defaults{controller}||=content defaults{action}||=index
target{controller} ||= defaults{controller} target{action} ||= defaults{action}
Each value of 'requirements' is compiled into a regex: ^value$
Route hash is built.
Pushed to 'routes', unless _static (namely: absolute route, or _static=1 specifically passed in)
Stored in 'named', if a name was given.
Finds the first route matching PATH. Routes are tried in the order they were added using $mapper->connect.
$mapper->connect
If a matching route is found, returns the parameters required. If no matching route is found, returns undef.
undef
TODO, document how matching works.
TODO, document what "the parameters required" means.
Create a url for a mapped controller.
TODO, what does that even mean?
NAME is TODO. PARAMS is a list of name/value options.
_base controller action
requirements/defaults/regex
Returns the names of all named routes, sorted, as an array ref.
A&M Network Publishing <DLAMNetPub@bbc.co.uk>
To install Pinwheel, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Pinwheel
CPAN shell
perl -MCPAN -e shell install Pinwheel
For more information on module installation, please visit the detailed CPAN module installation guide.