getting catalyst to build
[catagits/Catalyst-Runtime.git] / README.mkdn
1 # NAME
2
3 Catalyst - The Elegant MVC Web Application Framework
4
5 <div>
6
7     <a href="https://badge.fury.io/pl/Catalyst-Runtime"><img src="https://badge.fury.io/pl/Catalyst-Runtime.svg" alt="CPAN version" height="18"></a>
8     <a href="https://travis-ci.org/perl-catalyst/catalyst-runtime/"><img src="https://api.travis-ci.org/perl-catalyst/catalyst-runtime.png" alt="Catalyst></a>
9     <a href="http://cpants.cpanauthors.org/dist/Catalyst-Runtime"><img src="http://cpants.cpanauthors.org/dist/Catalyst-Runtime.png" alt='Kwalitee Score' /></a>
10 </div>
11
12 # SYNOPSIS
13
14 See the [Catalyst::Manual](https://metacpan.org/pod/Catalyst::Manual) distribution for comprehensive
15 documentation and tutorials.
16
17     # Building Catalyst for development
18     cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
19     cpanm --installdeps --with-develop .
20
21     # Install Catalyst::Devel for helpers and other development tools
22     # use the helper to create a new application
23     catalyst.pl MyApp
24
25     # add models, views, controllers
26     script/myapp_create.pl model MyDatabase DBIC::Schema create=static dbi:SQLite:/path/to/db
27     script/myapp_create.pl view MyTemplate TT
28     script/myapp_create.pl controller Search
29
30     # built in testserver -- use -r to restart automatically on changes
31     # --help to see all available options
32     script/myapp_server.pl
33
34     # command line testing interface
35     script/myapp_test.pl /yada
36
37     ### in lib/MyApp.pm
38     use Catalyst qw/-Debug/; # include plugins here as well
39
40     ### In lib/MyApp/Controller/Root.pm (autocreated)
41     sub foo : Chained('/') Args() { # called for /foo, /foo/1, /foo/1/2, etc.
42         my ( $self, $c, @args ) = @_; # args are qw/1 2/ for /foo/1/2
43         $c->stash->{template} = 'foo.tt'; # set the template
44         # lookup something from db -- stash vars are passed to TT
45         $c->stash->{data} =
46           $c->model('Database::Foo')->search( { country => $args[0] } );
47         if ( $c->req->params->{bar} ) { # access GET or POST parameters
48             $c->forward( 'bar' ); # process another action
49             # do something else after forward returns
50         }
51     }
52
53     # The foo.tt TT template can use the stash data from the database
54     [% WHILE (item = data.next) %]
55         [% item.foo %]
56     [% END %]
57
58     # called for /bar/of/soap, /bar/of/soap/10, etc.
59     sub bar : Chained('/') PathPart('/bar/of/soap') Args() { ... }
60
61     # called after all actions are finished
62     sub end : Action {
63         my ( $self, $c ) = @_;
64         if ( scalar @{ $c->error } ) { ... } # handle errors
65         return if $c->res->body; # already have a response
66         $c->forward( 'MyApp::View::TT' ); # render template
67     }
68
69 See [Catalyst::Manual::Intro](https://metacpan.org/pod/Catalyst::Manual::Intro) for additional information.
70
71 # DESCRIPTION
72
73 Catalyst is a modern framework for making web applications without the
74 pain usually associated with this process. This document is a reference
75 to the main Catalyst application. If you are a new user, we suggest you
76 start with [Catalyst::Manual::Tutorial](https://metacpan.org/pod/Catalyst::Manual::Tutorial) or [Catalyst::Manual::Intro](https://metacpan.org/pod/Catalyst::Manual::Intro).
77
78 See [Catalyst::Manual](https://metacpan.org/pod/Catalyst::Manual) for more documentation.
79
80 Catalyst plugins can be loaded by naming them as arguments to the "use
81 Catalyst" statement. Omit the `Catalyst::Plugin::` prefix from the
82 plugin name, i.e., `Catalyst::Plugin::My::Module` becomes
83 `My::Module`.
84
85     use Catalyst qw/My::Module/;
86
87 If your plugin starts with a name other than `Catalyst::Plugin::`, you can
88 fully qualify the name by using a unary plus:
89
90     use Catalyst qw/
91         My::Module
92         +Fully::Qualified::Plugin::Name
93     /;
94
95 Special flags like `-Debug` can also be specified as
96 arguments when Catalyst is loaded:
97
98     use Catalyst qw/-Debug My::Module/;
99
100 The position of plugins and flags in the chain is important, because
101 they are loaded in the order in which they appear.
102
103 The following flags are supported:
104
105 ## -Debug
106
107 Enables debug output. You can also force this setting from the system
108 environment with CATALYST\_DEBUG or <MYAPP>\_DEBUG. The environment
109 settings override the application, with <MYAPP>\_DEBUG having the highest
110 priority.
111
112 This sets the log level to 'debug' and enables full debug output on the
113 error screen. If you only want the latter, see [$c->debug](https://metacpan.org/pod/$c->debug).
114
115 ## -Home
116
117 Forces Catalyst to use a specific home directory, e.g.:
118
119     use Catalyst qw[-Home=/usr/mst];
120
121 This can also be done in the shell environment by setting either the
122 `CATALYST_HOME` environment variable or `MYAPP_HOME`; where `MYAPP`
123 is replaced with the uppercased name of your application, any "::" in
124 the name will be replaced with underscores, e.g. MyApp::Web should use
125 MYAPP\_WEB\_HOME. If both variables are set, the MYAPP\_HOME one will be used.
126
127 If none of these are set, Catalyst will attempt to automatically detect the
128 home directory. If you are working in a development environment, Catalyst
129 will try and find the directory containing either Makefile.PL, Build.PL,
130 dist.ini, or cpanfile. If the application has been installed into the system
131 (i.e. you have done `make install`), then Catalyst will use the path to your
132 application module, without the .pm extension (e.g., /foo/MyApp if your
133 application was installed at /foo/MyApp.pm)
134
135 ## -Log
136
137     use Catalyst '-Log=warn,fatal,error';
138
139 Specifies a comma-delimited list of log levels.
140
141 ## -Stats
142
143 Enables statistics collection and reporting.
144
145     use Catalyst qw/-Stats=1/;
146
147 You can also force this setting from the system environment with CATALYST\_STATS
148 or <MYAPP>\_STATS. The environment settings override the application, with
149 <MYAPP>\_STATS having the highest priority.
150
151 Stats are also enabled if [debugging ](#debug) is enabled.
152
153 # METHODS
154
155 ## INFORMATION ABOUT THE CURRENT REQUEST
156
157 ## $c->action
158
159 Returns a [Catalyst::Action](https://metacpan.org/pod/Catalyst::Action) object for the current action, which
160 stringifies to the action name. See [Catalyst::Action](https://metacpan.org/pod/Catalyst::Action).
161
162 ## $c->namespace
163
164 Returns the namespace of the current action, i.e., the URI prefix
165 corresponding to the controller of the current action. For example:
166
167     # in Controller::Foo::Bar
168     $c->namespace; # returns 'foo/bar';
169
170 ## $c->request
171
172 ## $c->req
173
174 Returns the current [Catalyst::Request](https://metacpan.org/pod/Catalyst::Request) object, giving access to
175 information about the current client request (including parameters,
176 cookies, HTTP headers, etc.). See [Catalyst::Request](https://metacpan.org/pod/Catalyst::Request).
177
178 ## REQUEST FLOW HANDLING
179
180 ## $c->forward( $action \[, \\@arguments \] )
181
182 ## $c->forward( $class, $method, \[, \\@arguments \] )
183
184 This is one way of calling another action (method) in the same or
185 a different controller. You can also use `$self->my_method($c, @args)`
186 in the same controller or `$c->controller('MyController')->my_method($c, @args)`
187 in a different controller.
188 The main difference is that 'forward' uses some of the Catalyst request
189 cycle overhead, including debugging, which may be useful to you. On the
190 other hand, there are some complications to using 'forward', restrictions
191 on values returned from 'forward', and it may not handle errors as you prefer.
192 Whether you use 'forward' or not is up to you; it is not considered superior to
193 the other ways to call a method.
194
195 'forward' calls  another action, by its private name. If you give a
196 class name but no method, `process()` is called. You may also optionally
197 pass arguments in an arrayref. The action will receive the arguments in
198 `@_` and `$c->req->args`. Upon returning from the function,
199 `$c->req->args` will be restored to the previous values.
200
201 Any data `return`ed from the action forwarded to, will be returned by the
202 call to forward.
203
204     my $foodata = $c->forward('/foo');
205     $c->forward('index');
206     $c->forward(qw/Model::DBIC::Foo do_stuff/);
207     $c->forward('View::TT');
208
209 Note that [forward](#c-forward-action-arguments) implies
210 an `eval { }` around the call (actually
211 [execute](#c-execute-class-coderef) does), thus rendering all
212 exceptions thrown by the called action non-fatal and pushing them onto
213 $c->error instead. If you want `die` to propagate you need to do something
214 like:
215
216     $c->forward('foo');
217     die join "\n", @{ $c->error } if @{ $c->error };
218
219 Or make sure to always return true values from your actions and write
220 your code like this:
221
222     $c->forward('foo') || return;
223
224 Another note is that `$c->forward` always returns a scalar because it
225 actually returns $c->state which operates in a scalar context.
226 Thus, something like:
227
228     return @array;
229
230 in an action that is forwarded to is going to return a scalar,
231 i.e. how many items are in that array, which is probably not what you want.
232 If you need to return an array then return a reference to it,
233 or stash it like so:
234
235     $c->stash->{array} = \@array;
236
237 and access it from the stash.
238
239 Keep in mind that the `end` method used is that of the caller action. So a `$c->detach` inside a forwarded action would run the `end` method from the original action requested.
240
241 ## $c->detach( $action \[, \\@arguments \] )
242
243 ## $c->detach( $class, $method, \[, \\@arguments \] )
244
245 ## $c->detach()
246
247 The same as [forward](#c-forward-action-arguments), but
248 doesn't return to the previous action when processing is finished.
249
250 When called with no arguments it escapes the processing chain entirely.
251
252 ## $c->visit( $action \[, \\@arguments \] )
253
254 ## $c->visit( $action \[, \\@captures, \\@arguments \] )
255
256 ## $c->visit( $class, $method, \[, \\@arguments \] )
257
258 ## $c->visit( $class, $method, \[, \\@captures, \\@arguments \] )
259
260 Almost the same as [forward](#c-forward-action-arguments),
261 but does a full dispatch, instead of just calling the new `$action` /
262 `$class->$method`. This means that `begin`, `auto` and the method
263 you go to are called, just like a new request.
264
265 In addition both `$c->action` and `$c->namespace` are localized.
266 This means, for example, that `$c->action` methods such as
267 [name](https://metacpan.org/pod/Catalyst::Action#name), [class](https://metacpan.org/pod/Catalyst::Action#class) and
268 [reverse](https://metacpan.org/pod/Catalyst::Action#reverse) return information for the visited action
269 when they are invoked within the visited action.  This is different from the
270 behavior of [forward](#c-forward-action-arguments), which
271 continues to use the $c->action object from the caller action even when
272 invoked from the called action.
273
274 `$c->stash` is kept unchanged.
275
276 In effect, [visit](#c-visit-action-captures-arguments)
277 allows you to "wrap" another action, just as it would have been called by
278 dispatching from a URL, while the analogous
279 [go](#c-go-action-captures-arguments) allows you to
280 transfer control to another action as if it had been reached directly from a URL.
281
282 ## $c->go( $action \[, \\@arguments \] )
283
284 ## $c->go( $action \[, \\@captures, \\@arguments \] )
285
286 ## $c->go( $class, $method, \[, \\@arguments \] )
287
288 ## $c->go( $class, $method, \[, \\@captures, \\@arguments \] )
289
290 The relationship between `go` and
291 [visit](#c-visit-action-captures-arguments) is the same as
292 the relationship between
293 [forward](#c-forward-class-method-arguments) and
294 [detach](#c-detach-action-arguments). Like `$c->visit`,
295 `$c->go` will perform a full dispatch on the specified action or method,
296 with localized `$c->action` and `$c->namespace`. Like `detach`,
297 `go` escapes the processing of the current request chain on completion, and
298 does not return to its cunless blessed $cunless blessed $caller.
299
300 @arguments are arguments to the final destination of $action. @captures are
301 arguments to the intermediate steps, if any, on the way to the final sub of
302 $action.
303
304 ## $c->response
305
306 ## $c->res
307
308 Returns the current [Catalyst::Response](https://metacpan.org/pod/Catalyst::Response) object, see there for details.
309
310 ## $c->stash
311
312 Returns a hashref to the stash, which may be used to store data and pass
313 it between components during a request. You can also set hash keys by
314 passing arguments. The stash is automatically sent to the view. The
315 stash is cleared at the end of a request; it cannot be used for
316 persistent storage (for this you must use a session; see
317 [Catalyst::Plugin::Session](https://metacpan.org/pod/Catalyst::Plugin::Session) for a complete system integrated with
318 Catalyst).
319
320     $c->stash->{foo} = $bar;
321     $c->stash( { moose => 'majestic', qux => 0 } );
322     $c->stash( bar => 1, gorch => 2 ); # equivalent to passing a hashref
323
324     # stash is automatically passed to the view for use in a template
325     $c->forward( 'MyApp::View::TT' );
326
327 The stash hash is currently stored in the PSGI `$env` and is managed by
328 [Catalyst::Middleware::Stash](https://metacpan.org/pod/Catalyst::Middleware::Stash).  Since it's part of the `$env` items in
329 the stash can be accessed in sub applications mounted under your main
330 [Catalyst](https://metacpan.org/pod/Catalyst) application.  For example if you delegate the response of an
331 action to another [Catalyst](https://metacpan.org/pod/Catalyst) application, that sub application will have
332 access to all the stash keys of the main one, and if can of course add
333 more keys of its own.  However those new keys will not 'bubble' back up
334 to the main application.
335
336 For more information the best thing to do is to review the test case:
337 t/middleware-stash.t in the distribution /t directory.
338
339 ## $c->error
340
341 ## $c->error($error, ...)
342
343 ## $c->error($arrayref)
344
345 Returns an arrayref containing error messages.  If Catalyst encounters an
346 error while processing a request, it stores the error in $c->error.  This
347 method should only be used to store fatal error messages.
348
349     my @error = @{ $c->error };
350
351 Add a new error.
352
353     $c->error('Something bad happened');
354
355 Calling this will always return an arrayref (if there are no errors it
356 will be an empty arrayref.
357
358 ## $c->state
359
360 Contains the return value of the last executed action.
361 Note that << $c->state >> operates in a scalar context which means that all
362 values it returns are scalar.
363
364 ## $c->clear\_errors
365
366 Clear errors.  You probably don't want to clear the errors unless you are
367 implementing a custom error screen.
368
369 This is equivalent to running
370
371     $c->error(0);
372
373 ## $c->has\_errors
374
375 Returns true if you have errors
376
377 ## $c->last\_error
378
379 Returns the most recent error in the stack (the one most recently added...)
380 or nothing if there are no errors.
381
382 ## shift\_errors
383
384 shifts the most recently added error off the error stack and returns if.  Returns
385 nothing if there are no more errors.
386
387 ## COMPONENT ACCESSORS
388
389 ## $c->controller($name)
390
391 Gets a [Catalyst::Controller](https://metacpan.org/pod/Catalyst::Controller) instance by name.
392
393     $c->controller('Foo')->do_stuff;
394
395 If the name is omitted, will return the controller for the dispatched
396 action.
397
398 If you want to search for controllers, pass in a regexp as the argument.
399
400     # find all controllers that start with Foo
401     my @foo_controllers = $c->controller(qr{^Foo});
402
403 ## $c->model($name)
404
405 Gets a [Catalyst::Model](https://metacpan.org/pod/Catalyst::Model) instance by name.
406
407     $c->model('Foo')->do_stuff;
408
409 Any extra arguments are directly passed to ACCEPT\_CONTEXT, if the model
410 defines ACCEPT\_CONTEXT.  If it does not, the args are discarded.
411
412 If the name is omitted, it will look for
413  - a model object in $c->stash->{current\_model\_instance}, then
414  - a model name in $c->stash->{current\_model}, then
415  - a config setting 'default\_model', or
416  - check if there is only one model, and return it if that's the case.
417
418 If you want to search for models, pass in a regexp as the argument.
419
420     # find all models that start with Foo
421     my @foo_models = $c->model(qr{^Foo});
422
423 ## $c->view($name)
424
425 Gets a [Catalyst::View](https://metacpan.org/pod/Catalyst::View) instance by name.
426
427     $c->view('Foo')->do_stuff;
428
429 Any extra arguments are directly passed to ACCEPT\_CONTEXT.
430
431 If the name is omitted, it will look for
432  - a view object in $c->stash->{current\_view\_instance}, then
433  - a view name in $c->stash->{current\_view}, then
434  - a config setting 'default\_view', or
435  - check if there is only one view, and return it if that's the case.
436
437 If you want to search for views, pass in a regexp as the argument.
438
439     # find all views that start with Foo
440     my @foo_views = $c->view(qr{^Foo});
441
442 ## $c->controllers
443
444 Returns the available names which can be passed to $c->controller
445
446 ## $c->models
447
448 Returns the available names which can be passed to $c->model
449
450 ## $c->views
451
452 Returns the available names which can be passed to $c->view
453
454 ## $c->comp($name)
455
456 ## $c->component($name)
457
458 Gets a component object by name. This method is not recommended,
459 unless you want to get a specific component by full
460 class. `$c->controller`, `$c->model`, and `$c->view`
461 should be used instead.
462
463 If `$name` is a regexp, a list of components matched against the full
464 component name will be returned.
465
466 If Catalyst can't find a component by name, it will fallback to regex
467 matching by default. To disable this behaviour set
468 disable\_component\_resolution\_regex\_fallback to a true value.
469
470     __PACKAGE__->config( disable_component_resolution_regex_fallback => 1 );
471
472 ## CLASS DATA AND HELPER CLASSES
473
474 ## $c->config
475
476 Returns or takes a hashref containing the application's configuration.
477
478     __PACKAGE__->config( { db => 'dsn:SQLite:foo.db' } );
479
480 You can also use a `YAML`, `XML` or [Config::General](https://metacpan.org/pod/Config::General) config file
481 like `myapp.conf` in your applications home directory. See
482 [Catalyst::Plugin::ConfigLoader](https://metacpan.org/pod/Catalyst::Plugin::ConfigLoader).
483
484 ### Cascading configuration
485
486 The config method is present on all Catalyst components, and configuration
487 will be merged when an application is started. Configuration loaded with
488 [Catalyst::Plugin::ConfigLoader](https://metacpan.org/pod/Catalyst::Plugin::ConfigLoader) takes precedence over other configuration,
489 followed by configuration in your top level `MyApp` class. These two
490 configurations are merged, and then configuration data whose hash key matches a
491 component name is merged with configuration for that component.
492
493 The configuration for a component is then passed to the `new` method when a
494 component is constructed.
495
496 For example:
497
498     MyApp->config({ 'Model::Foo' => { bar => 'baz', overrides => 'me' } });
499     MyApp::Model::Foo->config({ quux => 'frob', overrides => 'this' });
500
501 will mean that `MyApp::Model::Foo` receives the following data when
502 constructed:
503
504     MyApp::Model::Foo->new({
505         bar => 'baz',
506         quux => 'frob',
507         overrides => 'me',
508     });
509
510 It's common practice to use a Moose attribute
511 on the receiving component to access the config value.
512
513     package MyApp::Model::Foo;
514
515     use Moose;
516
517     # this attr will receive 'baz' at construction time
518     has 'bar' => (
519         is  => 'rw',
520         isa => 'Str',
521     );
522
523 You can then get the value 'baz' by calling $c->model('Foo')->bar
524 (or $self->bar inside code in the model).
525
526 **NOTE:** you MUST NOT call `$self->config` or `__PACKAGE__->config`
527 as a way of reading config within your code, as this **will not** give you the
528 correctly merged config back. You **MUST** take the config values supplied to
529 the constructor and use those instead.
530
531 ## $c->log
532
533 Returns the logging object instance. Unless it is already set, Catalyst
534 sets this up with a [Catalyst::Log](https://metacpan.org/pod/Catalyst::Log) object. To use your own log class,
535 set the logger with the `__PACKAGE__->log` method prior to calling
536 `__PACKAGE__->setup`.
537
538     __PACKAGE__->log( MyLogger->new );
539     __PACKAGE__->setup;
540
541 And later:
542
543     $c->log->info( 'Now logging with my own logger!' );
544
545 Your log class should implement the methods described in
546 [Catalyst::Log](https://metacpan.org/pod/Catalyst::Log).
547
548 ## has\_encoding
549
550 Returned True if there's a valid encoding
551
552 ## clear\_encoding
553
554 Clears the encoding for the current context
555
556 ## encoding
557
558 Sets or gets the application encoding.  Setting encoding takes either an
559 Encoding object or a string that we try to resolve via [Encode::find\_encoding](https://metacpan.org/pod/Encode::find_encoding).
560
561 You would expect to get the encoding object back if you attempt to set it.  If
562 there is a failure you will get undef returned and an error message in the log.
563
564 ## $c->debug
565
566 Returns 1 if debug mode is enabled, 0 otherwise.
567
568 You can enable debug mode in several ways:
569
570 - By calling myapp\_server.pl with the -d flag
571 - With the environment variables MYAPP\_DEBUG, or CATALYST\_DEBUG
572 - The -Debug option in your MyApp.pm
573 - By declaring `sub debug { 1 }` in your MyApp.pm.
574
575 The first three also set the log level to 'debug'.
576
577 Calling `$c->debug(1)` has no effect.
578
579 ## $c->dispatcher
580
581 Returns the dispatcher instance. See [Catalyst::Dispatcher](https://metacpan.org/pod/Catalyst::Dispatcher).
582
583 ## $c->engine
584
585 Returns the engine instance. See [Catalyst::Engine](https://metacpan.org/pod/Catalyst::Engine).
586
587 ## UTILITY METHODS
588
589 ## $c->path\_to(@path)
590
591 Merges `@path` with `$c->config->{home}` and returns a
592 [Path::Class::Dir](https://metacpan.org/pod/Path::Class::Dir) object. Note you can usually use this object as
593 a filename, but sometimes you will have to explicitly stringify it
594 yourself by calling the `->stringify` method.
595
596 For example:
597
598     $c->path_to( 'db', 'sqlite.db' );
599
600 ## MyApp->setup
601
602 Initializes the dispatcher and engine, loads any plugins, and loads the
603 model, view, and controller components. You may also specify an array
604 of plugins to load here, if you choose to not load them in the `use
605 Catalyst` line.
606
607     MyApp->setup;
608     MyApp->setup( qw/-Debug/ );
609
610 **Note:** You **should not** wrap this method with method modifiers
611 or bad things will happen - wrap the `setup_finalize` method instead.
612
613 **Note:** You can create a custom setup stage that will execute when the
614 application is starting.  Use this to customize setup.
615
616     MyApp->setup(-Custom=value);
617
618     sub setup_custom {
619       my ($class, $value) = @_;
620     }
621
622 Can be handy if you want to hook into the setup phase.
623
624 ## $app->setup\_finalize
625
626 A hook to attach modifiers to. This method does not do anything except set the
627 `setup_finished` accessor.
628
629 Applying method modifiers to the `setup` method doesn't work, because of quirky things done for plugin setup.
630
631 Example:
632
633     after setup_finalize => sub {
634         my $app = shift;
635
636         ## do stuff here..
637     };
638
639 ## $c->uri\_for( $path?, @args?, \\%query\_values? )
640
641 ## $c->uri\_for( $action, \\@captures?, @args?, \\%query\_values? )
642
643 ## $c->uri\_for( $action, \[@captures, @args\], \\%query\_values? )
644
645 Constructs an absolute [URI](https://metacpan.org/pod/URI) object based on the application root, the
646 provided path, and the additional arguments and query parameters provided.
647 When used as a string, provides a textual URI.  If you need more flexibility
648 than this (i.e. the option to provide relative URIs etc.) see
649 [Catalyst::Plugin::SmartURI](https://metacpan.org/pod/Catalyst::Plugin::SmartURI).
650
651 If no arguments are provided, the URI for the current action is returned.
652 To return the current action and also provide @args, use
653 `$c->uri_for( $c->action, @args )`.
654
655 If the first argument is a string, it is taken as a public URI path relative
656 to `$c->namespace` (if it doesn't begin with a forward slash) or
657 relative to the application root (if it does). It is then merged with
658 `$c->request->base`; any `@args` are appended as additional path
659 components; and any `%query_values` are appended as `?foo=bar` parameters.
660
661 If the first argument is a [Catalyst::Action](https://metacpan.org/pod/Catalyst::Action) it represents an action which
662 will have its path resolved using `$c->dispatcher->uri_for_action`. The
663 optional `\@captures` argument (an arrayref) allows passing the captured
664 variables that are needed to fill in the paths of Chained and Regex actions;
665 once the path is resolved, `uri_for` continues as though a path was
666 provided, appending any arguments or parameters and creating an absolute
667 URI.
668
669 The captures for the current request can be found in
670 `$c->request->captures`, and actions can be resolved using
671 `Catalyst::Controller->action_for($name)`. If you have a private action
672 path, use `$c->uri_for_action` instead.
673
674     # Equivalent to $c->req->uri
675     $c->uri_for($c->action, $c->req->captures,
676         @{ $c->req->args }, $c->req->params);
677
678     # For the Foo action in the Bar controller
679     $c->uri_for($c->controller('Bar')->action_for('Foo'));
680
681     # Path to a static resource
682     $c->uri_for('/static/images/logo.png');
683
684 In general the scheme of the generated URI object will follow the incoming request
685 however if your targeted action or action chain has the Scheme attribute it will
686 use that instead.
687
688 Also, if the targeted Action or Action chain declares Args/CaptureArgs that have
689 type constraints, we will require that your proposed URL verify on those declared
690 constraints.
691
692 ## $c->uri\_for\_action( $path, \\@captures\_and\_args?, @args?, \\%query\_values? )
693
694 ## $c->uri\_for\_action( $action, \\@captures\_and\_args?, @args?, \\%query\_values? )
695
696 - $path
697
698     A private path to the Catalyst action you want to create a URI for.
699
700     This is a shortcut for calling `$c->dispatcher->get_action_by_path($path)` and passing the resulting `$action` and the remaining arguments to `$c->uri_for`.
701
702     You can also pass in a Catalyst::Action object, in which case it is passed to
703     `$c->uri_for`.
704
705     Note that although the path looks like a URI that dispatches to the wanted action, it is not a URI, but an internal path to that action.
706
707     For example, if the action looks like:
708
709         package MyApp::Controller::Users;
710
711         sub lst : Path('the-list') {}
712
713     You can use:
714
715         $c->uri_for_action('/users/lst')
716
717     and it will create the URI /users/the-list.
718
719 - \\@captures\_and\_args?
720
721     Optional array reference of Captures (i.e. `<CaptureArgs or $c-`req->captures>)
722     and arguments to the request. Usually used with [Catalyst::DispatchType::Chained](https://metacpan.org/pod/Catalyst::DispatchType::Chained)
723     to interpolate all the parameters in the URI.
724
725 - @args?
726
727     Optional list of extra arguments - can be supplied in the
728     `\@captures_and_args?` array ref, or here - whichever is easier for your
729     code.
730
731     Your action can have zero, a fixed or a variable number of args (e.g.
732     `Args(1)` for a fixed number or `Args()` for a variable number)..
733
734 - \\%query\_values?
735
736     Optional array reference of query parameters to append. E.g.
737
738         { foo => 'bar' }
739
740     will generate
741
742         /rest/of/your/uri?foo=bar
743
744 ## $c->welcome\_message
745
746 Returns the Catalyst welcome HTML page.
747
748 ## run\_options
749
750 Contains a hash of options passed from the application script, including
751 the original ARGV the script received, the processed values from that
752 ARGV and any extra arguments to the script which were not processed.
753
754 This can be used to add custom options to your application's scripts
755 and setup your application differently depending on the values of these
756 options.
757
758 # INTERNAL METHODS
759
760 These methods are not meant to be used by end users.
761
762 ## $c->components
763
764 Returns a hash of components.
765
766 ## $c->context\_class
767
768 Returns or sets the context class.
769
770 ## $c->counter
771
772 Returns a hashref containing coderefs and execution counts (needed for
773 deep recursion detection).
774
775 ## $c->depth
776
777 Returns the number of actions on the current internal execution stack.
778
779 ## $c->dispatch
780
781 Dispatches a request to actions.
782
783 ## $c->dispatcher\_class
784
785 Returns or sets the dispatcher class.
786
787 ## $c->dump\_these
788
789 Returns a list of 2-element array references (name, structure) pairs
790 that will be dumped on the error page in debug mode.
791
792 ## $c->engine\_class
793
794 Returns or sets the engine class.
795
796 ## $c->execute( $class, $coderef )
797
798 Execute a coderef in given class and catch exceptions. Errors are available
799 via $c->error.
800
801 ## $c->finalize
802
803 Finalizes the request.
804
805 ## $c->finalize\_body
806
807 Finalizes body.
808
809 ## $c->finalize\_cookies
810
811 Finalizes cookies.
812
813 ## $c->finalize\_error
814
815 Finalizes error.  If there is only one error in ["error"](#error) and it is an object that
816 does `as_psgi` or `code` we rethrow the error and presume it caught by middleware
817 up the ladder.  Otherwise we return the debugging error page (in debug mode) or we
818 return the default error page (production mode).
819
820 ## $c->finalize\_headers
821
822 Finalizes headers.
823
824 ## $c->finalize\_encoding
825
826 Make sure your body is encoded properly IF you set an encoding.  By
827 default the encoding is UTF-8 but you can disable it by explicitly setting the
828 encoding configuration value to undef.
829
830 We can only encode when the body is a scalar.  Methods for encoding via the
831 streaming interfaces (such as `write` and `write_fh` on [Catalyst::Response](https://metacpan.org/pod/Catalyst::Response)
832 are available).
833
834 See ["ENCODING"](#encoding).
835
836 ## $c->finalize\_output
837
838 An alias for finalize\_body.
839
840 ## $c->finalize\_read
841
842 Finalizes the input after reading is complete.
843
844 ## $c->finalize\_uploads
845
846 Finalizes uploads. Cleans up any temporary files.
847
848 ## $c->get\_action( $action, $namespace )
849
850 Gets an action in a given namespace.
851
852 ## $c->get\_actions( $action, $namespace )
853
854 Gets all actions of a given name in a namespace and all parent
855 namespaces.
856
857 ## $app->handle\_request( @arguments )
858
859 Called to handle each HTTP request.
860
861 ## $class->prepare( @arguments )
862
863 Creates a Catalyst context from an engine-specific request (Apache, CGI,
864 etc.).
865
866 ## $c->prepare\_action
867
868 Prepares action. See [Catalyst::Dispatcher](https://metacpan.org/pod/Catalyst::Dispatcher).
869
870 ## $c->prepare\_body
871
872 Prepares message body.
873
874 ## $c->prepare\_body\_chunk( $chunk )
875
876 Prepares a chunk of data before sending it to [HTTP::Body](https://metacpan.org/pod/HTTP::Body).
877
878 See [Catalyst::Engine](https://metacpan.org/pod/Catalyst::Engine).
879
880 ## $c->prepare\_body\_parameters
881
882 Prepares body parameters.
883
884 ## $c->prepare\_connection
885
886 Prepares connection.
887
888 ## $c->prepare\_cookies
889
890 Prepares cookies by ensuring that the attribute on the request
891 object has been built.
892
893 ## $c->prepare\_headers
894
895 Prepares request headers by ensuring that the attribute on the request
896 object has been built.
897
898 ## $c->prepare\_parameters
899
900 Prepares parameters.
901
902 ## $c->prepare\_path
903
904 Prepares path and base.
905
906 ## $c->prepare\_query\_parameters
907
908 Prepares query parameters.
909
910 ## $c->log\_request
911
912 Writes information about the request to the debug logs.  This includes:
913
914 - Request method, path, and remote IP address
915 - Query keywords (see ["query\_keywords" in Catalyst::Request](https://metacpan.org/pod/Catalyst::Request#query_keywords))
916 - Request parameters
917 - File uploads
918
919 ## $c->log\_response
920
921 Writes information about the response to the debug logs by calling
922 `$c->log_response_status_line` and `$c->log_response_headers`.
923
924 ## $c->log\_response\_status\_line($response)
925
926 Writes one line of information about the response to the debug logs.  This includes:
927
928 - Response status code
929 - Content-Type header (if present)
930 - Content-Length header (if present)
931
932 ## $c->log\_response\_headers($headers);
933
934 Hook method which can be wrapped by plugins to log the response headers.
935 No-op in the default implementation.
936
937 ## $c->log\_request\_parameters( query => {}, body => {} )
938
939 Logs request parameters to debug logs
940
941 ## $c->log\_request\_uploads
942
943 Logs file uploads included in the request to the debug logs.
944 The parameter name, filename, file type, and file size are all included in
945 the debug logs.
946
947 ## $c->log\_request\_headers($headers);
948
949 Hook method which can be wrapped by plugins to log the request headers.
950 No-op in the default implementation.
951
952 ## $c->log\_headers($type => $headers)
953
954 Logs [HTTP::Headers](https://metacpan.org/pod/HTTP::Headers) (either request or response) to the debug logs.
955
956 ## $c->prepare\_read
957
958 Prepares the input for reading.
959
960 ## $c->prepare\_request
961
962 Prepares the engine request.
963
964 ## $c->prepare\_uploads
965
966 Prepares uploads.
967
968 ## $c->prepare\_write
969
970 Prepares the output for writing.
971
972 ## $c->request\_class
973
974 Returns or sets the request class. Defaults to [Catalyst::Request](https://metacpan.org/pod/Catalyst::Request).
975
976 ## $app->request\_class\_traits
977
978 An arrayref of [Moose::Role](https://metacpan.org/pod/Moose::Role)s which are applied to the request class.  
979
980 ## $app->composed\_request\_class
981
982 This is the request class which has been composed with any request\_class\_traits.
983
984 ## $c->response\_class
985
986 Returns or sets the response class. Defaults to [Catalyst::Response](https://metacpan.org/pod/Catalyst::Response).
987
988 ## $app->response\_class\_traits
989
990 An arrayref of [Moose::Role](https://metacpan.org/pod/Moose::Role)s which are applied to the response class.
991
992 ## $app->composed\_response\_class
993
994 This is the request class which has been composed with any response\_class\_traits.
995
996 ## $c->read( \[$maxlength\] )
997
998 Reads a chunk of data from the request body. This method is designed to
999 be used in a while loop, reading `$maxlength` bytes on every call.
1000 `$maxlength` defaults to the size of the request if not specified.
1001
1002 You have to set `MyApp->config(parse_on_demand => 1)` to use this
1003 directly.
1004
1005 Warning: If you use read(), Catalyst will not process the body,
1006 so you will not be able to access POST parameters or file uploads via
1007 $c->request.  You must handle all body parsing yourself.
1008
1009 ## $c->run
1010
1011 Starts the engine.
1012
1013 ## $c->set\_action( $action, $code, $namespace, $attrs )
1014
1015 Sets an action in a given namespace.
1016
1017 ## $c->setup\_actions($component)
1018
1019 Sets up actions for a component.
1020
1021 ## $c->setup\_components
1022
1023 This method is called internally to set up the application's components.
1024
1025 It finds modules by calling the [locate\_components](https://metacpan.org/pod/locate_components) method, expands them to
1026 package names with the [expand\_component\_module](https://metacpan.org/pod/expand_component_module) method, and then installs
1027 each component into the application.
1028
1029 The `setup_components` config option is passed to both of the above methods.
1030
1031 Installation of each component is performed by the [setup\_component](https://metacpan.org/pod/setup_component) method,
1032 below.
1033
1034 ## $app->setup\_injected\_components
1035
1036 Called by setup\_compoents to setup components that are injected.
1037
1038 ## $app->setup\_injected\_component( $injected\_component\_name, $config )
1039
1040 Setup a given injected component.
1041
1042 ## $app->inject\_component($MyApp\_Component\_name => \\%args);
1043
1044 Add a component that is injected at setup:
1045
1046     MyApp->inject_component( 'Model::Foo' => { from_component => 'Common::Foo' } );
1047
1048 Must be called before ->setup.  Expects a component name for your
1049 current application and \\%args where
1050
1051 - from\_component
1052
1053     The target component being injected into your application
1054
1055 - roles
1056
1057     An arrayref of [Moose::Role](https://metacpan.org/pod/Moose::Role)s that are applied to your component.
1058
1059 Example
1060
1061     MyApp->inject_component(
1062       'Model::Foo' => {
1063         from_component => 'Common::Model::Foo',
1064         roles => ['Role1', 'Role2'],
1065       });
1066
1067 ## $app->inject\_components
1068
1069 Inject a list of components:
1070
1071     MyApp->inject_components(
1072       'Model::FooOne' => {
1073         from_component => 'Common::Model::Foo',
1074         roles => ['Role1', 'Role2'],
1075       },
1076       'Model::FooTwo' => {
1077         from_component => 'Common::Model::Foo',
1078         roles => ['Role1', 'Role2'],
1079       });
1080
1081 ## $c->locate\_components( $setup\_component\_config )
1082
1083 This method is meant to provide a list of component modules that should be
1084 setup for the application.  By default, it will use [Module::Pluggable](https://metacpan.org/pod/Module::Pluggable).
1085
1086 Specify a `setup_components` config option to pass additional options directly
1087 to [Module::Pluggable](https://metacpan.org/pod/Module::Pluggable). To add additional search paths, specify a key named
1088 `search_extra` as an array reference. Items in the array beginning with `::`
1089 will have the application class name prepended to them.
1090
1091 ## $c->expand\_component\_module( $component, $setup\_component\_config )
1092
1093 Components found by `locate_components` will be passed to this method, which
1094 is expected to return a list of component (package) names to be set up.
1095
1096 ## $app->delayed\_setup\_component
1097
1098 Returns a coderef that points to a setup\_component instance.  Used
1099 internally for when you want to delay setup until the first time
1100 the component is called.
1101
1102 ## $c->setup\_component
1103
1104 ## $app->config\_for( $component\_name )
1105
1106 Return the application level configuration (which is not yet merged with any
1107 local component configuration, via $component\_class->config) for the named
1108 component or component object. Example:
1109
1110     MyApp->config(
1111       'Model::Foo' => { a => 1, b => 2},
1112     );
1113
1114     my $config = MyApp->config_for('MyApp::Model::Foo');
1115
1116 In this case $config is the hashref ` {a=`1, b=>2} >.
1117
1118 This is also handy for looking up configuration for a plugin, to make sure you follow
1119 existing [Catalyst](https://metacpan.org/pod/Catalyst) standards for where a plugin should put its configuration.
1120
1121 ## $c->setup\_dispatcher
1122
1123 Sets up dispatcher.
1124
1125 ## $c->setup\_engine
1126
1127 Sets up engine.
1128
1129 ## $c->apply\_default\_middlewares
1130
1131 Adds the following [Plack](https://metacpan.org/pod/Plack) middlewares to your application, since they are
1132 useful and commonly needed:
1133
1134 [Plack::Middleware::LighttpdScriptNameFix](https://metacpan.org/pod/Plack::Middleware::LighttpdScriptNameFix) (if you are using Lighttpd),
1135 [Plack::Middleware::IIS6ScriptNameFix](https://metacpan.org/pod/Plack::Middleware::IIS6ScriptNameFix) (always applied since this middleware
1136 is smart enough to conditionally apply itself).
1137
1138 We will also automatically add [Plack::Middleware::ReverseProxy](https://metacpan.org/pod/Plack::Middleware::ReverseProxy) if we notice
1139 that your HTTP $env variable `REMOTE_ADDR` is '127.0.0.1'.  This is usually
1140 an indication that your server is running behind a proxy frontend.  However in
1141 2014 this is often not the case.  We preserve this code for backwards compatibility
1142 however I **highly** recommend that if you are running the server behind a front
1143 end proxy that you clearly indicate so with the `using_frontend_proxy` configuration
1144 setting to true for your environment configurations that run behind a proxy.  This
1145 way if you change your front end proxy address someday your code would inexplicably
1146 stop working as expected.
1147
1148 Additionally if we detect we are using Nginx, we add a bit of custom middleware
1149 to solve some problems with the way that server handles $ENV{PATH\_INFO} and
1150 $ENV{SCRIPT\_NAME}.
1151
1152 Please **NOTE** that if you do use `using_frontend_proxy` the middleware is now
1153 adding via `registered_middleware` rather than this method.
1154
1155 If you are using Lighttpd or IIS6 you may wish to apply these middlewares.  In
1156 general this is no longer a common case but we have this here for backward
1157 compatibility.
1158
1159 ## App->psgi\_app
1160
1161 ## App->to\_app
1162
1163 Returns a PSGI application code reference for the catalyst application
1164 `$c`. This is the bare application created without the `apply_default_middlewares`
1165 method called.  We do however apply `registered_middleware` since those are
1166 integral to how [Catalyst](https://metacpan.org/pod/Catalyst) functions.  Also, unlike starting your application
1167 with a generated server script (via [Catalyst::Devel](https://metacpan.org/pod/Catalyst::Devel) and `catalyst.pl`) we do
1168 not attempt to return a valid [PSGI](https://metacpan.org/pod/PSGI) application using any existing `${myapp}.psgi`
1169 scripts in your $HOME directory.
1170
1171 **NOTE** `apply_default_middlewares` was originally created when the first PSGI
1172 port was done for v5.90000.  These are middlewares that are added to achieve
1173 backward compatibility with older applications.  If you start your application
1174 using one of the supplied server scripts (generated with [Catalyst::Devel](https://metacpan.org/pod/Catalyst::Devel) and
1175 the project skeleton script `catalyst.pl`) we apply `apply_default_middlewares`
1176 automatically.  This was done so that pre and post PSGI port applications would
1177 work the same way.
1178
1179 This is what you want to be using to retrieve the PSGI application code
1180 reference of your Catalyst application for use in a custom `.psgi` or in your
1181 own created server modules.
1182
1183 ## $c->setup\_home
1184
1185 Sets up the home directory.
1186
1187 ## $c->setup\_encoding
1188
1189 Sets up the input/output encoding. See [ENCODING](https://metacpan.org/pod/ENCODING)
1190
1191 ## handle\_unicode\_encoding\_exception
1192
1193 Hook to let you customize how encoding errors are handled.  By default
1194 we just throw an exception.  Receives a hashref of debug information.
1195 Example:
1196
1197     $c->handle_unicode_encoding_exception({
1198         param_value => $value,
1199         error_msg => $_,
1200             encoding_step => 'params',
1201         });
1202
1203 ## $c->setup\_log
1204
1205 Sets up log by instantiating a [Catalyst::Log](https://metacpan.org/pod/Catalyst::Log) object and
1206 passing it to `log()`. Pass in a comma-delimited list of levels to set the
1207 log to.
1208
1209 This method also installs a `debug` method that returns a true value into the
1210 catalyst subclass if the "debug" level is passed in the comma-delimited list,
1211 or if the `$CATALYST_DEBUG` environment variable is set to a true value.
1212
1213 Note that if the log has already been setup, by either a previous call to
1214 `setup_log` or by a call such as `__PACKAGE__->log( MyLogger->new )`,
1215 that this method won't actually set up the log object.
1216
1217 ## $c->setup\_plugins
1218
1219 Sets up plugins.
1220
1221 ## $c->setup\_stats
1222
1223 Sets up timing statistics class.
1224
1225 ## $c->registered\_plugins
1226
1227 Returns a sorted list of the plugins which have either been stated in the
1228 import list.
1229
1230 If passed a given plugin name, it will report a boolean value indicating
1231 whether or not that plugin is loaded.  A fully qualified name is required if
1232 the plugin name does not begin with `Catalyst::Plugin::`.
1233
1234     if ($c->registered_plugins('Some::Plugin')) {
1235         ...
1236     }
1237
1238 ## default\_middleware
1239
1240 Returns a list of instantiated PSGI middleware objects which is the default
1241 middleware that is active for this application (taking any configuration
1242 options into account, excluding your custom added middleware via the `psgi_middleware`
1243 configuration option).  You can override this method if you wish to change
1244 the default middleware (although do so at risk since some middleware is vital
1245 to application function.)
1246
1247 The current default middleware list is:
1248
1249       Catalyst::Middleware::Stash
1250       Plack::Middleware::HTTPExceptions
1251       Plack::Middleware::RemoveRedundantBody
1252       Plack::Middleware::FixMissingBodyInRedirect
1253       Plack::Middleware::ContentLength
1254       Plack::Middleware::MethodOverride
1255       Plack::Middleware::Head
1256
1257 If the configuration setting `using_frontend_proxy` is true we add:
1258
1259       Plack::Middleware::ReverseProxy
1260
1261 If the configuration setting `using_frontend_proxy_path` is true we add:
1262
1263       Plack::Middleware::ReverseProxyPath
1264
1265 But **NOTE** that [Plack::Middleware::ReverseProxyPath](https://metacpan.org/pod/Plack::Middleware::ReverseProxyPath) is not a dependency of the
1266 [Catalyst](https://metacpan.org/pod/Catalyst) distribution so if you want to use this option you should add it to
1267 your project distribution file.
1268
1269 These middlewares will be added at ["setup\_middleware"](#setup_middleware) during the
1270 ["setup"](#setup) phase of application startup.
1271
1272 ## registered\_middlewares
1273
1274 Read only accessor that returns an array of all the middleware in the order
1275 that they were added (which is the REVERSE of the order they will be applied).
1276
1277 The values returned will be either instances of [Plack::Middleware](https://metacpan.org/pod/Plack::Middleware) or of a
1278 compatible interface, or a coderef, which is assumed to be inlined middleware
1279
1280 ## setup\_middleware (?@middleware)
1281
1282 Read configuration information stored in configuration key `psgi_middleware` or
1283 from passed @args.
1284
1285 See under ["CONFIGURATION"](#configuration) information regarding `psgi_middleware` and how
1286 to use it to enable [Plack::Middleware](https://metacpan.org/pod/Plack::Middleware)
1287
1288 This method is automatically called during 'setup' of your application, so
1289 you really don't need to invoke it.  However you may do so if you find the idea
1290 of loading middleware via configuration weird :).  For example:
1291
1292     package MyApp;
1293
1294     use Catalyst;
1295
1296     __PACKAGE__->setup_middleware('Head');
1297     __PACKAGE__->setup;
1298
1299 When we read middleware definitions from configuration, we reverse the list
1300 which sounds odd but is likely how you expect it to work if you have prior
1301 experience with [Plack::Builder](https://metacpan.org/pod/Plack::Builder) or if you previously used the plugin
1302 [Catalyst::Plugin::EnableMiddleware](https://metacpan.org/pod/Catalyst::Plugin::EnableMiddleware) (which is now considered deprecated)
1303
1304 So basically your middleware handles an incoming request from the first
1305 registered middleware, down and handles the response from the last middleware
1306 up.
1307
1308 ## registered\_data\_handlers
1309
1310 A read only copy of registered Data Handlers returned as a Hash, where each key
1311 is a content type and each value is a subref that attempts to decode that content
1312 type.
1313
1314 ## setup\_data\_handlers (?@data\_handler)
1315
1316 Read configuration information stored in configuration key `data_handlers` or
1317 from passed @args.
1318
1319 See under ["CONFIGURATION"](#configuration) information regarding `data_handlers`.
1320
1321 This method is automatically called during 'setup' of your application, so
1322 you really don't need to invoke it.
1323
1324 ## default\_data\_handlers
1325
1326 Default Data Handlers that come bundled with [Catalyst](https://metacpan.org/pod/Catalyst).  Currently there are
1327 only two default data handlers, for 'application/json' and an alternative to
1328 'application/x-www-form-urlencoded' which supposed nested form parameters via
1329 [CGI::Struct](https://metacpan.org/pod/CGI::Struct) or via [CGI::Struct::XS](https://metacpan.org/pod/CGI::Struct::XS) IF you've installed it.
1330
1331 The 'application/json' data handler is used to parse incoming JSON into a Perl
1332 data structure.  It used either [JSON::MaybeXS](https://metacpan.org/pod/JSON::MaybeXS) or [JSON](https://metacpan.org/pod/JSON), depending on which
1333 is installed.  This allows you to fail back to [JSON:PP](JSON:PP), which is a Pure Perl
1334 JSON decoder, and has the smallest dependency impact.
1335
1336 Because we don't wish to add more dependencies to [Catalyst](https://metacpan.org/pod/Catalyst), if you wish to
1337 use this new feature we recommend installing [JSON](https://metacpan.org/pod/JSON) or [JSON::MaybeXS](https://metacpan.org/pod/JSON::MaybeXS) in
1338 order to get the best performance.  You should add either to your dependency
1339 list (Makefile.PL, dist.ini, cpanfile, etc.)
1340
1341 ## $c->stack
1342
1343 Returns an arrayref of the internal execution stack (actions that are
1344 currently executing).
1345
1346 ## $c->stats
1347
1348 Returns the current timing statistics object. By default Catalyst uses
1349 [Catalyst::Stats](https://metacpan.org/pod/Catalyst::Stats), but can be set otherwise with
1350 [stats\_class](#c-stats_class).
1351
1352 Even if [-Stats](#stats) is not enabled, the stats object is still
1353 available. By enabling it with ` $c-`stats->enabled(1) >, it can be used to
1354 profile explicitly, although MyApp.pm still won't profile nor output anything
1355 by itself.
1356
1357 ## $c->stats\_class
1358
1359 Returns or sets the stats (timing statistics) class. [Catalyst::Stats](https://metacpan.org/pod/Catalyst::Stats) is used by default.
1360
1361 ## $app->stats\_class\_traits
1362
1363 A arrayref of [Moose::Role](https://metacpan.org/pod/Moose::Role)s that are applied to the stats\_class before creating it.
1364
1365 ## $app->composed\_stats\_class
1366
1367 this is the stats\_class composed with any 'stats\_class\_traits'.
1368
1369 ## $c->use\_stats
1370
1371 Returns 1 when [stats collection](#stats) is enabled.
1372
1373 Note that this is a static method, not an accessor and should be overridden
1374 by declaring `sub use_stats { 1 }` in your MyApp.pm, not by calling `$c->use_stats(1)`.
1375
1376 ## $c->write( $data )
1377
1378 Writes $data to the output stream. When using this method directly, you
1379 will need to manually set the `Content-Length` header to the length of
1380 your output data, if known.
1381
1382 ## version
1383
1384 Returns the Catalyst version number. Mostly useful for "powered by"
1385 messages in template systems.
1386
1387 # CONFIGURATION
1388
1389 There are a number of 'base' config variables which can be set:
1390
1391 - `always_catch_http_exceptions` - As of version 5.90060 Catalyst
1392 rethrows errors conforming to the interface described by
1393 [Plack::Middleware::HTTPExceptions](https://metacpan.org/pod/Plack::Middleware::HTTPExceptions) and lets the middleware deal with it.
1394 Set true to get the deprecated behaviour and have Catalyst catch HTTP exceptions.
1395 - `default_model` - The default model picked if you say `$c->model`. See ["$c->model($name)"](#c-model-name).
1396 - `default_view` - The default view to be rendered or returned when `$c->view` is called. See ["$c->view($name)"](#c-view-name).
1397 - `disable_component_resolution_regex_fallback` - Turns
1398 off the deprecated component resolution functionality so
1399 that if any of the component methods (e.g. `$c->controller('Foo')`)
1400 are called then regex search will not be attempted on string values and
1401 instead `undef` will be returned.
1402 - `home` - The application home directory. In an uninstalled application,
1403 this is the top level application directory. In an installed application,
1404 this will be the directory containing `MyApp.pm`.
1405 - `ignore_frontend_proxy` - See ["PROXY SUPPORT"](#proxy-support)
1406 - `name` - The name of the application in debug messages and the debug and
1407 welcome screens
1408 - `parse_on_demand` - The request body (for example file uploads) will not be parsed
1409 until it is accessed. This allows you to (for example) check authentication (and reject
1410 the upload) before actually receiving all the data. See ["ON-DEMAND PARSER"](#on-demand-parser)
1411 - `root` - The root directory for templates. Usually this is just a
1412 subdirectory of the home directory, but you can set it to change the
1413 templates to a different directory.
1414 - `search_extra` - Array reference passed to Module::Pluggable to for additional
1415 namespaces from which components will be loaded (and constructed and stored in
1416 `$c->components`).
1417 - `show_internal_actions` - If true, causes internal actions such as `_DISPATCH`
1418 to be shown in hit debug tables in the test server.
1419 - `use_request_uri_for_path` - Controls if the `REQUEST_URI` or `PATH_INFO` environment
1420 variable should be used for determining the request path.
1421
1422     Most web server environments pass the requested path to the application using environment variables,
1423     from which Catalyst has to reconstruct the request base (i.e. the top level path to / in the application,
1424     exposed as `$c->request->base`) and the request path below that base.
1425
1426     There are two methods of doing this, both of which have advantages and disadvantages. Which method is used
1427     is determined by the `$c->config(use_request_uri_for_path)` setting (which can either be true or false).
1428
1429     - use\_request\_uri\_for\_path => 0
1430
1431         This is the default (and the) traditional method that Catalyst has used for determining the path information.
1432         The path is generated from a combination of the `PATH_INFO` and `SCRIPT_NAME` environment variables.
1433         The allows the application to behave correctly when `mod_rewrite` is being used to redirect requests
1434         into the application, as these variables are adjusted by mod\_rewrite to take account for the redirect.
1435
1436         However this method has the major disadvantage that it is impossible to correctly decode some elements
1437         of the path, as RFC 3875 says: "`Unlike a URI path, the PATH_INFO is not URL-encoded, and cannot
1438         contain path-segment parameters.`" This means PATH\_INFO is **always** decoded, and therefore Catalyst
1439         can't distinguish / vs %2F in paths (in addition to other encoded values).
1440
1441     - use\_request\_uri\_for\_path => 1
1442
1443         This method uses the `REQUEST_URI` and `SCRIPT_NAME` environment variables. As `REQUEST_URI` is never
1444         decoded, this means that applications using this mode can correctly handle URIs including the %2F character
1445         (i.e. with `AllowEncodedSlashes` set to `On` in Apache).
1446
1447         Given that this method of path resolution is probably more correct, it is recommended that you use
1448         this unless you have a specific need to deploy your application in a non-standard environment, and you are
1449         aware of the implications of not being able to handle encoded URI paths correctly.
1450
1451         However it also means that in a number of cases when the app isn't installed directly at a path, but instead
1452         is having paths rewritten into it (e.g. as a .cgi/fcgi in a public\_html directory, with mod\_rewrite in a
1453         .htaccess file, or when SSI is used to rewrite pages into the app, or when sub-paths of the app are exposed
1454         at other URIs than that which the app is 'normally' based at with `mod_rewrite`), the resolution of
1455         `$c->request->base` will be incorrect.
1456
1457 - `using_frontend_proxy` - See ["PROXY SUPPORT"](#proxy-support).
1458 - `using_frontend_proxy_path` - Enabled [Plack::Middleware::ReverseProxyPath](https://metacpan.org/pod/Plack::Middleware::ReverseProxyPath) on your application (if
1459 installed, otherwise log an error).  This is useful if your application is not running on the
1460 'root' (or /) of your host server.  **NOTE** if you use this feature you should add the required
1461 middleware to your project dependency list since it's not automatically a dependency of [Catalyst](https://metacpan.org/pod/Catalyst).
1462 This has been done since not all people need this feature and we wish to restrict the growth of
1463 [Catalyst](https://metacpan.org/pod/Catalyst) dependencies.
1464 - `encoding` - See ["ENCODING"](#encoding)
1465
1466     This now defaults to 'UTF-8'.  You my turn it off by setting this configuration
1467     value to undef.
1468
1469 - `abort_chain_on_error_fix`
1470
1471     When there is an error in an action chain, the default behavior is to continue
1472     processing the remaining actions and then catch the error upon chain end.  This
1473     can lead to running actions when the application is in an unexpected state.  If
1474     you have this issue, setting this config value to true will promptly exit a
1475     chain when there is an error raised in any action (thus terminating the chain
1476     early.)
1477
1478     use like:
1479
1480         __PACKAGE__->config(abort_chain_on_error_fix => 1);
1481
1482     In the future this might become the default behavior.
1483
1484 - `use_hash_multivalue_in_request`
1485
1486     In [Catalyst::Request](https://metacpan.org/pod/Catalyst::Request) the methods `query_parameters`, `body_parametes`
1487     and `parameters` return a hashref where values might be scalar or an arrayref
1488     depending on the incoming data.  In many cases this can be undesirable as it
1489     leads one to writing defensive code like the following:
1490
1491         my ($val) = ref($c->req->parameters->{a}) ?
1492           @{$c->req->parameters->{a}} :
1493             $c->req->parameters->{a};
1494
1495     Setting this configuration item to true will make [Catalyst](https://metacpan.org/pod/Catalyst) populate the
1496     attributes underlying these methods with an instance of [Hash::MultiValue](https://metacpan.org/pod/Hash::MultiValue)
1497     which is used by [Plack::Request](https://metacpan.org/pod/Plack::Request) and others to solve this very issue.  You
1498     may prefer this behavior to the default, if so enable this option (be warned
1499     if you enable it in a legacy application we are not sure if it is completely
1500     backwardly compatible).
1501
1502 - `skip_complex_post_part_handling`
1503
1504     When creating body parameters from a POST, if we run into a multpart POST
1505     that does not contain uploads, but instead contains inlined complex data
1506     (very uncommon) we cannot reliably convert that into field => value pairs.  So
1507     instead we create an instance of [Catalyst::Request::PartData](https://metacpan.org/pod/Catalyst::Request::PartData).  If this causes
1508     issue for you, you can disable this by setting `skip_complex_post_part_handling`
1509     to true (default is false).  
1510
1511 - `skip_body_param_unicode_decoding`
1512
1513     Generally we decode incoming POST params based on your declared encoding (the
1514     default for this is to decode UTF-8).  If this is causing you trouble and you
1515     do not wish to turn all encoding support off (with the `encoding` configuration
1516     parameter) you may disable this step atomically by setting this configuration
1517     parameter to true.
1518
1519 - `do_not_decode_query`
1520
1521     If true, then do not try to character decode any wide characters in your
1522     request URL query or keywords.  Most readings of the relevant specifications
1523     suggest these should be UTF-\* encoded, which is the default that [Catalyst](https://metacpan.org/pod/Catalyst)
1524     will use, hwoever if you are creating a lot of URLs manually or have external
1525     evil clients, this might cause you trouble.  If you find the changes introduced
1526     in Catalyst version 5.90080+ break some of your query code, you may disable 
1527     the UTF-8 decoding globally using this configuration.
1528
1529     This setting takes precedence over `default_query_encoding` and
1530     `decode_query_using_global_encoding`
1531
1532 - `default_query_encoding`
1533
1534     By default we decode query and keywords in your request URL using UTF-8, which
1535     is our reading of the relevent specifications.  This setting allows one to
1536     specify a fixed value for how to decode your query.  You might need this if
1537     you are doing a lot of custom encoding of your URLs and not using UTF-8.
1538
1539     This setting take precedence over `decode_query_using_global_encoding`.
1540
1541 - `decode_query_using_global_encoding`
1542
1543     Setting this to true will default your query decoding to whatever your
1544     general global encoding is (the default is UTF-8).
1545
1546 - `use_chained_args_0_special_case`
1547
1548     In older versions of Catalyst, when more than one action matched the same path
1549     AND all those matching actions declared Args(0), we'd break the tie by choosing
1550     the first action defined.  We now normalized how Args(0) works so that it
1551     follows the same rule as Args(N), which is to say when we need to break a tie
1552     we choose the LAST action defined.  If this breaks your code and you don't
1553     have time to update to follow the new normalized approach, you may set this
1554     value to true and it will globally revert to the original chaining behavior.
1555
1556 - `psgi_middleware` - See ["PSGI MIDDLEWARE"](#psgi-middleware).
1557 - `data_handlers` - See ["DATA HANDLERS"](#data-handlers).
1558 - `stats_class_traits`
1559
1560     An arrayref of [Moose::Role](https://metacpan.org/pod/Moose::Role)s that get componsed into your stats class.
1561
1562 - `request_class_traits`
1563
1564     An arrayref of [Moose::Role](https://metacpan.org/pod/Moose::Role)s that get componsed into your request class.
1565
1566 - `response_class_traits`
1567
1568     An arrayref of [Moose::Role](https://metacpan.org/pod/Moose::Role)s that get componsed into your response class.
1569
1570 - `inject_components`
1571
1572     A Hashref of [Catalyst::Component](https://metacpan.org/pod/Catalyst::Component) subclasses that are 'injected' into configuration.
1573     For example:
1574
1575         MyApp->config({
1576           inject_components => {
1577             'Controller::Err' => { from_component => 'Local::Controller::Errors' },
1578             'Model::Zoo' => { from_component => 'Local::Model::Foo' },
1579             'Model::Foo' => { from_component => 'Local::Model::Foo', roles => ['TestRole'] },
1580           },
1581           'Controller::Err' => { a => 100, b=>200, namespace=>'error' },
1582           'Model::Zoo' => { a => 2 },
1583           'Model::Foo' => { a => 100 },
1584         });
1585
1586     Generally [Catalyst](https://metacpan.org/pod/Catalyst) looks for components in your Model/View or Controller directories.
1587     However for cases when you which to use an existing component and you don't need any
1588     customization (where for when you can apply a role to customize it) you may inject those
1589     components into your application.  Please note any configuration should be done 'in the
1590     normal way', with a key under configuration named after the component affix, as in the
1591     above example.
1592
1593     Using this type of injection allows you to construct significant amounts of your application
1594     with only configuration!.  This may or may not lead to increased code understanding.
1595
1596     Please not you may also call the ->inject\_components application method as well, although
1597     you must do so BEFORE setup.
1598
1599 # EXCEPTIONS
1600
1601 Generally when you throw an exception inside an Action (or somewhere in
1602 your stack, such as in a model that an Action is calling) that exception
1603 is caught by Catalyst and unless you either catch it yourself (via eval
1604 or something like [Try::Tiny](https://metacpan.org/pod/Try::Tiny) or by reviewing the ["error"](#error) stack, it
1605 will eventually reach ["finalize\_errors"](#finalize_errors) and return either the debugging
1606 error stack page, or the default error page.  However, if your exception
1607 can be caught by [Plack::Middleware::HTTPExceptions](https://metacpan.org/pod/Plack::Middleware::HTTPExceptions), [Catalyst](https://metacpan.org/pod/Catalyst) will
1608 instead rethrow it so that it can be handled by that middleware (which
1609 is part of the default middleware).  For example this would allow
1610
1611     use HTTP::Throwable::Factory 'http_throw';
1612
1613     sub throws_exception :Local {
1614       my ($self, $c) = @_;
1615
1616       http_throw(SeeOther => { location =>
1617         $c->uri_for($self->action_for('redirect')) });
1618
1619     }
1620
1621 # INTERNAL ACTIONS
1622
1623 Catalyst uses internal actions like `_DISPATCH`, `_BEGIN`, `_AUTO`,
1624 `_ACTION`, and `_END`. These are by default not shown in the private
1625 action table, but you can make them visible with a config parameter.
1626
1627     MyApp->config(show_internal_actions => 1);
1628
1629 # ON-DEMAND PARSER
1630
1631 The request body is usually parsed at the beginning of a request,
1632 but if you want to handle input yourself, you can enable on-demand
1633 parsing with a config parameter.
1634
1635     MyApp->config(parse_on_demand => 1);
1636
1637 # PROXY SUPPORT
1638
1639 Many production servers operate using the common double-server approach,
1640 with a lightweight frontend web server passing requests to a larger
1641 backend server. An application running on the backend server must deal
1642 with two problems: the remote user always appears to be `127.0.0.1` and
1643 the server's hostname will appear to be `localhost` regardless of the
1644 virtual host that the user connected through.
1645
1646 Catalyst will automatically detect this situation when you are running
1647 the frontend and backend servers on the same machine. The following
1648 changes are made to the request.
1649
1650     $c->req->address is set to the user's real IP address, as read from
1651     the HTTP X-Forwarded-For header.
1652
1653     The host value for $c->req->base and $c->req->uri is set to the real
1654     host, as read from the HTTP X-Forwarded-Host header.
1655
1656 Additionally, you may be running your backend application on an insecure
1657 connection (port 80) while your frontend proxy is running under SSL.  If there
1658 is a discrepancy in the ports, use the HTTP header `X-Forwarded-Port` to
1659 tell Catalyst what port the frontend listens on.  This will allow all URIs to
1660 be created properly.
1661
1662 In the case of passing in:
1663
1664     X-Forwarded-Port: 443
1665
1666 All calls to `uri_for` will result in an https link, as is expected.
1667
1668 Obviously, your web server must support these headers for this to work.
1669
1670 In a more complex server farm environment where you may have your
1671 frontend proxy server(s) on different machines, you will need to set a
1672 configuration option to tell Catalyst to read the proxied data from the
1673 headers.
1674
1675     MyApp->config(using_frontend_proxy => 1);
1676
1677 If you do not wish to use the proxy support at all, you may set:
1678
1679     MyApp->config(ignore_frontend_proxy => 0);
1680
1681 ## Note about psgi files
1682
1683 Note that if you supply your own .psgi file, calling
1684 `MyApp->psgi_app(@_);`, then **this will not happen automatically**.
1685
1686 You either need to apply [Plack::Middleware::ReverseProxy](https://metacpan.org/pod/Plack::Middleware::ReverseProxy) yourself
1687 in your psgi, for example:
1688
1689     builder {
1690         enable "Plack::Middleware::ReverseProxy";
1691         MyApp->psgi_app
1692     };
1693
1694 This will unconditionally add the ReverseProxy support, or you need to call
1695 `$app = MyApp->apply_default_middlewares($app)` (to conditionally
1696 apply the support depending upon your config).
1697
1698 See [Catalyst::PSGI](https://metacpan.org/pod/Catalyst::PSGI) for more information.
1699
1700 # THREAD SAFETY
1701
1702 Catalyst has been tested under Apache 2's threading `mpm_worker`,
1703 `mpm_winnt`, and the standalone forking HTTP server on Windows. We
1704 believe the Catalyst core to be thread-safe.
1705
1706 If you plan to operate in a threaded environment, remember that all other
1707 modules you are using must also be thread-safe. Some modules, most notably
1708 [DBD::SQLite](https://metacpan.org/pod/DBD::SQLite), are not thread-safe.
1709
1710 # DATA HANDLERS
1711
1712 The [Catalyst::Request](https://metacpan.org/pod/Catalyst::Request) object uses [HTTP::Body](https://metacpan.org/pod/HTTP::Body) to populate 'classic' HTML
1713 form parameters and URL search query fields.  However it has become common
1714 for various alternative content types to be PUT or POSTed to your controllers
1715 and actions.  People working on RESTful APIs, or using AJAX often use JSON,
1716 XML and other content types when communicating with an application server.  In
1717 order to better support this use case, [Catalyst](https://metacpan.org/pod/Catalyst) defines a global configuration
1718 option, `data_handlers`, which lets you associate a content type with a coderef
1719 that parses that content type into something Perl can readily access.
1720
1721        package MyApp::Web;
1722     
1723        use Catalyst;
1724        use JSON::Maybe;
1725     
1726        __PACKAGE__->config(
1727          data_handlers => {
1728            'application/json' => sub { local $/; decode_json $_->getline },
1729          },
1730          ## Any other configuration.
1731        );
1732     
1733        __PACKAGE__->setup;
1734
1735 By default [Catalyst](https://metacpan.org/pod/Catalyst) comes with a generic JSON data handler similar to the
1736 example given above, which uses [JSON::Maybe](https://metacpan.org/pod/JSON::Maybe) to provide either [JSON::PP](https://metacpan.org/pod/JSON::PP)
1737 (a pure Perl, dependency free JSON parser) or [Cpanel::JSON::XS](https://metacpan.org/pod/Cpanel::JSON::XS) if you have
1738 it installed (if you want the faster XS parser, add it to you project Makefile.PL
1739 or dist.ini, cpanfile, etc.)
1740
1741 The `data_handlers` configuration is a hashref whose keys are HTTP Content-Types
1742 (matched against the incoming request type using a regexp such as to be case
1743 insensitive) and whose values are coderefs that receive a localized version of
1744 `$_` which is a filehandle object pointing to received body.
1745
1746 This feature is considered an early access release and we reserve the right
1747 to alter the interface in order to provide a performant and secure solution to
1748 alternative request body content.  Your reports welcomed!
1749
1750 # PSGI MIDDLEWARE
1751
1752 You can define middleware, defined as [Plack::Middleware](https://metacpan.org/pod/Plack::Middleware) or a compatible
1753 interface in configuration.  Your middleware definitions are in the form of an
1754 arrayref under the configuration key `psgi_middleware`.  Here's an example
1755 with details to follow:
1756
1757        package MyApp::Web;
1758     
1759        use Catalyst;
1760        use Plack::Middleware::StackTrace;
1761     
1762        my $stacktrace_middleware = Plack::Middleware::StackTrace->new;
1763     
1764        __PACKAGE__->config(
1765          'psgi_middleware', [
1766            'Debug',
1767            '+MyApp::Custom',
1768            $stacktrace_middleware,
1769            'Session' => {store => 'File'},
1770            sub {
1771              my $app = shift;
1772              return sub {
1773                my $env = shift;
1774                $env->{myapp.customkey} = 'helloworld';
1775                $app->($env);
1776              },
1777            },
1778          ],
1779        );
1780     
1781        __PACKAGE__->setup;
1782
1783 So the general form is:
1784
1785     __PACKAGE__->config(psgi_middleware => \@middleware_definitions);
1786
1787 Where `@middleware` is one or more of the following, applied in the REVERSE of
1788 the order listed (to make it function similarly to [Plack::Builder](https://metacpan.org/pod/Plack::Builder):
1789
1790 Alternatively, you may also define middleware by calling the ["setup\_middleware"](#setup_middleware)
1791 package method:
1792
1793     package MyApp::Web;
1794
1795     use Catalyst;
1796
1797     __PACKAGE__->setup_middleware( \@middleware_definitions);
1798     __PACKAGE__->setup;
1799
1800 In the case where you do both (use 'setup\_middleware' and configuration) the
1801 package call to setup\_middleware will be applied earlier (in other words its
1802 middleware will wrap closer to the application).  Keep this in mind since in
1803 some cases the order of middleware is important.
1804
1805 The two approaches are not exclusive.
1806
1807 - Middleware Object
1808
1809     An already initialized object that conforms to the [Plack::Middleware](https://metacpan.org/pod/Plack::Middleware)
1810     specification:
1811
1812            my $stacktrace_middleware = Plack::Middleware::StackTrace->new;
1813         
1814            __PACKAGE__->config(
1815              'psgi_middleware', [
1816                $stacktrace_middleware,
1817              ]);
1818         
1819         
1820
1821 - coderef
1822
1823     A coderef that is an inlined middleware:
1824
1825            __PACKAGE__->config(
1826              'psgi_middleware', [
1827                sub {
1828                  my $app = shift;
1829                  return sub {
1830                    my $env = shift;
1831                    if($env->{PATH_INFO} =~m/forced/) {
1832                      Plack::App::File
1833                        ->new(file=>TestApp->path_to(qw/share static forced.txt/))
1834                        ->call($env);
1835                    } else {
1836                      return $app->($env);
1837                    }
1838                 },
1839              },
1840            ]);
1841         
1842         
1843         
1844
1845 - a scalar
1846
1847     We assume the scalar refers to a namespace after normalizing it using the
1848     following rules:
1849
1850     (1) If the scalar is prefixed with a "+" (as in `+MyApp::Foo`) then the full string
1851     is assumed to be 'as is', and we just install and use the middleware.
1852
1853     (2) If the scalar begins with "Plack::Middleware" or your application namespace
1854     (the package name of your Catalyst application subclass), we also assume then
1855     that it is a full namespace, and use it.
1856
1857     (3) Lastly, we then assume that the scalar is a partial namespace, and attempt to
1858     resolve it first by looking for it under your application namespace (for example
1859     if you application is "MyApp::Web" and the scalar is "MyMiddleware", we'd look
1860     under "MyApp::Web::Middleware::MyMiddleware") and if we don't find it there, we
1861     will then look under the regular [Plack::Middleware](https://metacpan.org/pod/Plack::Middleware) namespace (i.e. for the
1862     previous we'd try "Plack::Middleware::MyMiddleware").  We look under your application
1863     namespace first to let you 'override' common [Plack::Middleware](https://metacpan.org/pod/Plack::Middleware) locally, should
1864     you find that a good idea.
1865
1866     Examples:
1867
1868            package MyApp::Web;
1869
1870            __PACKAGE__->config(
1871              'psgi_middleware', [
1872                'Debug',  ## MyAppWeb::Middleware::Debug->wrap or Plack::Middleware::Debug->wrap
1873                'Plack::Middleware::Stacktrace', ## Plack::Middleware::Stacktrace->wrap
1874                '+MyApp::Custom',  ## MyApp::Custom->wrap
1875              ],
1876            );
1877         
1878
1879 - a scalar followed by a hashref
1880
1881     Just like the previous, except the following `HashRef` is used as arguments
1882     to initialize the middleware object.
1883
1884         __PACKAGE__->config(
1885           'psgi_middleware', [
1886              'Session' => {store => 'File'},
1887         ]);
1888
1889 Please see [PSGI](https://metacpan.org/pod/PSGI) for more on middleware.
1890
1891 # ENCODING
1892
1893 Starting in [Catalyst](https://metacpan.org/pod/Catalyst) version 5.90080 encoding is automatically enabled
1894 and set to encode all body responses to UTF8 when possible and applicable.
1895 Following is documentation on this process.  If you are using an older
1896 version of [Catalyst](https://metacpan.org/pod/Catalyst) you should review documentation for that version since
1897 a lot has changed.
1898
1899 By default encoding is now 'UTF-8'.  You may turn it off by setting
1900 the encoding configuration to undef.
1901
1902     MyApp->config(encoding => undef);
1903
1904 This is recommended for temporary backwards compatibility only.
1905
1906 Encoding is automatically applied when the content-type is set to
1907 a type that can be encoded.  Currently we encode when the content type
1908 matches the following regular expression:
1909
1910     $content_type =~ /^text|xml$|javascript$/
1911
1912 Encoding is set on the application, but it is copied to the context object
1913 so that you can override it on a request basis.
1914
1915 Be default we don't automatically encode 'application/json' since the most
1916 common approaches to generating this type of response (Either via [Catalyst::View::JSON](https://metacpan.org/pod/Catalyst::View::JSON)
1917 or [Catalyst::Action::REST](https://metacpan.org/pod/Catalyst::Action::REST)) will do so already and we want to avoid double
1918 encoding issues.
1919
1920 If you are producing JSON response in an unconventional manner (such
1921 as via a template or manual strings) you should perform the UTF8 encoding
1922 manually as well such as to conform to the JSON specification.
1923
1924 NOTE: We also examine the value of $c->response->content\_encoding.  If
1925 you set this (like for example 'gzip', and manually gzipping the body)
1926 we assume that you have done all the necessary encoding yourself, since
1927 we cannot encode the gzipped contents.  If you use a plugin like
1928 [Catalyst::Plugin::Compress](https://metacpan.org/pod/Catalyst::Plugin::Compress) you need to update to a modern version in order
1929 to have this function correctly  with the new UTF8 encoding code, or you
1930 can use [Plack::Middleware::Deflater](https://metacpan.org/pod/Plack::Middleware::Deflater) or (probably best) do your compression on
1931 a front end proxy.
1932
1933 ## Methods
1934
1935 - encoding
1936
1937     Returns an instance of an `Encode` encoding
1938
1939         print $c->encoding->name
1940
1941 - handle\_unicode\_encoding\_exception ($exception\_context)
1942
1943     Method called when decoding process for a request fails.
1944
1945     An `$exception_context` hashref is provided to allow you to override the
1946     behaviour of your application when given data with incorrect encodings.
1947
1948     The default method throws exceptions in the case of invalid request parameters
1949     (resulting in a 500 error), but ignores errors in upload filenames.
1950
1951     The keys passed in the `$exception_context` hash are:
1952
1953     - param\_value
1954
1955         The value which was not able to be decoded.
1956
1957     - error\_msg
1958
1959         The exception received from [Encode](https://metacpan.org/pod/Encode).
1960
1961     - encoding\_step
1962
1963         What type of data was being decoded. Valid values are (currently)
1964         `params` - for request parameters / arguments / captures
1965         and `uploads` - for request upload filenames.
1966
1967 # SUPPORT
1968
1969 IRC:
1970
1971     Join #catalyst on irc.perl.org.
1972
1973 Mailing Lists:
1974
1975     http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
1976     http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
1977
1978 Web:
1979
1980     http://catalyst.perl.org
1981
1982 Wiki:
1983
1984     http://dev.catalyst.perl.org
1985
1986 # SEE ALSO
1987
1988 ## [Task::Catalyst](https://metacpan.org/pod/Task::Catalyst) - All you need to start with Catalyst
1989
1990 ## [Catalyst::Manual](https://metacpan.org/pod/Catalyst::Manual) - The Catalyst Manual
1991
1992 ## [Catalyst::Component](https://metacpan.org/pod/Catalyst::Component), [Catalyst::Controller](https://metacpan.org/pod/Catalyst::Controller) - Base classes for components
1993
1994 ## [Catalyst::Engine](https://metacpan.org/pod/Catalyst::Engine) - Core engine
1995
1996 ## [Catalyst::Log](https://metacpan.org/pod/Catalyst::Log) - Log class.
1997
1998 ## [Catalyst::Request](https://metacpan.org/pod/Catalyst::Request) - Request object
1999
2000 ## [Catalyst::Response](https://metacpan.org/pod/Catalyst::Response) - Response object
2001
2002 ## [Catalyst::Test](https://metacpan.org/pod/Catalyst::Test) - The test suite.
2003
2004 # PROJECT FOUNDER
2005
2006 sri: Sebastian Riedel <sri@cpan.org>
2007
2008 # CONTRIBUTORS
2009
2010 abw: Andy Wardley
2011
2012 acme: Leon Brocard <leon@astray.com>
2013
2014 abraxxa: Alexander Hartmaier <abraxxa@cpan.org>
2015
2016 andrewalker: André Walker <andre@cpan.org>
2017
2018 Andrew Bramble
2019
2020 Andrew Ford <A.Ford@ford-mason.co.uk>
2021
2022 Andrew Ruthven
2023
2024 andyg: Andy Grundman <andy@hybridized.org>
2025
2026 audreyt: Audrey Tang
2027
2028 bricas: Brian Cassidy <bricas@cpan.org>
2029
2030 Caelum: Rafael Kitover <rkitover@io.com>
2031
2032 chansen: Christian Hansen
2033
2034 chicks: Christopher Hicks
2035
2036 Chisel Wright `pause@herlpacker.co.uk`
2037
2038 Danijel Milicevic `me@danijel.de`
2039
2040 davewood: David Schmidt <davewood@cpan.org>
2041
2042 David Kamholz <dkamholz@cpan.org>
2043
2044 David Naughton, `naughton@umn.edu`
2045
2046 David E. Wheeler
2047
2048 dhoss: Devin Austin <dhoss@cpan.org>
2049
2050 dkubb: Dan Kubb <dan.kubb-cpan@onautopilot.com>
2051
2052 Drew Taylor
2053
2054 dwc: Daniel Westermann-Clark <danieltwc@cpan.org>
2055
2056 esskar: Sascha Kiefer
2057
2058 fireartist: Carl Franks <cfranks@cpan.org>
2059
2060 frew: Arthur Axel "fREW" Schmidt <frioux@gmail.com>
2061
2062 gabb: Danijel Milicevic
2063
2064 Gary Ashton Jones
2065
2066 Gavin Henry `ghenry@perl.me.uk`
2067
2068 Geoff Richards
2069
2070 groditi: Guillermo Roditi <groditi@gmail.com>
2071
2072 hobbs: Andrew Rodland <andrew@cleverdomain.org>
2073
2074 ilmari: Dagfinn Ilmari MannsÃ¥ker <ilmari@ilmari.org>
2075
2076 jcamacho: Juan Camacho
2077
2078 jester: Jesse Sheidlower `jester@panix.com`
2079
2080 jhannah: Jay Hannah <jay@jays.net>
2081
2082 Jody Belka
2083
2084 Johan Lindstrom
2085
2086 jon: Jon Schutz <jjschutz@cpan.org>
2087
2088 Jonathan Rockway `<jrockway@cpan.org>`
2089
2090 Kieren Diment `kd@totaldatasolution.com`
2091
2092 konobi: Scott McWhirter <konobi@cpan.org>
2093
2094 marcus: Marcus Ramberg <mramberg@cpan.org>
2095
2096 miyagawa: Tatsuhiko Miyagawa <miyagawa@bulknews.net>
2097
2098 mgrimes: Mark Grimes <mgrimes@cpan.org>
2099
2100 mst: Matt S. Trout <mst@shadowcatsystems.co.uk>
2101
2102 mugwump: Sam Vilain
2103
2104 naughton: David Naughton
2105
2106 ningu: David Kamholz <dkamholz@cpan.org>
2107
2108 nothingmuch: Yuval Kogman <nothingmuch@woobling.org>
2109
2110 numa: Dan Sully <daniel@cpan.org>
2111
2112 obra: Jesse Vincent
2113
2114 Octavian Rasnita
2115
2116 omega: Andreas Marienborg
2117
2118 Oleg Kostyuk <cub.uanic@gmail.com>
2119
2120 phaylon: Robert Sedlacek <phaylon@dunkelheit.at>
2121
2122 rafl: Florian Ragwitz <rafl@debian.org>
2123
2124 random: Roland Lammel <lammel@cpan.org>
2125
2126 Robert Sedlacek `<rs@474.at>`
2127
2128 SpiceMan: Marcel Montes
2129
2130 sky: Arthur Bergman
2131
2132 szbalint: Balint Szilakszi <szbalint@cpan.org>
2133
2134 t0m: Tomas Doran <bobtfish@bobtfish.net>
2135
2136 Ulf Edvinsson
2137
2138 vanstyn: Henry Van Styn <vanstyn@cpan.org>
2139
2140 Viljo Marrandi `vilts@yahoo.com`
2141
2142 Will Hawes `info@whawes.co.uk`
2143
2144 willert: Sebastian Willert <willert@cpan.org>
2145
2146 wreis: Wallace Reis <wreis@cpan.org>
2147
2148 Yuval Kogman, `nothingmuch@woobling.org`
2149
2150 rainboxx: Matthias Dietrich, `perl@rainboxx.de`
2151
2152 dd070: Dhaval Dhanani <dhaval070@gmail.com>
2153
2154 Upasana <me@upasana.me>
2155
2156 John Napiorkowski (jnap) <jjnapiork@cpan.org>
2157
2158 # COPYRIGHT
2159
2160 Copyright (c) 2005-2015, the above named PROJECT FOUNDER and CONTRIBUTORS.
2161
2162 # LICENSE
2163
2164 This library is free software. You can redistribute it and/or modify it under
2165 the same terms as Perl itself.