Path::Dispatcher::Cookbook.3pm

Langue: en

Version: 2009-12-31 (ubuntu - 24/10/10)

Section: 3 (Bibliothèques de fonctions)

NAME

Path::Dispatcher::Cookbook - A cookbook for Path::Dispatcher

RECIPES

How can I change the path delimiter from a space ' ' to a slash '/'?

When importing the Path::Dispatcher::Declarative sugar, specify the "token_delimiter" option for the "default" group.
     package My::Dispatcher;
     use Path::Dispatcher::Declarative -base, -default => {
         token_delimiter => '/',
     };
 
 

Or define a subclass of Path::Dispatcher::Declarative with a "token_delimiter" method:

     package Web::Dispatcher;
     use base 'Path::Dispatcher::Declarative';
 
     use constant token_delimiter => '/';
 
 
     package My::Other::Dispatcher;
     use Web::Dispatcher -base;
 
 

How can I do rule chaining (like in Catalyst)?

You can use a "chain" rule approximate chaining behavior:
     package MyDispatcher;
     use Path::Dispatcher::Declarative -base;
 
     under show => sub {
         chain {
             print "Displaying ";
         };
         on inventory => sub {
             print "inventory:\n";
             ...
         };
         on score => sub {
             print "score:\n";
             ...
         };
     };
 
     package main;
 
     MyDispatcher->run("show inventory"); # "Displaying inventory:\n ..."
 
     MyDispatcher->run("show score"); # "Displaying score:\n ..."