SYNOPSIS

    package MyApp;
    use base 'REST::Application::Routes';

    my $obj = REST::Application::Routes->new();
    $obj->loadResource(
        '/data/workspaces/:ws/pages/:page', => \&do_thing,
        # ... other routes here ...
    );

    sub do_thing {
        my %vars = @_;
        print $vars{ws} . " " . $vars{page} . "\n";
    }

    # Now, in some other place.  Maybe a CGI file or an Apache handler, do:
    use MyApp;
    MyApp->new->run("/data/workspaces/cows/pages/good"); # prints "cows good"

DESCRIPTION

Ruby on Rails has this concept of routes. Routes are \s-1URI\s0 path info templates which are tied to specific code (i.e. Controllers and Actions in Rails). That is routes consist of key value pairs, called the route map, where the key is the path info template and the value is a code reference.

A template is of the form: \*(C`/foo/:variable/bar\*(C' where variables are always prefaced with a colon. When a given path is passed to \*(C`run()\*(C' the code reference which the template maps to will be passed a hash where the keys are the variable names (sans colon) and the values are what was specified in place of the variables.

The route map is ordered, so the most specific matching template is used and so you should order your templates from least generic to most generic.

See REST::Application for details. The only difference between this module and that one is that this one uses \s-1URI\s0 templates as keys in the \*(C`resourceHooks\*(C' rather than regexes.

METHODS

These are methods which REST::Application::Routes has but its superclass does not.

\$1

Returns a hash whose keys are the \*(C`:symbols\*(C' from the \s-1URI\s0 template and whose values are what where matched to be there. It is assumed that this method is called either from within or after \*(C`loadResource()\*(C' is called. Otherwise you're likely to get an empty hash back. This is an alias for \*(C`getLastMatchPattern()\*(C', since this class is about templates rather than regexes.

AUTHORS

Matthew O'Connor <[email protected]>

LICENSE

This program is free software. It is subject to the same license as Perl itself.

RELATED TO REST::Application::Routes…

REST::Application, <http://manuals.rubyonrails.com/read/chapter/65>