NAME
CGI::Application::Plugin::Routes - CGI::Application::Plugin::Routes
VERSION
Version 0.01
SYNOPSIS
CGI::Application::Plugin::Routes tries to bring to perl some of the goodies of Rails routes by allowing the creationg of a routes table that is parsed at the prerun stage again the CGI's path_info data. The result of the process (if there's any match at the end of the process) is added to CGI's query method from CGI::Application and available to all the runmodes via the CGI::Application::query::param method. By doing this, the plugin provides a uniform way to access GET and POST parameters when using clean url's with the query->param() method.
Perhaps a little code snippet.
In TestApp.om
package TestApp;
use strict;
use warnings;
use base qw/CGI::Application/;
use CGI::Application::Plugin::Routes;
sub setup {
my $self = shift;
$self->routes_root('/thismod');#optional, will be used to prepend every route defines in $self->routes.
$self->routes([
'' => 'home' ,
'/view/:name/:id/:email' => 'view',
]);
$self->start_mode('show');
$self->tmpl_path('templates/');
}
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
return $self->dump_html();
}
1;
Not that we did not have to also call run_modes() to register the run modes. We will automatically register the route targets as run modes if there is not already a run mode registered with that name, and we can call target as a method.
EXPORT
Exported subs:
routes-
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 I<harm> will be done to the CGI query params. routes_root-
This method makes possible to set a common root for all the routes passed to the plugin, to avoid unnecessary repetition. routes_parse-
Is exported in order to make the callback available into the CGI::Application based app. Not meant to be invoked manually. routes_dbg-
Is exported so you can see what happened on the Routes guts.
FUNCTIONS
routes
routes_root
routes_parse
routes_dbg
Ideally, you shouldn't worry for the module functions. Just make sure to pass the routes and use the routes_dbg to see the guts of what happened if something isn't working as expected.
AUTHOR
Julián Porta, <julian.porta at gmail.com>
BUGS
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.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc CGI::Application::Plugin::Routes
You can also look for information at:
github
http://github.com/Porta/cgi--application--plugin--routes/tree/master
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=CGI-Application-Plugin-Routes
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
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 & LICENSE
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.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 205:
Non-ASCII character seen before =encoding in 'Julián'. Assuming UTF-8