Julián Porta > CGI-Application-Plugin-Routes-1.02 > CGI::Application::Plugin::Routes



Annotate this POD


New  2
Open  0
View/Report Bugs
Module Version: 1.02   Source  


CGI::Application::Plugin::Routes - Routes-style dispatching for CGI::Application


CGI::Application::Plugin::Routes tries to bring to Perl some of the goodies of Rails routes by allowing the creation of a routes table that is parsed at the prerun stage against $ENV{PATH_INFO}. The result of the process (if there's any match at the end of the process) is added to CGI query method from CGI::Application and available in all the runmodes via $self->query->param. By doing this, the plugin provides a uniform way of accessing GET and POST parameters when using clean URIs.


In TestApp.pm

        package TestApp;
        use strict;
        use warnings;
        use base qw/CGI::Application/;
        use CGI::Application::Plugin::Routes;
        sub setup {
                my $self = shift;

        # routes_root optionally is used to prepend a URI part to every route
                        '' => 'home' ,
                        '/view/:name/:id/:email'  => 'view',

        sub view {
                my $self  = shift;
                my $q     = $self->query();
                my $name  = $q->param('name');
                my $id    = $q->param('id');
                my $email = $q->param('email');
                my $debug = $self->routes_dbg; #dumps all the C::A::P::Routes info
                my $params = $self->routes_params; #shows params found.
                return $self->dump_html();

Note that we did not have to call run_modes() to register the run modes. CGI::Application::Plugin::Routes will automatically register each route as run modes if there is no run mode registered with that name, and your application can call target as a method.



Is exported so it can be called from the CGI::Application app to receive the routes table. If no routes table is provided to the module, it will warn and return 0 and no harm will be done to the CGI query params.


This method makes it possible to set a common root for all the routes passed to the plugin, to avoid unnecessary repetition.


Is exported in order to make the callback available into the CGI::Application based app. Not meant to be invoked manually.


This method return a array of all the params found in the query_string


Is exported so you can see what happened on the Routes guts.


Julián Porta, <julian.porta at gmail.com>


Please report any bugs or feature requests to bug-cgi-application-plugin-routes at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Application-Plugin-Routes. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc CGI::Application::Plugin::Routes

You can also look for information at:


Michael Peter's CGI::Application::Dispatch module that can be found here: http://search.cpan.org/~wonko/CGI-Application-Dispatch I borrowed from him most of the routine that parses the url.

Mark Stosberg http://search.cpan.org/~markstos/ Provided very valuable feedback and some useful patches and changes to the code.


Copyright 2008 Julián Porta, all rights reserved.

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

syntax highlighting: