Commit | Line | Data |
fc7ec1d9 |
1 | NAME |
2 | Catalyst - The Elegant MVC Web Application Framework |
3 | |
4 | SYNOPSIS |
5 | # use the helper to start a new application |
d01df17d |
6 | catalyst.pl MyApp |
fc7ec1d9 |
7 | cd MyApp |
8 | |
9 | # add models, views, controllers |
f56990fa |
10 | script/myapp_create.pl model Something |
11 | script/myapp_create.pl view Stuff |
12 | script/myapp_create.pl controller Yada |
fc7ec1d9 |
13 | |
14 | # built in testserver |
f56990fa |
15 | script/myapp_server.pl |
fc7ec1d9 |
16 | |
17 | # command line interface |
f56990fa |
18 | script/myapp_test.pl /yada |
fc7ec1d9 |
19 | |
fc7ec1d9 |
20 | use Catalyst; |
21 | |
22 | use Catalyst qw/My::Module My::OtherModule/; |
23 | |
24 | use Catalyst '-Debug'; |
25 | |
26 | use Catalyst qw/-Debug -Engine=CGI/; |
27 | |
4be6aea7 |
28 | sub default : Private { $_[1]->res->output('Hello') } ); |
29 | |
30 | sub index : Path('/index.html') { |
31 | my ( $self, $c ) = @_; |
32 | $c->res->output('Hello'); |
6f6e1bb4 |
33 | $c->forward('foo'); |
4be6aea7 |
34 | } |
35 | |
6f6e1bb4 |
36 | sub product : Regex('^product[_]*(\d*).html$') { |
4be6aea7 |
37 | my ( $self, $c ) = @_; |
38 | $c->stash->{template} = 'product.tt'; |
39 | $c->stash->{product} = $c->req->snippets->[0]; |
40 | } |
fc7ec1d9 |
41 | |
92af75fc |
42 | See also Catalyst::Manual::Intro |
43 | |
fc7ec1d9 |
44 | DESCRIPTION |
fc7ec1d9 |
45 | The key concept of Catalyst is DRY (Don't Repeat Yourself). |
46 | |
47 | See Catalyst::Manual for more documentation. |
48 | |
4be6aea7 |
49 | Catalyst plugins can be loaded by naming them as arguments to the "use |
50 | Catalyst" statement. Omit the "Catalyst::Plugin::" prefix from the |
51 | plugin name, so "Catalyst::Plugin::My::Module" becomes "My::Module". |
fc7ec1d9 |
52 | |
53 | use Catalyst 'My::Module'; |
54 | |
01ba879f |
55 | Special flags like -Debug and -Engine can also be specified as arguments |
4be6aea7 |
56 | when Catalyst is loaded: |
fc7ec1d9 |
57 | |
58 | use Catalyst qw/-Debug My::Module/; |
59 | |
60 | The position of plugins and flags in the chain is important, because |
4be6aea7 |
61 | they are loaded in exactly the order that they appear. |
fc7ec1d9 |
62 | |
4be6aea7 |
63 | The following flags are supported: |
fc7ec1d9 |
64 | |
4be6aea7 |
65 | -Debug |
66 | enables debug output, i.e.: |
fc7ec1d9 |
67 | |
4be6aea7 |
68 | use Catalyst '-Debug'; |
69 | |
70 | this is equivalent to: |
71 | |
72 | use Catalyst; |
73 | sub debug { 1 } |
fc7ec1d9 |
74 | |
fbcc39ad |
75 | -Dispatcher |
76 | Force Catalyst to use a specific dispatcher. |
77 | |
4be6aea7 |
78 | -Engine |
79 | Force Catalyst to use a specific engine. Omit the |
80 | "Catalyst::Engine::" prefix of the engine name, i.e.: |
fc7ec1d9 |
81 | |
4be6aea7 |
82 | use Catalyst '-Engine=CGI'; |
fc7ec1d9 |
83 | |
fbcc39ad |
84 | -Home |
85 | Force Catalyst to use a specific home directory. |
86 | |
87 | -Log |
88 | Specify log level. |
89 | |
4be6aea7 |
90 | METHODS |
01ba879f |
91 | $c->action |
92 | Accessor for the current action |
93 | |
fbcc39ad |
94 | $c->comp($name) |
95 | $c->component($name) |
96 | Get a component object by name. |
97 | |
98 | $c->comp('MyApp::Model::MyModel')->do_stuff; |
fc7ec1d9 |
99 | |
4be6aea7 |
100 | config |
101 | Returns a hashref containing your applications settings. |
102 | |
fbcc39ad |
103 | debug |
104 | Overload to enable debug messages. |
105 | |
106 | $c->detach( $command [, \@arguments ] ) |
107 | Like "forward" but doesn't return. |
108 | |
109 | $c->dispatcher |
110 | Contains the dispatcher instance. Stringifies to class. |
111 | |
112 | $c->forward( $command [, \@arguments ] ) |
113 | Forward processing to a private action or a method from a class. If |
114 | you define a class without method it will default to process(). also |
115 | takes an optional arrayref containing arguments to be passed to the |
116 | new function. $c->req->args will be reset upon returning from the |
117 | function. |
118 | |
119 | $c->forward('/foo'); |
120 | $c->forward('index'); |
121 | $c->forward(qw/MyApp::Model::CDBI::Foo do_stuff/); |
122 | $c->forward('MyApp::View::TT'); |
123 | |
01ba879f |
124 | $c->namespace |
125 | Accessor to the namespace of the current action |
126 | |
127 | $c->path_to(@path) |
128 | Merges @path with $c->config->{home} and returns a Path::Class |
129 | object. |
130 | |
131 | For example: |
132 | |
133 | $c->path_to( 'db', 'sqlite.db' ); |
134 | |
fbcc39ad |
135 | $c->setup |
136 | Setup. |
137 | |
138 | $c->setup; |
139 | |
01ba879f |
140 | $c->uri_for($path,[@args]) |
fbcc39ad |
141 | Merges path with $c->request->base for absolute uri's and with |
142 | $c->request->match for relative uri's, then returns a normalized URI |
01ba879f |
143 | object. If any args are passed, they are added at the end of the |
144 | path. |
fbcc39ad |
145 | |
146 | $c->error |
147 | $c->error($error, ...) |
148 | $c->error($arrayref) |
149 | Returns an arrayref containing error messages. |
150 | |
151 | my @error = @{ $c->error }; |
152 | |
153 | Add a new error. |
154 | |
155 | $c->error('Something bad happened'); |
156 | |
01ba879f |
157 | Clean errors. |
158 | |
159 | $c->error(0); |
160 | |
4be6aea7 |
161 | $c->engine |
fbcc39ad |
162 | Contains the engine instance. Stringifies to the class. |
4be6aea7 |
163 | |
164 | $c->log |
165 | Contains the logging object. Unless it is already set Catalyst sets |
166 | this up with a "Catalyst::Log" object. To use your own log class: |
167 | |
168 | $c->log( MyLogger->new ); |
169 | $c->log->info("now logging with my own logger!"); |
170 | |
171 | Your log class should implement the methods described in the |
172 | "Catalyst::Log" man page. |
fc7ec1d9 |
173 | |
6f6e1bb4 |
174 | $c->plugin( $name, $class, @args ) |
175 | Instant plugins for Catalyst. Classdata accessor/mutator will be |
176 | created, class loaded and instantiated. |
177 | |
178 | MyApp->plugin( 'prototype', 'HTML::Prototype' ); |
179 | |
180 | $c->prototype->define_javascript_functions; |
d1a31ac6 |
181 | |
fbcc39ad |
182 | $c->request |
183 | $c->req |
184 | Returns a "Catalyst::Request" object. |
185 | |
186 | my $req = $c->req; |
187 | |
188 | $c->response |
189 | $c->res |
190 | Returns a "Catalyst::Response" object. |
191 | |
192 | my $res = $c->res; |
193 | |
194 | $c->state |
195 | Contains the return value of the last executed action. |
196 | |
197 | $c->stash |
198 | Returns a hashref containing all your data. |
199 | |
fbcc39ad |
200 | print $c->stash->{foo}; |
201 | |
01ba879f |
202 | Keys may be set in the stash by assigning to the hash reference, or |
203 | by passing either a single hash reference or a list of key/value |
204 | pairs as arguments. |
205 | |
206 | For example: |
207 | |
208 | $c->stash->{foo} ||= 'yada'; |
209 | $c->stash( { moose => 'majestic', qux => 0 } ); |
210 | $c->stash( bar => 1, gorch => 2 ); |
211 | |
212 | $c->welcome_message |
213 | Returns the Catalyst welcome HTML page. |
214 | |
fbcc39ad |
215 | INTERNAL METHODS |
216 | $c->benchmark($coderef) |
217 | Takes a coderef with arguments and returns elapsed time as float. |
218 | |
219 | my ( $elapsed, $status ) = $c->benchmark( sub { return 1 } ); |
220 | $c->log->info( sprintf "Processing took %f seconds", $elapsed ); |
221 | |
222 | $c->components |
223 | Contains the components. |
224 | |
225 | $c->counter |
226 | Returns a hashref containing coderefs and execution counts. (Needed |
227 | for deep recursion detection) |
228 | |
229 | $c->depth |
230 | Returns the actual forward depth. |
231 | |
232 | $c->dispatch |
233 | Dispatch request to actions. |
234 | |
60b53d07 |
235 | dump_these |
236 | Returns a list of 2-element array references (name, structure) pairs |
237 | that will be dumped on the error page in debug mode. |
238 | |
fbcc39ad |
239 | $c->execute($class, $coderef) |
240 | Execute a coderef in given class and catch exceptions. Errors are |
241 | available via $c->error. |
242 | |
243 | $c->finalize |
244 | Finalize request. |
245 | |
246 | $c->finalize_body |
247 | Finalize body. |
248 | |
249 | $c->finalize_cookies |
250 | Finalize cookies. |
251 | |
252 | $c->finalize_error |
253 | Finalize error. |
254 | |
255 | $c->finalize_headers |
256 | Finalize headers. |
257 | |
258 | $c->finalize_output |
259 | An alias for finalize_body. |
260 | |
261 | $c->finalize_read |
262 | Finalize the input after reading is complete. |
263 | |
264 | $c->finalize_uploads |
265 | Finalize uploads. Cleans up any temporary files. |
266 | |
60b53d07 |
267 | $c->get_action( $action, $namespace ) |
fbcc39ad |
268 | Get an action in a given namespace. |
269 | |
60b53d07 |
270 | $c->get_actions( $action, $namespace ) |
271 | Get all actions of a given name in a namespace and all base |
272 | namespaces. |
273 | |
fbcc39ad |
274 | handle_request( $class, @arguments ) |
275 | Handles the request. |
276 | |
277 | $c->prepare(@arguments) |
278 | Turns the engine-specific request( Apache, CGI ... ) into a Catalyst |
279 | context . |
280 | |
281 | $c->prepare_action |
282 | Prepare action. |
283 | |
284 | $c->prepare_body |
285 | Prepare message body. |
286 | |
01ba879f |
287 | $c->prepare_body_chunk( $chunk ) |
288 | Prepare a chunk of data before sending it to HTTP::Body. |
289 | |
fbcc39ad |
290 | $c->prepare_body_parameters |
291 | Prepare body parameters. |
292 | |
293 | $c->prepare_connection |
294 | Prepare connection. |
295 | |
296 | $c->prepare_cookies |
297 | Prepare cookies. |
298 | |
299 | $c->prepare_headers |
300 | Prepare headers. |
301 | |
302 | $c->prepare_parameters |
303 | Prepare parameters. |
304 | |
305 | $c->prepare_path |
306 | Prepare path and base. |
307 | |
308 | $c->prepare_query_parameters |
309 | Prepare query parameters. |
310 | |
311 | $c->prepare_read |
312 | Prepare the input for reading. |
313 | |
314 | $c->prepare_request |
315 | Prepare the engine request. |
316 | |
317 | $c->prepare_uploads |
318 | Prepare uploads. |
319 | |
320 | $c->prepare_write |
321 | Prepare the output for writing. |
322 | |
323 | $c->read( [$maxlength] ) |
324 | Read a chunk of data from the request body. This method is designed |
325 | to be used in a while loop, reading $maxlength bytes on every call. |
326 | $maxlength defaults to the size of the request if not specified. |
327 | |
328 | You have to set MyApp->config->{parse_on_demand} to use this |
329 | directly. |
330 | |
331 | $c->run |
332 | Starts the engine. |
333 | |
334 | $c->set_action( $action, $code, $namespace, $attrs ) |
335 | Set an action in a given namespace. |
336 | |
337 | $c->setup_actions($component) |
338 | Setup actions for a component. |
339 | |
340 | $c->setup_components |
341 | Setup components. |
342 | |
343 | $c->setup_dispatcher |
344 | $c->setup_engine |
345 | $c->setup_home |
346 | $c->setup_log |
347 | $c->setup_plugins |
348 | $c->write( $data ) |
349 | Writes $data to the output stream. When using this method directly, |
350 | you will need to manually set the Content-Length header to the |
351 | length of your output data, if known. |
352 | |
01ba879f |
353 | version |
354 | Returns the Catalyst version number. mostly useful for powered by |
355 | messages in template systems. |
356 | |
60b53d07 |
357 | INTERNAL ACTIONS |
358 | Catalyst uses internal actions like "_DISPATCH", "_BEGIN", "_AUTO" |
359 | "_ACTION" and "_END", these are by default not shown in the private |
360 | action table. |
361 | |
362 | But you can deactivate this with a config parameter. |
363 | |
364 | MyApp->config->{show_internal_actions} = 1; |
365 | |
f56990fa |
366 | CASE SENSITIVITY |
367 | By default Catalyst is not case sensitive, so "MyApp::C::FOO::Bar" |
368 | becomes "/foo/bar". |
369 | |
370 | But you can activate case sensitivity with a config parameter. |
371 | |
372 | MyApp->config->{case_sensitive} = 1; |
373 | |
fbcc39ad |
374 | So "MyApp::C::Foo::Bar" becomes "/Foo/Bar". |
375 | |
376 | ON-DEMAND PARSER |
377 | The request body is usually parsed at the beginning of a request, but if |
378 | you want to handle input yourself or speed things up a bit you can |
379 | enable on-demand parsing with a config parameter. |
380 | |
381 | MyApp->config->{parse_on_demand} = 1; |
382 | |
383 | PROXY SUPPORT |
384 | Many production servers operate using the common double-server approach, |
385 | with a lightweight frontend web server passing requests to a larger |
386 | backend server. An application running on the backend server must deal |
387 | with two problems: the remote user always appears to be '127.0.0.1' and |
388 | the server's hostname will appear to be 'localhost' regardless of the |
389 | virtual host the user connected through. |
390 | |
391 | Catalyst will automatically detect this situation when you are running |
392 | both the frontend and backend servers on the same machine. The following |
393 | changes are made to the request. |
394 | |
395 | $c->req->address is set to the user's real IP address, as read from the |
396 | HTTP_X_FORWARDED_FOR header. |
397 | |
398 | The host value for $c->req->base and $c->req->uri is set to the real host, |
399 | as read from the HTTP_X_FORWARDED_HOST header. |
400 | |
401 | Obviously, your web server must support these 2 headers for this to |
402 | work. |
403 | |
404 | In a more complex server farm environment where you may have your |
405 | frontend proxy server(s) on different machines, you will need to set a |
406 | configuration option to tell Catalyst to read the proxied data from the |
407 | headers. |
408 | |
409 | MyApp->config->{using_frontend_proxy} = 1; |
410 | |
411 | If you do not wish to use the proxy support at all, you may set: |
412 | |
413 | MyApp->config->{ignore_frontend_proxy} = 1; |
414 | |
415 | THREAD SAFETY |
416 | Catalyst has been tested under Apache 2's threading mpm_worker, |
417 | mpm_winnt, and the standalone forking HTTP server on Windows. We believe |
418 | the Catalyst core to be thread-safe. |
419 | |
420 | If you plan to operate in a threaded environment, remember that all |
421 | other modules you are using must also be thread-safe. Some modules, most |
422 | notably DBD::SQLite, are not thread-safe. |
d1a31ac6 |
423 | |
92af75fc |
424 | SUPPORT |
425 | IRC: |
426 | |
427 | Join #catalyst on irc.perl.org. |
428 | |
429 | Mailing-Lists: |
430 | |
431 | http://lists.rawmode.org/mailman/listinfo/catalyst |
432 | http://lists.rawmode.org/mailman/listinfo/catalyst-dev |
4be6aea7 |
433 | |
6f6e1bb4 |
434 | Web: |
435 | |
436 | http://catalyst.perl.org |
437 | |
fc7ec1d9 |
438 | SEE ALSO |
4be6aea7 |
439 | Catalyst::Manual - The Catalyst Manual |
440 | Catalyst::Engine - Core Engine |
441 | Catalyst::Log - The Log Class. |
442 | Catalyst::Request - The Request Object |
443 | Catalyst::Response - The Response Object |
444 | Catalyst::Test - The test suite. |
fc7ec1d9 |
445 | |
4e449be9 |
446 | CREDITS |
447 | Andy Grundman |
448 | |
fbcc39ad |
449 | Andy Wardley |
450 | |
01ba879f |
451 | Andreas Marienborg |
452 | |
453 | Andrew Bramble |
454 | |
4e449be9 |
455 | Andrew Ford |
456 | |
457 | Andrew Ruthven |
458 | |
fbcc39ad |
459 | Arthur Bergman |
460 | |
4e449be9 |
461 | Autrijus Tang |
462 | |
463 | Christian Hansen |
464 | |
465 | Christopher Hicks |
466 | |
467 | Dan Sully |
468 | |
469 | Danijel Milicevic |
470 | |
471 | David Naughton |
472 | |
473 | Gary Ashton Jones |
474 | |
475 | Geoff Richards |
476 | |
477 | Jesse Sheidlower |
478 | |
fbcc39ad |
479 | Jesse Vincent |
480 | |
4e449be9 |
481 | Jody Belka |
482 | |
483 | Johan Lindstrom |
484 | |
485 | Juan Camacho |
486 | |
487 | Leon Brocard |
488 | |
489 | Marcus Ramberg |
490 | |
491 | Matt S Trout |
492 | |
493 | Robert Sedlacek |
494 | |
60b53d07 |
495 | Sam Vilain |
496 | |
4e449be9 |
497 | Tatsuhiko Miyagawa |
498 | |
499 | Ulf Edvinsson |
500 | |
01ba879f |
501 | Yuval Kogman |
502 | |
fc7ec1d9 |
503 | AUTHOR |
504 | Sebastian Riedel, "sri@oook.de" |
505 | |
fc7ec1d9 |
506 | LICENSE |
01ba879f |
507 | This library is free software, you can redistribute it and/or modify it |
508 | under the same terms as Perl itself. |
fc7ec1d9 |
509 | |