Stevan Little > Path-Router-0.01 > Path::Router

Download:
Path-Router-0.01.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  1
View/Report Bugs
Module Version: 0.01   Source   Latest Release: Path-Router-0.11

NAME ^

Path::Router - A tool for routing paths

SYNOPSIS ^

  my $router = Path::Router->new;
  
  $router->add_route('blog' => (
      defaults => {
          controller => 'blog',
          action     => 'index',
      }
  ));
  
  $router->add_route('blog/:year/:month/:day' => (
      defaults => {
          controller => 'blog',
          action     => 'show_date',
      },
      # validate with ...
      validations => {
          # ... raw-Regexp refs
          year       => qr/\d{4}/,
          # ... custom Moose types you created
          month      => 'NumericMonth', 
          # ... Moose anon-subtypes created inline
          day        => subtype('Int' => where { $_ <= 31 }),        
      }
  ));
  
  $router->add_route('blog/:action/?:id' => (
      defaults => {
          controller => 'blog',
      },
      validations => {
          action  => qr/\D+/,   
          id      => 'Int',  # also use plain Moose types too
      }
  ));
  
  # ... in your dispatcher
  
  my $deconstructed_path_hash = $router->match('/blog/edit/15');
  
  # ... in your code
  
  my $uri = $router->uri_for(
      controller => 'blog',
      action     => 'show_date',
      year       => 2006,
      month      => 10,
      day        => 5,
  );

DESCRIPTION ^

This module provides a way of deconstructing paths into parameters suitable for dispatching on. It also provides the inverse in that it will take a list of parameters, and construct an appropriate uri for it.

Reversable

This module places a high degree of importance on reversability. The value produced by a path match can be passed back in and you will get the same path you originally put in. The result of this is that it removes ambiguity and therefore reduces the number of possible mis-routings.

Verifyable

This module also provides additional tools you can use to test and verify the integrity of your router. These include:

Hey, wait, this is like RoR!

Yes, this is based on Ruby on Rails ActionController::Routing::Routes, however, it has one important difference.

It is in Perl :)

METHODS ^

new
add_route ($path, ?%options)
routes
match ($path)
uri_for (%path_descriptior)
meta

BUGS ^

All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.

AUTHOR ^

Stevan Little <stevan.little@iinteractive.com>

COPYRIGHT AND LICENSE ^

Copyright 2008 Infinity Interactive, Inc.

http://www.iinteractive.com

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: