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