.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "CGI::Application::Plugin::ActionDispatch 3pm" .TH CGI::Application::Plugin::ActionDispatch 3pm "2021-01-07" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" CGI::Application::Plugin::ActionDispatch \- Perl extension .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& # In "WebApp.pm"... \& package WebApp; \& \& use base \*(AqCGI::Application\*(Aq; \& use CGI::Application::Plugin::ActionDispatch; \& \& sub do_stuff : Path(\*(Aqdo/stuff\*(Aq) { ... } \& sub do_more_stuff : Regex(\*(Aq^/do/more/stuff\e/?$\*(Aq) { ... } \& sub do_something_else : Regex(\*(Aqdo/something/else/(\ew+)/(\ed+)$\*(Aq) { ... } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" CGI::Application::Plugin::ActionDispatch adds attribute based support for parsing the \s-1PATH_INFO\s0 of the incoming request. For those who are familiar with Catalyst. The interface works very similar. .PP This plugin is plug and play and shouldn't interrupt the default behavior of CGI::Application. .SH "CAVEATS" .IX Header "CAVEATS" Be aware though, this plugin will not likely work with other modules that use attributes. .PP This module should work with mod_perl. It however has not be thoroughly tested as such. If you have used it with mod_perl please e\-mail me with your experience. .SH "METHODS" .IX Header "METHODS" .IP "\fBaction_args()\fR" 4 .IX Item "action_args()" If using capturing parentheses in a Regex action. The captured values are accessible using this method. .Sp .Vb 5 \& sub addElement : Regex(\*(Aqadd/(\ed+)/(\ed+)\*(Aq) { \& my $self = shift; \& my($column, $row) = $self\->action_args(); \& ... \& } .Ve .Sp The Path action will store everything after the matched path into the action args. .Sp .Vb 7 \& # http://example.com/state/pa/philadelphia \& sub find_state_and_city : Path(\*(Aqstate/\*(Aq) { \& my $self = shift; \& my($state, $city) = $self\->action_args(); \& # $state == pa, $city == philadelphia \& ... \& } .Ve .SH "ACTIONS" .IX Header "ACTIONS" .IP "Regex" 4 .IX Item "Regex" Regex action is used for regular expression matching against \s-1PATH_INFO.\s0 If capturing parentheses are used; the matched parameters are accesssible using the \fBaction_args()\fR method. .Sp .Vb 1 \& Regex(\*(Aq^blah/foo\*(Aq); .Ve .Sp The Regex action either matches or it doesn't. There are no secrets to it. .Sp It is important to note Regex action takes priority. It is assumed if a Path and Regex action both match. The Regex action will take priority, which may not always be the outcome of least suprise, for instance: .Sp # http://example.com/music/the_clash sub clash : Path('/music/the_clash') {} # This is an exact match, \s-1BUT.\s0 sub the_class : Regex('/music/the_clash') {} # This takes priority. Beware. .IP "Path" 4 .IX Item "Path" The Path action is basically a shortcut for a commonly used Regex action. .Sp .Vb 6 \& # http://example.com/products/movies/2 \& sub show_product : Path(\*(Aqproducts/\*(Aq) { \& my $self = shift; \& my($category, $id) = $self\->action_args(); \& .... \& } .Ve .Sp Is basically the same thing as. .Sp .Vb 5 \& sub show_product : Regex(\*(Aq^/products/(\ew+)/(\ed+)\*(Aq) { \& my $self = shift; \& my($category, $id) = $self\->action_args(); \& ... \& } .Ve .Sp For those that care, the Path('products/') will be converted to the regular expression \*(L"^/products\e/?(\e/.*)$\*(R"; then split('/') is run on the captured value and stored in \fBaction_args()\fR. .IP "Runmode" 4 .IX Item "Runmode" This action will take the method name and run a match on that. .Sp # http://example.com/foobar .Sp sub foobar : Runmode {} .IP "Default" 4 .IX Item "Default" The default run mode if no match is found. Essentially the equivalent of the \&\fBstart_mode()\fR method. .Sp sub default_mode : Default {} .SH "EXAMPLE" .IX Header "EXAMPLE" In CGI::Application module: .PP .Vb 1 \& package WebApp; \& \& use base \*(AqCGI::Application\*(Aq; \& use CGI::Application::Plugin::ActionDispatch; \& use strict; \& \& sub setup { \& my $self = shift; \& self\->mode_param(\*(Aqtest_rm\*(Aq); \& $self\->run_modes( \& basic_runmode => \*(Aqbasic_runmode\*(Aq \& ); \& } \& \& # Regular runmodes should work. \& sub basic_runmode { \& my $self = shift \& } .Ve .PP The \fBproduct()\fR runmode will match anything starting with \*(L"/products\*(R" in the \&\s-1PATH_INFO.\s0 .PP .Vb 5 \& # http://example.com/myapp.cgi/products/this/is/optional/and/stored/in/action_args/ \& sub product : Path(\*(Aqproducts/\*(Aq) { \& my $self = shift; \& my($category, $product) = $self\->action_args(); \& } .Ve .PP The \fBmusic()\fR runmode will match anything starting with \*(L"/products/music\*(R" in the \&\s-1PATH_INFO.\s0 The \fBproduct()\fR runmode also matches \*(L"/products/music\*(R". However since this runmode matches closer it takes priority over \fBproduct()\fR. .PP .Vb 6 \& # http://example.com/myapp.cgi/products/music/product/ \& sub music : Path(\*(Aqproducts/music/\*(Aq) { \& my $self = shift; \& my $product = $self\->action_args(); \& ... \& } .Ve .PP This \fBbeatles()\fR runmode will match \s-1ONLY\s0 \*(L"/product/music/beatles\*(R" or \&\*(L"/product/music/beatles/\*(R". Regex takes priority over Path so the previous runmodes which match this \s-1PATH_INFO\s0 are not run. .PP .Vb 5 \& # http://example.com/myapp.cgi/products/music/beatles/ \& sub beatles : Regex(\*(Aq^/products/music/beatles\e/?\*(Aq) { \& my $self = shift; \& ... \& } .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" CGI::Application, CGI::Application::Dispatch .PP http://github.com/jaywhy/cgi\-application\-plugin\-actiondispatch .SH "AUTHOR" .IX Header "AUTHOR" Jason Yates, .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2006\-2008 by Jason Yates .PP 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.