NAME CGI::Application::Plugin::ActionDispatch - Perl extension SYNOPSIS # In "WebApp.pm"... package WebApp; use base 'CGI::Application'; use CGI::Application::Plugin::ActionDispatch; sub do_stuff : Path('do/stuff') { ... } sub do_more_stuff : Regex('^/do/more/stuff\/?$') { ... } sub do_something_else : Regex('do/something/else/(\w+)/(\d+)$') { ... } DESCRIPTION CGI::Application::Plugin::ActionDispatch adds attribute based support for parsing the PATH_INFO of the incoming request. For those who are familiar with Catalyst. The interface works very similar. This plugin is plug and play and shouldn't interrupt the default behavior of CGI::Application. METHODS snippets() If using capturing parentheses in a Regex action. The captured values are accessible using this method. sub addElement : Regex('add/(\d+)/(\d+)') { my $self = shift; my($column, $row) = $self->snippets(); .... } The Path action also stores the left over PATH_INFO. # http://example.com/city/pa/philadelphia sub city : Path('city/') { my $self = shift; my($state, $city) = $self->snippets(); .... } ACTIONS Regex The Regex action is passed a regular expression. The regular expression is run on the PATH_INFO sent in the request. If capturing parentheses are used to extract parameters from the path. The parameters are accesssible using the snippets() method. Regex('^blah/foo'); The Regex action either matches or it doesn't. There are no secrets to it. It does however takes priority over the Path action. Path The Path action is basically a shortcut for a commonly used Regex action. sub list : Path('products/') { my $self = shift; my($category, $id) = $self->snippets(); .... } Is basically the same thing as. sub list : Regex('^/products/(\w+)/(\d+)') { my $self = shift; my($category, $id) = $self->snippets(); ... } For those that care, the Path('products/') will be converted to the regular expression "^/products\/?(\/.*)$". Then split('/') is run on the captured value and stored in snippets(). EXAMPLE In CGI::Application module: package WebApp; use base 'CGI::Application'; use CGI::Application::Plugin::ActionDispatch; use strict; sub setup { my $self = shift; self->mode_param('test_rm'); $self->run_modes( basic_runmode => 'basic_runmode' ); } # Regular runmodes should work. sub basic_runmode { my $self = shift } The product() runmode will match anything starting with "/products" in the PATH_INFO. # http://example.com/myapp.cgi/products/this/is/optional/and/stored/in/snippets/ sub product : Path('products/') { my $self = shift; my($category, $product) = $self->snippets(); } The music() runmode will match anything starting with "/products/music" in the PATH_INFO. The product() runmode also matches "/products/music". However since this runmode matches closer it takes priority over product(). # http://example.com/myapp.cgi/products/music/product/ sub music : Path('products/music/') { my $self = shift; my $product = $self->snippets(); ... } This beatles() runmode will match ONLY "/product/music/beatles" or "/product/music/beatles/". Regex takes priority over Path so the previous runmodes which match this PATH_INFO are not run. # http://example.com/myapp.cgi/products/music/beatles/ sub beatles : Regex('^/products/music/beatles\/?') { my $self = shift; ... } SEE ALSO CGI::Application, CGI::Application::Dispatch, Attribute::Handlers AUTHOR Jason Yates, COPYRIGHT AND LICENSE Copyright (C) 2006 by Jason Yates This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.