1CGI::Application::PlugiUns:e:rAcCtoinotnrDiibsuptCaeGtdIc:hP:(eA3rp)lplDioccautmieonnt:a:tPiloungin::ActionDispatch(3)
2
3
4
6 CGI::Application::Plugin::ActionDispatch - Perl extension
7
9 # In "WebApp.pm"...
10 package WebApp;
11
12 use base 'CGI::Application';
13 use CGI::Application::Plugin::ActionDispatch;
14
15 sub do_stuff : Path('do/stuff') { ... }
16 sub do_more_stuff : Regex('^/do/more/stuff\/?$') { ... }
17 sub do_something_else : Regex('do/something/else/(\w+)/(\d+)$') { ... }
18
20 CGI::Application::Plugin::ActionDispatch adds attribute based support
21 for parsing the PATH_INFO of the incoming request. For those who are
22 familiar with Catalyst. The interface works very similar.
23
24 This plugin is plug and play and shouldn't interrupt the default
25 behavior of CGI::Application.
26
28 Be aware though, this plugin will not likely work with other modules
29 that use attributes.
30
31 This module should work with mod_perl. It however has not be thoroughly
32 tested as such. If you have used it with mod_perl please e-mail me with
33 your experience.
34
36 action_args()
37 If using capturing parentheses in a Regex action. The captured
38 values are accessible using this method.
39
40 sub addElement : Regex('add/(\d+)/(\d+)') {
41 my $self = shift;
42 my($column, $row) = $self->action_args();
43 ...
44 }
45
46 The Path action will store everything after the matched path into
47 the action args.
48
49 # http://example.com/state/pa/philadelphia
50 sub find_state_and_city : Path('state/') {
51 my $self = shift;
52 my($state, $city) = $self->action_args();
53 # $state == pa, $city == philadelphia
54 ...
55 }
56
58 Regex
59 Regex action is used for regular expression matching against
60 PATH_INFO. If capturing parentheses are used; the matched
61 parameters are accesssible using the action_args() method.
62
63 Regex('^blah/foo');
64
65 The Regex action either matches or it doesn't. There are no secrets
66 to it.
67
68 It is important to note Regex action takes priority. It is assumed
69 if a Path and Regex action both match. The Regex action will take
70 priority, which may not always be the outcome of least suprise, for
71 instance:
72
73 # http://example.com/music/the_clash sub clash :
74 Path('/music/the_clash') {} # This is an exact match, BUT. sub
75 the_class : Regex('/music/the_clash') {} # This takes priority.
76 Beware.
77
78 Path
79 The Path action is basically a shortcut for a commonly used Regex
80 action.
81
82 # http://example.com/products/movies/2
83 sub show_product : Path('products/') {
84 my $self = shift;
85 my($category, $id) = $self->action_args();
86 ....
87 }
88
89 Is basically the same thing as.
90
91 sub show_product : Regex('^/products/(\w+)/(\d+)') {
92 my $self = shift;
93 my($category, $id) = $self->action_args();
94 ...
95 }
96
97 For those that care, the Path('products/') will be converted to the
98 regular expression "^/products\/?(\/.*)$"; then split('/') is run
99 on the captured value and stored in action_args().
100
101 Runmode
102 This action will take the method name and run a match on that.
103
104 # http://example.com/foobar
105
106 sub foobar : Runmode {}
107
108 Default
109 The default run mode if no match is found. Essentially the
110 equivalent of the start_mode() method.
111
112 sub default_mode : Default {}
113
115 In CGI::Application module:
116
117 package WebApp;
118
119 use base 'CGI::Application';
120 use CGI::Application::Plugin::ActionDispatch;
121 use strict;
122
123 sub setup {
124 my $self = shift;
125 self->mode_param('test_rm');
126 $self->run_modes(
127 basic_runmode => 'basic_runmode'
128 );
129 }
130
131 # Regular runmodes should work.
132 sub basic_runmode {
133 my $self = shift
134 }
135
136 The product() runmode will match anything starting with "/products" in
137 the PATH_INFO.
138
139 # http://example.com/myapp.cgi/products/this/is/optional/and/stored/in/action_args/
140 sub product : Path('products/') {
141 my $self = shift;
142 my($category, $product) = $self->action_args();
143 }
144
145 The music() runmode will match anything starting with "/products/music"
146 in the PATH_INFO. The product() runmode also matches "/products/music".
147 However since this runmode matches closer it takes priority over
148 product().
149
150 # http://example.com/myapp.cgi/products/music/product/
151 sub music : Path('products/music/') {
152 my $self = shift;
153 my $product = $self->action_args();
154 ...
155 }
156
157 This beatles() runmode will match ONLY "/product/music/beatles" or
158 "/product/music/beatles/". Regex takes priority over Path so the
159 previous runmodes which match this PATH_INFO are not run.
160
161 # http://example.com/myapp.cgi/products/music/beatles/
162 sub beatles : Regex('^/products/music/beatles\/?') {
163 my $self = shift;
164 ...
165 }
166
168 CGI::Application, CGI::Application::Dispatch
169
170 http://github.com/jaywhy/cgi-application-plugin-actiondispatch
171
173 Jason Yates, <jaywhy@gmail.com>
174
176 Copyright (C) 2006-2008 by Jason Yates
177
178 This library is free software; you can redistribute it and/or modify it
179 under the same terms as Perl itself, either Perl version 5.8.7 or, at
180 your option, any later version of Perl 5 you may have available.
181
182
183
184perl v5.32.1 20C2G1I-:0:1A-p2p6lication::Plugin::ActionDispatch(3)