.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" 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 turned on, 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 .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "CGI::Application::Plugin::ActionDispatch 3pm" .TH CGI::Application::Plugin::ActionDispatch 3pm "2012-10-22" "perl v5.20.2" "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 "\fIaction_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 \fIaction_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 \fIaction_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 \&\fIstart_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 \fIproduct()\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 \fImusic()\fR runmode will match anything starting with \*(L"/products/music\*(R" in the \&\s-1PATH_INFO.\s0 The \fIproduct()\fR runmode also matches \*(L"/products/music\*(R". However since this runmode matches closer it takes priority over \fIproduct()\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 \fIbeatles()\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.