test inheritance of builtin actions in mainapp.
[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 specified 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->action
92         Accessor for the current action
93
94     $c->comp($name)
95     $c->component($name)
96         Get a component object by name.
97
98             $c->comp('MyApp::Model::MyModel')->do_stuff;
99
100     config
101         Returns a hashref containing your applications settings.
102
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
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
135     $c->setup
136         Setup.
137
138             $c->setup;
139
140     $c->uri_for($path,[@args])
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
143         object. If any args are passed, they are added at the end of the
144         path.
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
157         Clean errors.
158
159             $c->error(0);
160
161     $c->engine
162         Contains the engine instance. Stringifies to the class.
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.
173
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;
181
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
200             print $c->stash->{foo};
201
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
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
235     $c->execute($class, $coderef)
236         Execute a coderef in given class and catch exceptions. Errors are
237         available via $c->error.
238
239     $c->finalize
240         Finalize request.
241
242     $c->finalize_body
243         Finalize body.
244
245     $c->finalize_cookies
246         Finalize cookies.
247
248     $c->finalize_error
249         Finalize error.
250
251     $c->finalize_headers
252         Finalize headers.
253
254     $c->finalize_output
255         An alias for finalize_body.
256
257     $c->finalize_read
258         Finalize the input after reading is complete.
259
260     $c->finalize_uploads
261         Finalize uploads. Cleans up any temporary files.
262
263     $c->get_action( $action, $namespace, $inherit )
264         Get an action in a given namespace.
265
266     handle_request( $class, @arguments )
267         Handles the request.
268
269     $c->prepare(@arguments)
270         Turns the engine-specific request( Apache, CGI ... ) into a Catalyst
271         context .
272
273     $c->prepare_action
274         Prepare action.
275
276     $c->prepare_body
277         Prepare message body.
278
279     $c->prepare_body_chunk( $chunk )
280         Prepare a chunk of data before sending it to HTTP::Body.
281
282     $c->prepare_body_parameters
283         Prepare body parameters.
284
285     $c->prepare_connection
286         Prepare connection.
287
288     $c->prepare_cookies
289         Prepare cookies.
290
291     $c->prepare_headers
292         Prepare headers.
293
294     $c->prepare_parameters
295         Prepare parameters.
296
297     $c->prepare_path
298         Prepare path and base.
299
300     $c->prepare_query_parameters
301         Prepare query parameters.
302
303     $c->prepare_read
304         Prepare the input for reading.
305
306     $c->prepare_request
307         Prepare the engine request.
308
309     $c->prepare_uploads
310         Prepare uploads.
311
312     $c->prepare_write
313         Prepare the output for writing.
314
315     $c->read( [$maxlength] )
316         Read a chunk of data from the request body. This method is designed
317         to be used in a while loop, reading $maxlength bytes on every call.
318         $maxlength defaults to the size of the request if not specified.
319
320         You have to set MyApp->config->{parse_on_demand} to use this
321         directly.
322
323     $c->run
324         Starts the engine.
325
326     $c->set_action( $action, $code, $namespace, $attrs )
327         Set an action in a given namespace.
328
329     $c->setup_actions($component)
330         Setup actions for a component.
331
332     $c->setup_components
333         Setup components.
334
335     $c->setup_dispatcher
336     $c->setup_engine
337     $c->setup_home
338     $c->setup_log
339     $c->setup_plugins
340     $c->write( $data )
341         Writes $data to the output stream. When using this method directly,
342         you will need to manually set the Content-Length header to the
343         length of your output data, if known.
344
345     version
346         Returns the Catalyst version number. mostly useful for powered by
347         messages in template systems.
348
349 CASE SENSITIVITY
350     By default Catalyst is not case sensitive, so "MyApp::C::FOO::Bar"
351     becomes "/foo/bar".
352
353     But you can activate case sensitivity with a config parameter.
354
355         MyApp->config->{case_sensitive} = 1;
356
357     So "MyApp::C::Foo::Bar" becomes "/Foo/Bar".
358
359 ON-DEMAND PARSER
360     The request body is usually parsed at the beginning of a request, but if
361     you want to handle input yourself or speed things up a bit you can
362     enable on-demand parsing with a config parameter.
363
364         MyApp->config->{parse_on_demand} = 1;
365     
366 PROXY SUPPORT
367     Many production servers operate using the common double-server approach,
368     with a lightweight frontend web server passing requests to a larger
369     backend server. An application running on the backend server must deal
370     with two problems: the remote user always appears to be '127.0.0.1' and
371     the server's hostname will appear to be 'localhost' regardless of the
372     virtual host the user connected through.
373
374     Catalyst will automatically detect this situation when you are running
375     both the frontend and backend servers on the same machine. The following
376     changes are made to the request.
377
378         $c->req->address is set to the user's real IP address, as read from the
379         HTTP_X_FORWARDED_FOR header.
380     
381         The host value for $c->req->base and $c->req->uri is set to the real host,
382         as read from the HTTP_X_FORWARDED_HOST header.
383
384     Obviously, your web server must support these 2 headers for this to
385     work.
386
387     In a more complex server farm environment where you may have your
388     frontend proxy server(s) on different machines, you will need to set a
389     configuration option to tell Catalyst to read the proxied data from the
390     headers.
391
392         MyApp->config->{using_frontend_proxy} = 1;
393     
394     If you do not wish to use the proxy support at all, you may set:
395
396         MyApp->config->{ignore_frontend_proxy} = 1;
397
398 THREAD SAFETY
399     Catalyst has been tested under Apache 2's threading mpm_worker,
400     mpm_winnt, and the standalone forking HTTP server on Windows. We believe
401     the Catalyst core to be thread-safe.
402
403     If you plan to operate in a threaded environment, remember that all
404     other modules you are using must also be thread-safe. Some modules, most
405     notably DBD::SQLite, are not thread-safe.
406
407 SUPPORT
408     IRC:
409
410         Join #catalyst on irc.perl.org.
411
412     Mailing-Lists:
413
414         http://lists.rawmode.org/mailman/listinfo/catalyst
415         http://lists.rawmode.org/mailman/listinfo/catalyst-dev
416
417     Web:
418
419         http://catalyst.perl.org
420
421 SEE ALSO
422     Catalyst::Manual - The Catalyst Manual
423     Catalyst::Engine - Core Engine
424     Catalyst::Log - The Log Class.
425     Catalyst::Request - The Request Object
426     Catalyst::Response - The Response Object
427     Catalyst::Test - The test suite.
428
429 CREDITS
430     Andy Grundman
431
432     Andy Wardley
433
434     Andreas Marienborg
435
436     Andrew Bramble
437
438     Andrew Ford
439
440     Andrew Ruthven
441
442     Arthur Bergman
443
444     Autrijus Tang
445
446     Christian Hansen
447
448     Christopher Hicks
449
450     Dan Sully
451
452     Danijel Milicevic
453
454     David Naughton
455
456     Gary Ashton Jones
457
458     Geoff Richards
459
460     Jesse Sheidlower
461
462     Jesse Vincent
463
464     Jody Belka
465
466     Johan Lindstrom
467
468     Juan Camacho
469
470     Leon Brocard
471
472     Marcus Ramberg
473
474     Matt S Trout
475
476     Robert Sedlacek
477
478     Tatsuhiko Miyagawa
479
480     Ulf Edvinsson
481
482     Yuval Kogman
483
484 AUTHOR
485     Sebastian Riedel, "sri@oook.de"
486
487 LICENSE
488     This library is free software, you can redistribute it and/or modify it
489     under the same terms as Perl itself.
490