BBC (British Broadcasting Corporation) > Pinwheel > Pinwheel::Mapper

Download:
Pinwheel-0.2.7.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  2
Open  0
View/Report Bugs
Source  

NAME ^

Pinwheel::Mapper

SYNOPSIS ^

    use Pinwheel::Mapper;
    my $mapper = Pinwheel::Mapper->new();

    # TODO, add a meaningful synopsis

DESCRIPTION ^

Handles the routing functionality.

ROUTINES ^

Mapper->new()

Constructor method. Creates an empty mapper.

$mapper->reset()

Empties the mapper.

$mapper->connect([NAME,] PATH, OPTIONS)

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.

$params = $mapper->match(PATH)

Finds the first route matching PATH. Routes are tried in the order they were added using $mapper->connect.

If a matching route is found, returns the parameters required. If no matching route is found, returns undef.

TODO, document how matching works.

TODO, document what "the parameters required" means.

$url = $mapper->generate([NAME, ]PARAMS)

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

@names = @{ $mapper->names }

Returns the names of all named routes, sorted, as an array ref.

AUTHOR ^

A&M Network Publishing <DLAMNetPub@bbc.co.uk>

syntax highlighting: