.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Catalyst 3pm" .TH Catalyst 3pm "2022-12-22" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Catalyst \- The Elegant MVC Web Application Framework .SH "SYNOPSIS" .IX Header "SYNOPSIS" See the Catalyst::Manual distribution for comprehensive documentation and tutorials. .PP .Vb 3 \& # Install Catalyst::Devel for helpers and other development tools \& # use the helper to create a new application \& catalyst.pl MyApp \& \& # add models, views, controllers \& script/myapp_create.pl model MyDatabase DBIC::Schema create=static dbi:SQLite:/path/to/db \& script/myapp_create.pl view MyTemplate TT \& script/myapp_create.pl controller Search \& \& # built in testserver \-\- use \-r to restart automatically on changes \& # \-\-help to see all available options \& script/myapp_server.pl \& \& # command line testing interface \& script/myapp_test.pl /yada \& \& ### in lib/MyApp.pm \& use Catalyst qw/\-Debug/; # include plugins here as well \& \& ### In lib/MyApp/Controller/Root.pm (autocreated) \& sub foo : Chained(\*(Aq/\*(Aq) Args() { # called for /foo, /foo/1, /foo/1/2, etc. \& my ( $self, $c, @args ) = @_; # args are qw/1 2/ for /foo/1/2 \& $c\->stash\->{template} = \*(Aqfoo.tt\*(Aq; # set the template \& # lookup something from db \-\- stash vars are passed to TT \& $c\->stash\->{data} = \& $c\->model(\*(AqDatabase::Foo\*(Aq)\->search( { country => $args[0] } ); \& if ( $c\->req\->params\->{bar} ) { # access GET or POST parameters \& $c\->forward( \*(Aqbar\*(Aq ); # process another action \& # do something else after forward returns \& } \& } \& \& # The foo.tt TT template can use the stash data from the database \& [% WHILE (item = data.next) %] \& [% item.foo %] \& [% END %] \& \& # called for /bar/of/soap, /bar/of/soap/10, etc. \& sub bar : Chained(\*(Aq/\*(Aq) PathPart(\*(Aq/bar/of/soap\*(Aq) Args() { ... } \& \& # called after all actions are finished \& sub end : Action { \& my ( $self, $c ) = @_; \& if ( scalar @{ $c\->error } ) { ... } # handle errors \& return if $c\->res\->body; # already have a response \& $c\->forward( \*(AqMyApp::View::TT\*(Aq ); # render template \& } .Ve .PP See Catalyst::Manual::Intro for additional information. .SH "DESCRIPTION" .IX Header "DESCRIPTION" Catalyst is a modern framework for making web applications without the pain usually associated with this process. This document is a reference to the main Catalyst application. If you are a new user, we suggest you start with Catalyst::Manual::Tutorial or Catalyst::Manual::Intro. .PP See Catalyst::Manual for more documentation. .PP Catalyst plugins can be loaded by naming them as arguments to the \*(L"use Catalyst\*(R" statement. Omit the \f(CW\*(C`Catalyst::Plugin::\*(C'\fR prefix from the plugin name, i.e., \f(CW\*(C`Catalyst::Plugin::My::Module\*(C'\fR becomes \&\f(CW\*(C`My::Module\*(C'\fR. .PP .Vb 1 \& use Catalyst qw/My::Module/; .Ve .PP If your plugin starts with a name other than \f(CW\*(C`Catalyst::Plugin::\*(C'\fR, you can fully qualify the name by using a unary plus: .PP .Vb 4 \& use Catalyst qw/ \& My::Module \& +Fully::Qualified::Plugin::Name \& /; .Ve .PP Special flags like \f(CW\*(C`\-Debug\*(C'\fR can also be specified as arguments when Catalyst is loaded: .PP .Vb 1 \& use Catalyst qw/\-Debug My::Module/; .Ve .PP The position of plugins and flags in the chain is important, because they are loaded in the order in which they appear. .PP The following flags are supported: .SS "\-Debug" .IX Subsection "-Debug" Enables debug output. You can also force this setting from the system environment with \s-1CATALYST_DEBUG\s0 or <\s-1MYAPP\s0>_DEBUG. The environment settings override the application, with <\s-1MYAPP\s0>_DEBUG having the highest priority. .PP This sets the log level to 'debug' and enables full debug output on the error screen. If you only want the latter, see \f(CW$c\fR\->debug. .SS "\-Home" .IX Subsection "-Home" Forces Catalyst to use a specific home directory, e.g.: .PP .Vb 1 \& use Catalyst qw[\-Home=/usr/mst]; .Ve .PP This can also be done in the shell environment by setting either the \&\f(CW\*(C`CATALYST_HOME\*(C'\fR environment variable or \f(CW\*(C`MYAPP_HOME\*(C'\fR; where \f(CW\*(C`MYAPP\*(C'\fR is replaced with the uppercased name of your application, any \*(L"::\*(R" in the name will be replaced with underscores, e.g. MyApp::Web should use \&\s-1MYAPP_WEB_HOME.\s0 If both variables are set, the \s-1MYAPP_HOME\s0 one will be used. .PP If none of these are set, Catalyst will attempt to automatically detect the home directory. If you are working in a development environment, Catalyst will try and find the directory containing either Makefile.PL, Build.PL, dist.ini, or cpanfile. If the application has been installed into the system (i.e. you have done \f(CW\*(C`make install\*(C'\fR), then Catalyst will use the path to your application module, without the .pm extension (e.g., /foo/MyApp if your application was installed at /foo/MyApp.pm) .SS "\-Log" .IX Subsection "-Log" .Vb 1 \& use Catalyst \*(Aq\-Log=warn,fatal,error\*(Aq; .Ve .PP Specifies a comma-delimited list of log levels. .SS "\-Stats" .IX Subsection "-Stats" Enables statistics collection and reporting. .PP .Vb 1 \& use Catalyst qw/\-Stats=1/; .Ve .PP You can also force this setting from the system environment with \s-1CATALYST_STATS\s0 or <\s-1MYAPP\s0>_STATS. The environment settings override the application, with <\s-1MYAPP\s0>_STATS having the highest priority. .PP Stats are also enabled if debugging is enabled. .SH "METHODS" .IX Header "METHODS" .SS "\s-1INFORMATION ABOUT THE CURRENT REQUEST\s0" .IX Subsection "INFORMATION ABOUT THE CURRENT REQUEST" .ie n .SS "$c\->action" .el .SS "\f(CW$c\fP\->action" .IX Subsection "$c->action" Returns a Catalyst::Action object for the current action, which stringifies to the action name. See Catalyst::Action. .ie n .SS "$c\->namespace" .el .SS "\f(CW$c\fP\->namespace" .IX Subsection "$c->namespace" Returns the namespace of the current action, i.e., the \s-1URI\s0 prefix corresponding to the controller of the current action. For example: .PP .Vb 2 \& # in Controller::Foo::Bar \& $c\->namespace; # returns \*(Aqfoo/bar\*(Aq; .Ve .ie n .SS "$c\->request" .el .SS "\f(CW$c\fP\->request" .IX Subsection "$c->request" .ie n .SS "$c\->req" .el .SS "\f(CW$c\fP\->req" .IX Subsection "$c->req" Returns the current Catalyst::Request object, giving access to information about the current client request (including parameters, cookies, \s-1HTTP\s0 headers, etc.). See Catalyst::Request. .PP There is a predicate method \f(CW\*(C`has_request\*(C'\fR that returns true if the request object has been created. This is something you might need to check if you are writing plugins that run before a request is finalized. .SS "\s-1REQUEST FLOW HANDLING\s0" .IX Subsection "REQUEST FLOW HANDLING" .ie n .SS "$c\->forward( $action [, \e@arguments ] )" .el .SS "\f(CW$c\fP\->forward( \f(CW$action\fP [, \e@arguments ] )" .IX Subsection "$c->forward( $action [, @arguments ] )" .ie n .SS "$c\->forward( $class, $method, [, \e@arguments ] )" .el .SS "\f(CW$c\fP\->forward( \f(CW$class\fP, \f(CW$method\fP, [, \e@arguments ] )" .IX Subsection "$c->forward( $class, $method, [, @arguments ] )" .ie n .SS "$c\->forward( $component_instance, $method, [, \e@arguments ] )" .el .SS "\f(CW$c\fP\->forward( \f(CW$component_instance\fP, \f(CW$method\fP, [, \e@arguments ] )" .IX Subsection "$c->forward( $component_instance, $method, [, @arguments ] )" This is one way of calling another action (method) in the same or a different controller. You can also use \f(CW\*(C`$self\->my_method($c, @args)\*(C'\fR in the same controller or \f(CW\*(C`$c\->controller(\*(AqMyController\*(Aq)\->my_method($c, @args)\*(C'\fR in a different controller. The main difference is that 'forward' uses some of the Catalyst request cycle overhead, including debugging, which may be useful to you. On the other hand, there are some complications to using 'forward', restrictions on values returned from 'forward', and it may not handle errors as you prefer. Whether you use 'forward' or not is up to you; it is not considered superior to the other ways to call a method. .PP \&'forward' calls another action, by its private name. If you give a class name but no method, \f(CW\*(C`process()\*(C'\fR is called. You may also optionally pass arguments in an arrayref. The action will receive the arguments in \&\f(CW@_\fR and \f(CW\*(C`$c\->req\->args\*(C'\fR. Upon returning from the function, \&\f(CW\*(C`$c\->req\->args\*(C'\fR will be restored to the previous values. .PP Any data \f(CW\*(C`return\*(C'\fRed from the action forwarded to, will be returned by the call to forward. .PP .Vb 4 \& my $foodata = $c\->forward(\*(Aq/foo\*(Aq); \& $c\->forward(\*(Aqindex\*(Aq); \& $c\->forward(qw/Model::DBIC::Foo do_stuff/); \& $c\->forward(\*(AqView::TT\*(Aq); .Ve .PP Note that forward implies an \f(CW\*(C`eval { }\*(C'\fR around the call (actually execute does), thus rendering all exceptions thrown by the called action non-fatal and pushing them onto \&\f(CW$c\fR\->error instead. If you want \f(CW\*(C`die\*(C'\fR to propagate you need to do something like: .PP .Vb 2 \& $c\->forward(\*(Aqfoo\*(Aq); \& die join "\en", @{ $c\->error } if @{ $c\->error }; .Ve .PP Or make sure to always return true values from your actions and write your code like this: .PP .Vb 1 \& $c\->forward(\*(Aqfoo\*(Aq) || return; .Ve .PP Another note is that \f(CW\*(C`$c\->forward\*(C'\fR always returns a scalar because it actually returns \f(CW$c\fR\->state which operates in a scalar context. Thus, something like: .PP .Vb 1 \& return @array; .Ve .PP in an action that is forwarded to is going to return a scalar, i.e. how many items are in that array, which is probably not what you want. If you need to return an array then return a reference to it, or stash it like so: .PP .Vb 1 \& $c\->stash\->{array} = \e@array; .Ve .PP and access it from the stash. .PP Keep in mind that the \f(CW\*(C`end\*(C'\fR method used is that of the caller action. So a \f(CW\*(C`$c\->detach\*(C'\fR inside a forwarded action would run the \f(CW\*(C`end\*(C'\fR method from the original action requested. .PP If you call c with the name of a component class or instance, rather than an action name or instance, we invoke the \f(CW\*(C`process\*(C'\fR action on that class or instance, or whatever action you specific via the second argument \f(CW$method\fR. .ie n .SS "$c\->detach( $action [, \e@arguments ] )" .el .SS "\f(CW$c\fP\->detach( \f(CW$action\fP [, \e@arguments ] )" .IX Subsection "$c->detach( $action [, @arguments ] )" .ie n .SS "$c\->detach( $class, $method, [, \e@arguments ] )" .el .SS "\f(CW$c\fP\->detach( \f(CW$class\fP, \f(CW$method\fP, [, \e@arguments ] )" .IX Subsection "$c->detach( $class, $method, [, @arguments ] )" .ie n .SS "$c\->\fBdetach()\fP" .el .SS "\f(CW$c\fP\->\fBdetach()\fP" .IX Subsection "$c->detach()" The same as forward, but doesn't return to the previous action when processing is finished. .PP When called with no arguments it escapes the processing chain entirely. .ie n .SS "$c\->visit( $action [, \e@arguments ] )" .el .SS "\f(CW$c\fP\->visit( \f(CW$action\fP [, \e@arguments ] )" .IX Subsection "$c->visit( $action [, @arguments ] )" .ie n .SS "$c\->visit( $action [, \e@captures, \e@arguments ] )" .el .SS "\f(CW$c\fP\->visit( \f(CW$action\fP [, \e@captures, \e@arguments ] )" .IX Subsection "$c->visit( $action [, @captures, @arguments ] )" .ie n .SS "$c\->visit( $class, $method, [, \e@arguments ] )" .el .SS "\f(CW$c\fP\->visit( \f(CW$class\fP, \f(CW$method\fP, [, \e@arguments ] )" .IX Subsection "$c->visit( $class, $method, [, @arguments ] )" .ie n .SS "$c\->visit( $class, $method, [, \e@captures, \e@arguments ] )" .el .SS "\f(CW$c\fP\->visit( \f(CW$class\fP, \f(CW$method\fP, [, \e@captures, \e@arguments ] )" .IX Subsection "$c->visit( $class, $method, [, @captures, @arguments ] )" Almost the same as forward, but does a full dispatch, instead of just calling the new \f(CW$action\fR / \&\f(CW\*(C`$class\->$method\*(C'\fR. This means that \f(CW\*(C`begin\*(C'\fR, \f(CW\*(C`auto\*(C'\fR and the method you go to are called, just like a new request. .PP In addition both \f(CW\*(C`$c\->action\*(C'\fR and \f(CW\*(C`$c\->namespace\*(C'\fR are localized. This means, for example, that \f(CW\*(C`$c\->action\*(C'\fR methods such as name, class and reverse return information for the visited action when they are invoked within the visited action. This is different from the behavior of forward, which continues to use the \f(CW$c\fR\->action object from the caller action even when invoked from the called action. .PP \&\f(CW\*(C`$c\->stash\*(C'\fR is kept unchanged. .PP In effect, visit allows you to \*(L"wrap\*(R" another action, just as it would have been called by dispatching from a \s-1URL,\s0 while the analogous go allows you to transfer control to another action as if it had been reached directly from a \s-1URL.\s0 .ie n .SS "$c\->go( $action [, \e@arguments ] )" .el .SS "\f(CW$c\fP\->go( \f(CW$action\fP [, \e@arguments ] )" .IX Subsection "$c->go( $action [, @arguments ] )" .ie n .SS "$c\->go( $action [, \e@captures, \e@arguments ] )" .el .SS "\f(CW$c\fP\->go( \f(CW$action\fP [, \e@captures, \e@arguments ] )" .IX Subsection "$c->go( $action [, @captures, @arguments ] )" .ie n .SS "$c\->go( $class, $method, [, \e@arguments ] )" .el .SS "\f(CW$c\fP\->go( \f(CW$class\fP, \f(CW$method\fP, [, \e@arguments ] )" .IX Subsection "$c->go( $class, $method, [, @arguments ] )" .ie n .SS "$c\->go( $class, $method, [, \e@captures, \e@arguments ] )" .el .SS "\f(CW$c\fP\->go( \f(CW$class\fP, \f(CW$method\fP, [, \e@captures, \e@arguments ] )" .IX Subsection "$c->go( $class, $method, [, @captures, @arguments ] )" The relationship between \f(CW\*(C`go\*(C'\fR and visit is the same as the relationship between forward and detach. Like \f(CW\*(C`$c\->visit\*(C'\fR, \&\f(CW\*(C`$c\->go\*(C'\fR will perform a full dispatch on the specified action or method, with localized \f(CW\*(C`$c\->action\*(C'\fR and \f(CW\*(C`$c\->namespace\*(C'\fR. Like \f(CW\*(C`detach\*(C'\fR, \&\f(CW\*(C`go\*(C'\fR escapes the processing of the current request chain on completion, and does not return to its caller. .PP \&\f(CW@arguments\fR are arguments to the final destination of \f(CW$action\fR. \f(CW@captures\fR are arguments to the intermediate steps, if any, on the way to the final sub of \&\f(CW$action\fR. .ie n .SS "$c\->response" .el .SS "\f(CW$c\fP\->response" .IX Subsection "$c->response" .ie n .SS "$c\->res" .el .SS "\f(CW$c\fP\->res" .IX Subsection "$c->res" Returns the current Catalyst::Response object, see there for details. .PP There is a predicate method \f(CW\*(C`has_response\*(C'\fR that returns true if the request object has been created. This is something you might need to check if you are writing plugins that run before a request is finalized. .ie n .SS "$c\->stash" .el .SS "\f(CW$c\fP\->stash" .IX Subsection "$c->stash" Returns a hashref to the stash, which may be used to store data and pass it between components during a request. You can also set hash keys by passing arguments. The stash is automatically sent to the view. The stash is cleared at the end of a request; it cannot be used for persistent storage (for this you must use a session; see Catalyst::Plugin::Session for a complete system integrated with Catalyst). .PP .Vb 3 \& $c\->stash\->{foo} = $bar; \& $c\->stash( { moose => \*(Aqmajestic\*(Aq, qux => 0 } ); \& $c\->stash( bar => 1, gorch => 2 ); # equivalent to passing a hashref \& \& # stash is automatically passed to the view for use in a template \& $c\->forward( \*(AqMyApp::View::TT\*(Aq ); .Ve .PP The stash hash is currently stored in the \s-1PSGI\s0 \f(CW$env\fR and is managed by Catalyst::Middleware::Stash. Since it's part of the \f(CW$env\fR items in the stash can be accessed in sub applications mounted under your main Catalyst application. For example if you delegate the response of an action to another Catalyst application, that sub application will have access to all the stash keys of the main one, and if can of course add more keys of its own. However those new keys will not 'bubble' back up to the main application. .PP For more information the best thing to do is to review the test case: t/middleware\-stash.t in the distribution /t directory. .ie n .SS "$c\->error" .el .SS "\f(CW$c\fP\->error" .IX Subsection "$c->error" .ie n .SS "$c\->error($error, ...)" .el .SS "\f(CW$c\fP\->error($error, ...)" .IX Subsection "$c->error($error, ...)" .ie n .SS "$c\->error($arrayref)" .el .SS "\f(CW$c\fP\->error($arrayref)" .IX Subsection "$c->error($arrayref)" Returns an arrayref containing error messages. If Catalyst encounters an error while processing a request, it stores the error in \f(CW$c\fR\->error. This method should only be used to store fatal error messages. .PP .Vb 1 \& my @error = @{ $c\->error }; .Ve .PP Add a new error. .PP .Vb 1 \& $c\->error(\*(AqSomething bad happened\*(Aq); .Ve .PP Calling this will always return an arrayref (if there are no errors it will be an empty arrayref. .ie n .SS "$c\->state" .el .SS "\f(CW$c\fP\->state" .IX Subsection "$c->state" Contains the return value of the last executed action. Note that << \f(CW$c\fR\->state >> operates in a scalar context which means that all values it returns are scalar. .PP Please note that if an action throws an exception, the value of state should no longer be considered the return if the last action. It is generally going to be 0, which indicates an error state. Examine \f(CW$c\fR\->error for error details. .ie n .SS "$c\->clear_errors" .el .SS "\f(CW$c\fP\->clear_errors" .IX Subsection "$c->clear_errors" Clear errors. You probably don't want to clear the errors unless you are implementing a custom error screen. .PP This is equivalent to running .PP .Vb 1 \& $c\->error(0); .Ve .ie n .SS "$c\->has_errors" .el .SS "\f(CW$c\fP\->has_errors" .IX Subsection "$c->has_errors" Returns true if you have errors .ie n .SS "$c\->last_error" .el .SS "\f(CW$c\fP\->last_error" .IX Subsection "$c->last_error" Returns the most recent error in the stack (the one most recently added...) or nothing if there are no errors. This does not modify the contents of the error stack. .SS "shift_errors" .IX Subsection "shift_errors" shifts the most recently added error off the error stack and returns it. Returns nothing if there are no more errors. .SS "pop_errors" .IX Subsection "pop_errors" pops the most recently added error off the error stack and returns it. Returns nothing if there are no more errors. .SS "\s-1COMPONENT ACCESSORS\s0" .IX Subsection "COMPONENT ACCESSORS" .ie n .SS "$c\->controller($name)" .el .SS "\f(CW$c\fP\->controller($name)" .IX Subsection "$c->controller($name)" Gets a Catalyst::Controller instance by name. .PP .Vb 1 \& $c\->controller(\*(AqFoo\*(Aq)\->do_stuff; .Ve .PP If the name is omitted, will return the controller for the dispatched action. .PP If you want to search for controllers, pass in a regexp as the argument. .PP .Vb 2 \& # find all controllers that start with Foo \& my @foo_controllers = $c\->controller(qr{^Foo}); .Ve .ie n .SS "$c\->model($name)" .el .SS "\f(CW$c\fP\->model($name)" .IX Subsection "$c->model($name)" Gets a Catalyst::Model instance by name. .PP .Vb 1 \& $c\->model(\*(AqFoo\*(Aq)\->do_stuff; .Ve .PP Any extra arguments are directly passed to \s-1ACCEPT_CONTEXT,\s0 if the model defines \s-1ACCEPT_CONTEXT.\s0 If it does not, the args are discarded. .PP If the name is omitted, it will look for \- a model object in \f(CW$c\fR\->stash\->{current_model_instance}, then \- a model name in \f(CW$c\fR\->stash\->{current_model}, then \- a config setting 'default_model', or \- check if there is only one model, and return it if that's the case. .PP If you want to search for models, pass in a regexp as the argument. .PP .Vb 2 \& # find all models that start with Foo \& my @foo_models = $c\->model(qr{^Foo}); .Ve .ie n .SS "$c\->view($name)" .el .SS "\f(CW$c\fP\->view($name)" .IX Subsection "$c->view($name)" Gets a Catalyst::View instance by name. .PP .Vb 1 \& $c\->view(\*(AqFoo\*(Aq)\->do_stuff; .Ve .PP Any extra arguments are directly passed to \s-1ACCEPT_CONTEXT.\s0 .PP If the name is omitted, it will look for \- a view object in \f(CW$c\fR\->stash\->{current_view_instance}, then \- a view name in \f(CW$c\fR\->stash\->{current_view}, then \- a config setting 'default_view', or \- check if there is only one view, and return it if that's the case. .PP If you want to search for views, pass in a regexp as the argument. .PP .Vb 2 \& # find all views that start with Foo \& my @foo_views = $c\->view(qr{^Foo}); .Ve .ie n .SS "$c\->controllers" .el .SS "\f(CW$c\fP\->controllers" .IX Subsection "$c->controllers" Returns the available names which can be passed to \f(CW$c\fR\->controller .ie n .SS "$c\->models" .el .SS "\f(CW$c\fP\->models" .IX Subsection "$c->models" Returns the available names which can be passed to \f(CW$c\fR\->model .ie n .SS "$c\->views" .el .SS "\f(CW$c\fP\->views" .IX Subsection "$c->views" Returns the available names which can be passed to \f(CW$c\fR\->view .ie n .SS "$c\->comp($name)" .el .SS "\f(CW$c\fP\->comp($name)" .IX Subsection "$c->comp($name)" .ie n .SS "$c\->component($name)" .el .SS "\f(CW$c\fP\->component($name)" .IX Subsection "$c->component($name)" Gets a component object by name. This method is not recommended, unless you want to get a specific component by full class. \f(CW\*(C`$c\->controller\*(C'\fR, \f(CW\*(C`$c\->model\*(C'\fR, and \f(CW\*(C`$c\->view\*(C'\fR should be used instead. .PP If \f(CW$name\fR is a regexp, a list of components matched against the full component name will be returned. .PP If Catalyst can't find a component by name, it will fallback to regex matching by default. To disable this behaviour set disable_component_resolution_regex_fallback to a true value. .PP .Vb 1 \& _\|_PACKAGE_\|_\->config( disable_component_resolution_regex_fallback => 1 ); .Ve .SS "\s-1CLASS DATA AND HELPER CLASSES\s0" .IX Subsection "CLASS DATA AND HELPER CLASSES" .ie n .SS "$c\->config" .el .SS "\f(CW$c\fP\->config" .IX Subsection "$c->config" Returns or takes a hashref containing the application's configuration. .PP .Vb 1 \& _\|_PACKAGE_\|_\->config( { db => \*(Aqdsn:SQLite:foo.db\*(Aq } ); .Ve .PP You can also use a \f(CW\*(C`YAML\*(C'\fR, \f(CW\*(C`XML\*(C'\fR or Config::General config file like \f(CW\*(C`myapp.conf\*(C'\fR in your applications home directory. See Catalyst::Plugin::ConfigLoader. .PP \fICascading configuration\fR .IX Subsection "Cascading configuration" .PP The config method is present on all Catalyst components, and configuration will be merged when an application is started. Configuration loaded with Catalyst::Plugin::ConfigLoader takes precedence over other configuration, followed by configuration in your top level \f(CW\*(C`MyApp\*(C'\fR class. These two configurations are merged, and then configuration data whose hash key matches a component name is merged with configuration for that component. .PP The configuration for a component is then passed to the \f(CW\*(C`new\*(C'\fR method when a component is constructed. .PP For example: .PP .Vb 2 \& MyApp\->config({ \*(AqModel::Foo\*(Aq => { bar => \*(Aqbaz\*(Aq, overrides => \*(Aqme\*(Aq } }); \& MyApp::Model::Foo\->config({ quux => \*(Aqfrob\*(Aq, overrides => \*(Aqthis\*(Aq }); .Ve .PP will mean that \f(CW\*(C`MyApp::Model::Foo\*(C'\fR receives the following data when constructed: .PP .Vb 5 \& MyApp::Model::Foo\->new({ \& bar => \*(Aqbaz\*(Aq, \& quux => \*(Aqfrob\*(Aq, \& overrides => \*(Aqme\*(Aq, \& }); .Ve .PP It's common practice to use a Moose attribute on the receiving component to access the config value. .PP .Vb 1 \& package MyApp::Model::Foo; \& \& use Moose; \& \& # this attr will receive \*(Aqbaz\*(Aq at construction time \& has \*(Aqbar\*(Aq => ( \& is => \*(Aqrw\*(Aq, \& isa => \*(AqStr\*(Aq, \& ); .Ve .PP You can then get the value 'baz' by calling \f(CW$c\fR\->model('Foo')\->bar (or \f(CW$self\fR\->bar inside code in the model). .PP \&\fB\s-1NOTE:\s0\fR you \s-1MUST NOT\s0 call \f(CW\*(C`$self\->config\*(C'\fR or \f(CW\*(C`_\|_PACKAGE_\|_\->config\*(C'\fR as a way of reading config within your code, as this \fBwill not\fR give you the correctly merged config back. You \fB\s-1MUST\s0\fR take the config values supplied to the constructor and use those instead. .ie n .SS "$c\->log" .el .SS "\f(CW$c\fP\->log" .IX Subsection "$c->log" Returns the logging object instance. Unless it is already set, Catalyst sets this up with a Catalyst::Log object. To use your own log class, set the logger with the \f(CW\*(C`_\|_PACKAGE_\|_\->log\*(C'\fR method prior to calling \&\f(CW\*(C`_\|_PACKAGE_\|_\->setup\*(C'\fR. .PP .Vb 2 \& _\|_PACKAGE_\|_\->log( MyLogger\->new ); \& _\|_PACKAGE_\|_\->setup; .Ve .PP And later: .PP .Vb 1 \& $c\->log\->info( \*(AqNow logging with my own logger!\*(Aq ); .Ve .PP Your log class should implement the methods described in Catalyst::Log. .SS "has_encoding" .IX Subsection "has_encoding" Returned True if there's a valid encoding .SS "clear_encoding" .IX Subsection "clear_encoding" Clears the encoding for the current context .SS "encoding" .IX Subsection "encoding" Sets or gets the application encoding. Setting encoding takes either an Encoding object or a string that we try to resolve via Encode::find_encoding. .PP You would expect to get the encoding object back if you attempt to set it. If there is a failure you will get undef returned and an error message in the log. .ie n .SS "$c\->debug" .el .SS "\f(CW$c\fP\->debug" .IX Subsection "$c->debug" Returns 1 if debug mode is enabled, 0 otherwise. .PP You can enable debug mode in several ways: .IP "By calling myapp_server.pl with the \-d flag" 4 .IX Item "By calling myapp_server.pl with the -d flag" .PD 0 .IP "With the environment variables \s-1MYAPP_DEBUG,\s0 or \s-1CATALYST_DEBUG\s0" 4 .IX Item "With the environment variables MYAPP_DEBUG, or CATALYST_DEBUG" .IP "The \-Debug option in your MyApp.pm" 4 .IX Item "The -Debug option in your MyApp.pm" .ie n .IP "By declaring ""sub debug { 1 }"" in your MyApp.pm." 4 .el .IP "By declaring \f(CWsub debug { 1 }\fR in your MyApp.pm." 4 .IX Item "By declaring sub debug { 1 } in your MyApp.pm." .PD .PP The first three also set the log level to 'debug'. .PP Calling \f(CW\*(C`$c\->debug(1)\*(C'\fR has no effect. .ie n .SS "$c\->dispatcher" .el .SS "\f(CW$c\fP\->dispatcher" .IX Subsection "$c->dispatcher" Returns the dispatcher instance. See Catalyst::Dispatcher. .ie n .SS "$c\->engine" .el .SS "\f(CW$c\fP\->engine" .IX Subsection "$c->engine" Returns the engine instance. See Catalyst::Engine. .SS "\s-1UTILITY METHODS\s0" .IX Subsection "UTILITY METHODS" .ie n .SS "$c\->path_to(@path)" .el .SS "\f(CW$c\fP\->path_to(@path)" .IX Subsection "$c->path_to(@path)" Merges \f(CW@path\fR with \f(CW\*(C`$c\->config\->{home}\*(C'\fR and returns a Path::Class::Dir object. Note you can usually use this object as a filename, but sometimes you will have to explicitly stringify it yourself by calling the \f(CW\*(C`\->stringify\*(C'\fR method. .PP For example: .PP .Vb 1 \& $c\->path_to( \*(Aqdb\*(Aq, \*(Aqsqlite.db\*(Aq ); .Ve .SS "MyApp\->setup" .IX Subsection "MyApp->setup" Initializes the dispatcher and engine, loads any plugins, and loads the model, view, and controller components. You may also specify an array of plugins to load here, if you choose to not load them in the \f(CW\*(C`use Catalyst\*(C'\fR line. .PP .Vb 2 \& MyApp\->setup; \& MyApp\->setup( qw/\-Debug/ ); .Ve .PP \&\fBNote:\fR You \fBshould not\fR wrap this method with method modifiers or bad things will happen \- wrap the \f(CW\*(C`setup_finalize\*(C'\fR method instead. .PP \&\fBNote:\fR You can create a custom setup stage that will execute when the application is starting. Use this to customize setup. .PP .Vb 1 \& MyApp\->setup(\-Custom=value); \& \& sub setup_custom { \& my ($class, $value) = @_; \& } .Ve .PP Can be handy if you want to hook into the setup phase. .ie n .SS "$app\->setup_finalize" .el .SS "\f(CW$app\fP\->setup_finalize" .IX Subsection "$app->setup_finalize" A hook to attach modifiers to. This method does not do anything except set the \&\f(CW\*(C`setup_finished\*(C'\fR accessor. .PP Applying method modifiers to the \f(CW\*(C`setup\*(C'\fR method doesn't work, because of quirky things done for plugin setup. .PP Example: .PP .Vb 2 \& after setup_finalize => sub { \& my $app = shift; \& \& ## do stuff here.. \& }; .Ve .ie n .SS "$c\->uri_for( $path?, @args?, \e%query_values?, \e$fragment? )" .el .SS "\f(CW$c\fP\->uri_for( \f(CW$path\fP?, \f(CW@args\fP?, \e%query_values?, \e$fragment? )" .IX Subsection "$c->uri_for( $path?, @args?, %query_values?, $fragment? )" .ie n .SS "$c\->uri_for( $action, \e@captures?, @args?, \e%query_values?, \e$fragment? )" .el .SS "\f(CW$c\fP\->uri_for( \f(CW$action\fP, \e@captures?, \f(CW@args\fP?, \e%query_values?, \e$fragment? )" .IX Subsection "$c->uri_for( $action, @captures?, @args?, %query_values?, $fragment? )" .ie n .SS "$c\->uri_for( $action, [@captures, @args], \e%query_values?, \e$fragment? )" .el .SS "\f(CW$c\fP\->uri_for( \f(CW$action\fP, [@captures, \f(CW@args\fP], \e%query_values?, \e$fragment? )" .IX Subsection "$c->uri_for( $action, [@captures, @args], %query_values?, $fragment? )" Constructs an absolute \s-1URI\s0 object based on the application root, the provided path, and the additional arguments and query parameters provided. When used as a string, provides a textual \s-1URI.\s0 If you need more flexibility than this (i.e. the option to provide relative URIs etc.) see Catalyst::Plugin::SmartURI. .PP If no arguments are provided, the \s-1URI\s0 for the current action is returned. To return the current action and also provide \f(CW@args\fR, use \&\f(CW\*(C`$c\->uri_for( $c\->action, @args )\*(C'\fR. .PP If the first argument is a string, it is taken as a public \s-1URI\s0 path relative to \f(CW\*(C`$c\->namespace\*(C'\fR (if it doesn't begin with a forward slash) or relative to the application root (if it does). It is then merged with \&\f(CW\*(C`$c\->request\->base\*(C'\fR; any \f(CW@args\fR are appended as additional path components; and any \f(CW%query_values\fR are appended as \f(CW\*(C`?foo=bar\*(C'\fR parameters. .PP \&\fB\s-1NOTE\s0\fR If you are using this 'stringy' first argument, we skip encoding and allow you to declare something like: .PP .Vb 1 \& $c\->uri_for(\*(Aq/foo/bar#baz\*(Aq) .Ve .PP Where 'baz' is a \s-1URI\s0 fragment. We consider this first argument string to be \&'expert' mode where you are expected to create a valid \s-1URL\s0 and we for the most part just pass it through without a lot of internal effort to escape and encode. .PP If the first argument is a Catalyst::Action it represents an action which will have its path resolved using \f(CW\*(C`$c\->dispatcher\->uri_for_action\*(C'\fR. The optional \f(CW\*(C`\e@captures\*(C'\fR argument (an arrayref) allows passing the captured variables that are needed to fill in the paths of Chained and Regex actions; once the path is resolved, \f(CW\*(C`uri_for\*(C'\fR continues as though a path was provided, appending any arguments or parameters and creating an absolute \&\s-1URI.\s0 .PP The captures for the current request can be found in \&\f(CW\*(C`$c\->request\->captures\*(C'\fR, and actions can be resolved using \&\f(CW\*(C`Catalyst::Controller\->action_for($name)\*(C'\fR. If you have a private action path, use \f(CW\*(C`$c\->uri_for_action\*(C'\fR instead. .PP .Vb 3 \& # Equivalent to $c\->req\->uri \& $c\->uri_for($c\->action, $c\->req\->captures, \& @{ $c\->req\->args }, $c\->req\->params); \& \& # For the Foo action in the Bar controller \& $c\->uri_for($c\->controller(\*(AqBar\*(Aq)\->action_for(\*(AqFoo\*(Aq)); \& \& # Path to a static resource \& $c\->uri_for(\*(Aq/static/images/logo.png\*(Aq); .Ve .PP In general the scheme of the generated \s-1URI\s0 object will follow the incoming request however if your targeted action or action chain has the Scheme attribute it will use that instead. .PP Also, if the targeted Action or Action chain declares Args/CaptureArgs that have type constraints, we will require that your proposed \s-1URL\s0 verify on those declared constraints. .ie n .SS "$c\->uri_for_action( $path, \e@captures_and_args?, @args?, \e%query_values? )" .el .SS "\f(CW$c\fP\->uri_for_action( \f(CW$path\fP, \e@captures_and_args?, \f(CW@args\fP?, \e%query_values? )" .IX Subsection "$c->uri_for_action( $path, @captures_and_args?, @args?, %query_values? )" .ie n .SS "$c\->uri_for_action( $action, \e@captures_and_args?, @args?, \e%query_values? )" .el .SS "\f(CW$c\fP\->uri_for_action( \f(CW$action\fP, \e@captures_and_args?, \f(CW@args\fP?, \e%query_values? )" .IX Subsection "$c->uri_for_action( $action, @captures_and_args?, @args?, %query_values? )" .ie n .IP "$path" 4 .el .IP "\f(CW$path\fR" 4 .IX Item "$path" A private path to the Catalyst action you want to create a \s-1URI\s0 for. .Sp This is a shortcut for calling \f(CW\*(C`$c\->dispatcher\->get_action_by_path($path)\*(C'\fR and passing the resulting \f(CW$action\fR and the remaining arguments to \f(CW\*(C`$c\->uri_for\*(C'\fR. .Sp You can also pass in a Catalyst::Action object, in which case it is passed to \&\f(CW\*(C`$c\->uri_for\*(C'\fR. .Sp Note that although the path looks like a \s-1URI\s0 that dispatches to the wanted action, it is not a \s-1URI,\s0 but an internal path to that action. .Sp For example, if the action looks like: .Sp .Vb 1 \& package MyApp::Controller::Users; \& \& sub lst : Path(\*(Aqthe\-list\*(Aq) {} .Ve .Sp You can use: .Sp .Vb 1 \& $c\->uri_for_action(\*(Aq/users/lst\*(Aq) .Ve .Sp and it will create the \s-1URI\s0 /users/the\-list. .IP "\e@captures_and_args?" 4 .IX Item "@captures_and_args?" Optional array reference of Captures (i.e. \f(CW\*(C`CaptureArgs\*(C'\fR or \f(CW\*(C`$c\->req\->captures\*(C'\fR) and arguments to the request. Usually used with Catalyst::DispatchType::Chained to interpolate all the parameters in the \s-1URI.\s0 .ie n .IP "@args?" 4 .el .IP "\f(CW@args\fR?" 4 .IX Item "@args?" Optional list of extra arguments \- can be supplied in the \&\f(CW\*(C`\e@captures_and_args?\*(C'\fR array ref, or here \- whichever is easier for your code. .Sp Your action can have zero, a fixed or a variable number of args (e.g. \&\f(CWArgs(1)\fR for a fixed number or \f(CW\*(C`Args()\*(C'\fR for a variable number).. .IP "\e%query_values?" 4 .IX Item "%query_values?" Optional array reference of query parameters to append. E.g. .Sp .Vb 1 \& { foo => \*(Aqbar\*(Aq } .Ve .Sp will generate .Sp .Vb 1 \& /rest/of/your/uri?foo=bar .Ve .ie n .SS "$c\->welcome_message" .el .SS "\f(CW$c\fP\->welcome_message" .IX Subsection "$c->welcome_message" Returns the Catalyst welcome \s-1HTML\s0 page. .SS "run_options" .IX Subsection "run_options" Contains a hash of options passed from the application script, including the original \s-1ARGV\s0 the script received, the processed values from that \&\s-1ARGV\s0 and any extra arguments to the script which were not processed. .PP This can be used to add custom options to your application's scripts and setup your application differently depending on the values of these options. .SH "INTERNAL METHODS" .IX Header "INTERNAL METHODS" These methods are not meant to be used by end users. .ie n .SS "$c\->components" .el .SS "\f(CW$c\fP\->components" .IX Subsection "$c->components" Returns a hash of components. .ie n .SS "$c\->context_class" .el .SS "\f(CW$c\fP\->context_class" .IX Subsection "$c->context_class" Returns or sets the context class. .ie n .SS "$c\->counter" .el .SS "\f(CW$c\fP\->counter" .IX Subsection "$c->counter" Returns a hashref containing coderefs and execution counts (needed for deep recursion detection). .ie n .SS "$c\->depth" .el .SS "\f(CW$c\fP\->depth" .IX Subsection "$c->depth" Returns the number of actions on the current internal execution stack. .ie n .SS "$c\->dispatch" .el .SS "\f(CW$c\fP\->dispatch" .IX Subsection "$c->dispatch" Dispatches a request to actions. .ie n .SS "$c\->dispatcher_class" .el .SS "\f(CW$c\fP\->dispatcher_class" .IX Subsection "$c->dispatcher_class" Returns or sets the dispatcher class. .ie n .SS "$c\->dump_these" .el .SS "\f(CW$c\fP\->dump_these" .IX Subsection "$c->dump_these" Returns a list of 2\-element array references (name, structure) pairs that will be dumped on the error page in debug mode. .ie n .SS "$c\->engine_class" .el .SS "\f(CW$c\fP\->engine_class" .IX Subsection "$c->engine_class" Returns or sets the engine class. .ie n .SS "$c\->execute( $class, $coderef )" .el .SS "\f(CW$c\fP\->execute( \f(CW$class\fP, \f(CW$coderef\fP )" .IX Subsection "$c->execute( $class, $coderef )" Execute a coderef in given class and catch exceptions. Errors are available via \f(CW$c\fR\->error. .ie n .SS "$c\->finalize" .el .SS "\f(CW$c\fP\->finalize" .IX Subsection "$c->finalize" Finalizes the request. .ie n .SS "$c\->log_stats" .el .SS "\f(CW$c\fP\->log_stats" .IX Subsection "$c->log_stats" Logs statistics. .ie n .SS "$c\->finalize_body" .el .SS "\f(CW$c\fP\->finalize_body" .IX Subsection "$c->finalize_body" Finalizes body. .ie n .SS "$c\->finalize_cookies" .el .SS "\f(CW$c\fP\->finalize_cookies" .IX Subsection "$c->finalize_cookies" Finalizes cookies. .ie n .SS "$c\->finalize_error" .el .SS "\f(CW$c\fP\->finalize_error" .IX Subsection "$c->finalize_error" Finalizes error. If there is only one error in \*(L"error\*(R" and it is an object that does \f(CW\*(C`as_psgi\*(C'\fR or \f(CW\*(C`code\*(C'\fR we rethrow the error and presume it caught by middleware up the ladder. Otherwise we return the debugging error page (in debug mode) or we return the default error page (production mode). .ie n .SS "$c\->finalize_headers" .el .SS "\f(CW$c\fP\->finalize_headers" .IX Subsection "$c->finalize_headers" Finalizes headers. .ie n .SS "$c\->finalize_encoding" .el .SS "\f(CW$c\fP\->finalize_encoding" .IX Subsection "$c->finalize_encoding" Make sure your body is encoded properly \s-1IF\s0 you set an encoding. By default the encoding is \s-1UTF\-8\s0 but you can disable it by explicitly setting the encoding configuration value to undef. .PP We can only encode when the body is a scalar. Methods for encoding via the streaming interfaces (such as \f(CW\*(C`write\*(C'\fR and \f(CW\*(C`write_fh\*(C'\fR on Catalyst::Response are available). .PP See \*(L"\s-1ENCODING\*(R"\s0. .ie n .SS "$c\->finalize_output" .el .SS "\f(CW$c\fP\->finalize_output" .IX Subsection "$c->finalize_output" An alias for finalize_body. .ie n .SS "$c\->finalize_read" .el .SS "\f(CW$c\fP\->finalize_read" .IX Subsection "$c->finalize_read" Finalizes the input after reading is complete. .ie n .SS "$c\->finalize_uploads" .el .SS "\f(CW$c\fP\->finalize_uploads" .IX Subsection "$c->finalize_uploads" Finalizes uploads. Cleans up any temporary files. .ie n .SS "$c\->get_action( $action, $namespace )" .el .SS "\f(CW$c\fP\->get_action( \f(CW$action\fP, \f(CW$namespace\fP )" .IX Subsection "$c->get_action( $action, $namespace )" Gets an action in a given namespace. .ie n .SS "$c\->get_actions( $action, $namespace )" .el .SS "\f(CW$c\fP\->get_actions( \f(CW$action\fP, \f(CW$namespace\fP )" .IX Subsection "$c->get_actions( $action, $namespace )" Gets all actions of a given name in a namespace and all parent namespaces. .ie n .SS "$app\->handle_request( @arguments )" .el .SS "\f(CW$app\fP\->handle_request( \f(CW@arguments\fP )" .IX Subsection "$app->handle_request( @arguments )" Called to handle each \s-1HTTP\s0 request. .ie n .SS "$class\->prepare( @arguments )" .el .SS "\f(CW$class\fP\->prepare( \f(CW@arguments\fP )" .IX Subsection "$class->prepare( @arguments )" Creates a Catalyst context from an engine-specific request (Apache, \s-1CGI,\s0 etc.). .ie n .SS "$c\->prepare_action" .el .SS "\f(CW$c\fP\->prepare_action" .IX Subsection "$c->prepare_action" Prepares action. See Catalyst::Dispatcher. .ie n .SS "$c\->prepare_body" .el .SS "\f(CW$c\fP\->prepare_body" .IX Subsection "$c->prepare_body" Prepares message body. .ie n .SS "$c\->prepare_body_chunk( $chunk )" .el .SS "\f(CW$c\fP\->prepare_body_chunk( \f(CW$chunk\fP )" .IX Subsection "$c->prepare_body_chunk( $chunk )" Prepares a chunk of data before sending it to HTTP::Body. .PP See Catalyst::Engine. .ie n .SS "$c\->prepare_body_parameters" .el .SS "\f(CW$c\fP\->prepare_body_parameters" .IX Subsection "$c->prepare_body_parameters" Prepares body parameters. .ie n .SS "$c\->prepare_connection" .el .SS "\f(CW$c\fP\->prepare_connection" .IX Subsection "$c->prepare_connection" Prepares connection. .ie n .SS "$c\->prepare_cookies" .el .SS "\f(CW$c\fP\->prepare_cookies" .IX Subsection "$c->prepare_cookies" Prepares cookies by ensuring that the attribute on the request object has been built. .ie n .SS "$c\->prepare_headers" .el .SS "\f(CW$c\fP\->prepare_headers" .IX Subsection "$c->prepare_headers" Prepares request headers by ensuring that the attribute on the request object has been built. .ie n .SS "$c\->prepare_parameters" .el .SS "\f(CW$c\fP\->prepare_parameters" .IX Subsection "$c->prepare_parameters" Prepares parameters. .ie n .SS "$c\->prepare_path" .el .SS "\f(CW$c\fP\->prepare_path" .IX Subsection "$c->prepare_path" Prepares path and base. .ie n .SS "$c\->prepare_query_parameters" .el .SS "\f(CW$c\fP\->prepare_query_parameters" .IX Subsection "$c->prepare_query_parameters" Prepares query parameters. .ie n .SS "$c\->log_request" .el .SS "\f(CW$c\fP\->log_request" .IX Subsection "$c->log_request" Writes information about the request to the debug logs. This includes: .IP "\(bu" 4 Request method, path, and remote \s-1IP\s0 address .IP "\(bu" 4 Query keywords (see \*(L"query_keywords\*(R" in Catalyst::Request) .IP "\(bu" 4 Request parameters .IP "\(bu" 4 File uploads .ie n .SS "$c\->log_response" .el .SS "\f(CW$c\fP\->log_response" .IX Subsection "$c->log_response" Writes information about the response to the debug logs by calling \&\f(CW\*(C`$c\->log_response_status_line\*(C'\fR and \f(CW\*(C`$c\->log_response_headers\*(C'\fR. .ie n .SS "$c\->log_response_status_line($response)" .el .SS "\f(CW$c\fP\->log_response_status_line($response)" .IX Subsection "$c->log_response_status_line($response)" Writes one line of information about the response to the debug logs. This includes: .IP "\(bu" 4 Response status code .IP "\(bu" 4 Content-Type header (if present) .IP "\(bu" 4 Content-Length header (if present) .ie n .SS "$c\->log_response_headers($headers);" .el .SS "\f(CW$c\fP\->log_response_headers($headers);" .IX Subsection "$c->log_response_headers($headers);" Hook method which can be wrapped by plugins to log the response headers. No-op in the default implementation. .ie n .SS "$c\->log_request_parameters( query => {}, body => {} )" .el .SS "\f(CW$c\fP\->log_request_parameters( query => {}, body => {} )" .IX Subsection "$c->log_request_parameters( query => {}, body => {} )" Logs request parameters to debug logs .ie n .SS "$c\->log_request_uploads" .el .SS "\f(CW$c\fP\->log_request_uploads" .IX Subsection "$c->log_request_uploads" Logs file uploads included in the request to the debug logs. The parameter name, filename, file type, and file size are all included in the debug logs. .ie n .SS "$c\->log_request_headers($headers);" .el .SS "\f(CW$c\fP\->log_request_headers($headers);" .IX Subsection "$c->log_request_headers($headers);" Hook method which can be wrapped by plugins to log the request headers. No-op in the default implementation. .ie n .SS "$c\->log_headers($type => $headers)" .el .SS "\f(CW$c\fP\->log_headers($type => \f(CW$headers\fP)" .IX Subsection "$c->log_headers($type => $headers)" Logs HTTP::Headers (either request or response) to the debug logs. .ie n .SS "$c\->prepare_read" .el .SS "\f(CW$c\fP\->prepare_read" .IX Subsection "$c->prepare_read" Prepares the input for reading. .ie n .SS "$c\->prepare_request" .el .SS "\f(CW$c\fP\->prepare_request" .IX Subsection "$c->prepare_request" Prepares the engine request. .ie n .SS "$c\->prepare_uploads" .el .SS "\f(CW$c\fP\->prepare_uploads" .IX Subsection "$c->prepare_uploads" Prepares uploads. .ie n .SS "$c\->prepare_write" .el .SS "\f(CW$c\fP\->prepare_write" .IX Subsection "$c->prepare_write" Prepares the output for writing. .ie n .SS "$c\->request_class" .el .SS "\f(CW$c\fP\->request_class" .IX Subsection "$c->request_class" Returns or sets the request class. Defaults to Catalyst::Request. .ie n .SS "$app\->request_class_traits" .el .SS "\f(CW$app\fP\->request_class_traits" .IX Subsection "$app->request_class_traits" An arrayref of Moose::Roles which are applied to the request class. You can name the full namespace of the role, or a namespace suffix, which will then be tried against the following standard namespace prefixes. .PP .Vb 2 \& $MyApp::TraitFor::Request::$trait_suffix \& Catalyst::TraitFor::Request::$trait_suffix .Ve .PP So for example if you set: .PP .Vb 1 \& MyApp\->request_class_traits([\*(AqFoo\*(Aq]); .Ve .PP We try each possible role in turn (and throw an error if none load) .PP .Vb 3 \& Foo \& MyApp::TraitFor::Request::Foo \& Catalyst::TraitFor::Request::Foo .Ve .PP The namespace part 'TraitFor::Request' was chosen to assist in backwards compatibility with CatalystX::RoleApplicator which previously provided these features in a stand alone package. .ie n .SS "$app\->composed_request_class" .el .SS "\f(CW$app\fP\->composed_request_class" .IX Subsection "$app->composed_request_class" This is the request class which has been composed with any request_class_traits. .ie n .SS "$c\->response_class" .el .SS "\f(CW$c\fP\->response_class" .IX Subsection "$c->response_class" Returns or sets the response class. Defaults to Catalyst::Response. .ie n .SS "$app\->response_class_traits" .el .SS "\f(CW$app\fP\->response_class_traits" .IX Subsection "$app->response_class_traits" An arrayref of Moose::Roles which are applied to the response class. You can name the full namespace of the role, or a namespace suffix, which will then be tried against the following standard namespace prefixes. .PP .Vb 2 \& $MyApp::TraitFor::Response::$trait_suffix \& Catalyst::TraitFor::Response::$trait_suffix .Ve .PP So for example if you set: .PP .Vb 1 \& MyApp\->response_class_traits([\*(AqFoo\*(Aq]); .Ve .PP We try each possible role in turn (and throw an error if none load) .PP .Vb 3 \& Foo \& MyApp::TraitFor::Response::Foo \& Catalyst::TraitFor::Responset::Foo .Ve .PP The namespace part 'TraitFor::Response' was chosen to assist in backwards compatibility with CatalystX::RoleApplicator which previously provided these features in a stand alone package. .ie n .SS "$app\->composed_response_class" .el .SS "\f(CW$app\fP\->composed_response_class" .IX Subsection "$app->composed_response_class" This is the request class which has been composed with any response_class_traits. .ie n .SS "$c\->read( [$maxlength] )" .el .SS "\f(CW$c\fP\->read( [$maxlength] )" .IX Subsection "$c->read( [$maxlength] )" Reads a chunk of data from the request body. This method is designed to be used in a while loop, reading \f(CW$maxlength\fR bytes on every call. \&\f(CW$maxlength\fR defaults to the size of the request if not specified. .PP You have to set \f(CW\*(C`MyApp\->config(parse_on_demand => 1)\*(C'\fR to use this directly. .PP Warning: If you use \fBread()\fR, Catalyst will not process the body, so you will not be able to access \s-1POST\s0 parameters or file uploads via \&\f(CW$c\fR\->request. You must handle all body parsing yourself. .ie n .SS "$c\->run" .el .SS "\f(CW$c\fP\->run" .IX Subsection "$c->run" Starts the engine. .ie n .SS "$c\->set_action( $action, $code, $namespace, $attrs )" .el .SS "\f(CW$c\fP\->set_action( \f(CW$action\fP, \f(CW$code\fP, \f(CW$namespace\fP, \f(CW$attrs\fP )" .IX Subsection "$c->set_action( $action, $code, $namespace, $attrs )" Sets an action in a given namespace. .ie n .SS "$c\->setup_actions($component)" .el .SS "\f(CW$c\fP\->setup_actions($component)" .IX Subsection "$c->setup_actions($component)" Sets up actions for a component. .ie n .SS "$c\->setup_components" .el .SS "\f(CW$c\fP\->setup_components" .IX Subsection "$c->setup_components" This method is called internally to set up the application's components. .PP It finds modules by calling the locate_components method, expands them to package names with the expand_component_module method, and then installs each component into the application. .PP The \f(CW\*(C`setup_components\*(C'\fR config option is passed to both of the above methods. .PP Installation of each component is performed by the setup_component method, below. .ie n .SS "$app\->setup_injected_components" .el .SS "\f(CW$app\fP\->setup_injected_components" .IX Subsection "$app->setup_injected_components" Called by setup_compoents to setup components that are injected. .ie n .SS "$app\->setup_injected_component( $injected_component_name, $config )" .el .SS "\f(CW$app\fP\->setup_injected_component( \f(CW$injected_component_name\fP, \f(CW$config\fP )" .IX Subsection "$app->setup_injected_component( $injected_component_name, $config )" Setup a given injected component. .ie n .SS "$app\->inject_component($MyApp_Component_name => \e%args);" .el .SS "\f(CW$app\fP\->inject_component($MyApp_Component_name => \e%args);" .IX Subsection "$app->inject_component($MyApp_Component_name => %args);" Add a component that is injected at setup: .PP .Vb 1 \& MyApp\->inject_component( \*(AqModel::Foo\*(Aq => { from_component => \*(AqCommon::Foo\*(Aq } ); .Ve .PP Must be called before \->setup. Expects a component name for your current application and \e%args where .IP "from_component" 4 .IX Item "from_component" The target component being injected into your application .IP "roles" 4 .IX Item "roles" An arrayref of Moose::Roles that are applied to your component. .PP Example .PP .Vb 5 \& MyApp\->inject_component( \& \*(AqModel::Foo\*(Aq => { \& from_component => \*(AqCommon::Model::Foo\*(Aq, \& roles => [\*(AqRole1\*(Aq, \*(AqRole2\*(Aq], \& }); .Ve .ie n .SS "$app\->inject_components" .el .SS "\f(CW$app\fP\->inject_components" .IX Subsection "$app->inject_components" Inject a list of components: .PP .Vb 9 \& MyApp\->inject_components( \& \*(AqModel::FooOne\*(Aq => { \& from_component => \*(AqCommon::Model::Foo\*(Aq, \& roles => [\*(AqRole1\*(Aq, \*(AqRole2\*(Aq], \& }, \& \*(AqModel::FooTwo\*(Aq => { \& from_component => \*(AqCommon::Model::Foo\*(Aq, \& roles => [\*(AqRole1\*(Aq, \*(AqRole2\*(Aq], \& }); .Ve .ie n .SS "$c\->locate_components( $setup_component_config )" .el .SS "\f(CW$c\fP\->locate_components( \f(CW$setup_component_config\fP )" .IX Subsection "$c->locate_components( $setup_component_config )" This method is meant to provide a list of component modules that should be setup for the application. By default, it will use Module::Pluggable. .PP Specify a \f(CW\*(C`setup_components\*(C'\fR config option to pass additional options directly to Module::Pluggable. To add additional search paths, specify a key named \&\f(CW\*(C`search_extra\*(C'\fR as an array reference. Items in the array beginning with \f(CW\*(C`::\*(C'\fR will have the application class name prepended to them. .ie n .SS "$c\->expand_component_module( $component, $setup_component_config )" .el .SS "\f(CW$c\fP\->expand_component_module( \f(CW$component\fP, \f(CW$setup_component_config\fP )" .IX Subsection "$c->expand_component_module( $component, $setup_component_config )" Components found by \f(CW\*(C`locate_components\*(C'\fR will be passed to this method, which is expected to return a list of component (package) names to be set up. .ie n .SS "$app\->delayed_setup_component" .el .SS "\f(CW$app\fP\->delayed_setup_component" .IX Subsection "$app->delayed_setup_component" Returns a coderef that points to a setup_component instance. Used internally for when you want to delay setup until the first time the component is called. .ie n .SS "$c\->setup_component" .el .SS "\f(CW$c\fP\->setup_component" .IX Subsection "$c->setup_component" .ie n .SS "$app\->config_for( $component_name )" .el .SS "\f(CW$app\fP\->config_for( \f(CW$component_name\fP )" .IX Subsection "$app->config_for( $component_name )" Return the application level configuration (which is not yet merged with any local component configuration, via \f(CW$component_class\fR\->config) for the named component or component object. Example: .PP .Vb 3 \& MyApp\->config( \& \*(AqModel::Foo\*(Aq => { a => 1, b => 2}, \& ); \& \& my $config = MyApp\->config_for(\*(AqMyApp::Model::Foo\*(Aq); .Ve .PP In this case \f(CW$config\fR is the hashref \f(CW\*(C`{a=>1, b=>2}\*(C'\fR. .PP This is also handy for looking up configuration for a plugin, to make sure you follow existing Catalyst standards for where a plugin should put its configuration. .ie n .SS "$c\->setup_dispatcher" .el .SS "\f(CW$c\fP\->setup_dispatcher" .IX Subsection "$c->setup_dispatcher" Sets up dispatcher. .ie n .SS "$c\->setup_engine" .el .SS "\f(CW$c\fP\->setup_engine" .IX Subsection "$c->setup_engine" Sets up engine. .ie n .SS "$c\->apply_default_middlewares" .el .SS "\f(CW$c\fP\->apply_default_middlewares" .IX Subsection "$c->apply_default_middlewares" Adds the following Plack middlewares to your application, since they are useful and commonly needed: .PP Plack::Middleware::LighttpdScriptNameFix (if you are using Lighttpd), Plack::Middleware::IIS6ScriptNameFix (always applied since this middleware is smart enough to conditionally apply itself). .PP We will also automatically add Plack::Middleware::ReverseProxy if we notice that your \s-1HTTP\s0 \f(CW$env\fR variable \f(CW\*(C`REMOTE_ADDR\*(C'\fR is '127.0.0.1'. This is usually an indication that your server is running behind a proxy frontend. However in 2014 this is often not the case. We preserve this code for backwards compatibility however I \fBhighly\fR recommend that if you are running the server behind a front end proxy that you clearly indicate so with the \f(CW\*(C`using_frontend_proxy\*(C'\fR configuration setting to true for your environment configurations that run behind a proxy. This way if you change your front end proxy address someday your code would inexplicably stop working as expected. .PP Additionally if we detect we are using Nginx, we add a bit of custom middleware to solve some problems with the way that server handles \f(CW$ENV\fR{\s-1PATH_INFO\s0} and \&\f(CW$ENV\fR{\s-1SCRIPT_NAME\s0}. .PP Please \fB\s-1NOTE\s0\fR that if you do use \f(CW\*(C`using_frontend_proxy\*(C'\fR the middleware is now adding via \f(CW\*(C`registered_middleware\*(C'\fR rather than this method. .PP If you are using Lighttpd or \s-1IIS6\s0 you may wish to apply these middlewares. In general this is no longer a common case but we have this here for backward compatibility. .SS "App\->psgi_app" .IX Subsection "App->psgi_app" .SS "App\->to_app" .IX Subsection "App->to_app" Returns a \s-1PSGI\s0 application code reference for the catalyst application \&\f(CW$c\fR. This is the bare application created without the \f(CW\*(C`apply_default_middlewares\*(C'\fR method called. We do however apply \f(CW\*(C`registered_middleware\*(C'\fR since those are integral to how Catalyst functions. Also, unlike starting your application with a generated server script (via Catalyst::Devel and \f(CW\*(C`catalyst.pl\*(C'\fR) we do not attempt to return a valid \s-1PSGI\s0 application using any existing \f(CW\*(C`${myapp}.psgi\*(C'\fR scripts in your \f(CW$HOME\fR directory. .PP \&\fB\s-1NOTE\s0\fR \f(CW\*(C`apply_default_middlewares\*(C'\fR was originally created when the first \s-1PSGI\s0 port was done for v5.90000. These are middlewares that are added to achieve backward compatibility with older applications. If you start your application using one of the supplied server scripts (generated with Catalyst::Devel and the project skeleton script \f(CW\*(C`catalyst.pl\*(C'\fR) we apply \f(CW\*(C`apply_default_middlewares\*(C'\fR automatically. This was done so that pre and post \s-1PSGI\s0 port applications would work the same way. .PP This is what you want to be using to retrieve the \s-1PSGI\s0 application code reference of your Catalyst application for use in a custom \fI.psgi\fR or in your own created server modules. .ie n .SS "$c\->setup_home" .el .SS "\f(CW$c\fP\->setup_home" .IX Subsection "$c->setup_home" Sets up the home directory. .ie n .SS "$c\->setup_encoding" .el .SS "\f(CW$c\fP\->setup_encoding" .IX Subsection "$c->setup_encoding" Sets up the input/output encoding. See \s-1ENCODING\s0 .SS "handle_unicode_encoding_exception" .IX Subsection "handle_unicode_encoding_exception" Hook to let you customize how encoding errors are handled. By default we just throw an exception and the default error page will pick it up. Receives a hashref of debug information. Example of call (from the Catalyst internals): .PP .Vb 5 \& my $decoded_after_fail = $c\->handle_unicode_encoding_exception({ \& param_value => $value, \& error_msg => $_, \& encoding_step => \*(Aqparams\*(Aq, \& }); .Ve .PP The calling code expects to receive a decoded string or an exception. .PP You can override this for custom handling of unicode errors. By default we just die. If you want a custom response here, one approach is to throw an \s-1HTTP\s0 style exception, instead of returning a decoded string or throwing a generic exception. .PP .Vb 4 \& sub handle_unicode_encoding_exception { \& my ($c, $params) = @_; \& HTTP::Exception::BAD_REQUEST\->throw(status_message=>$params\->{error_msg}); \& } .Ve .PP Alternatively you can 'catch' the error, stash it and write handling code later in your application: .PP .Vb 6 \& sub handle_unicode_encoding_exception { \& my ($c, $params) = @_; \& $c\->stash(BAD_UNICODE_DATA=>$params); \& # return a dummy string. \& return 1; \& } .Ve .PP NOTE: Please keep in mind that once an error like this occurs, the request setup is still ongoing, which means the state of \f(CW$c\fR and related context parts like the request and response may not be setup up correctly (since we haven't finished the setup yet). If you throw an exception the setup is aborted. .ie n .SS "$c\->setup_log" .el .SS "\f(CW$c\fP\->setup_log" .IX Subsection "$c->setup_log" Sets up log by instantiating a Catalyst::Log object and passing it to \f(CW\*(C`log()\*(C'\fR. Pass in a comma-delimited list of levels to set the log to. .PP This method also installs a \f(CW\*(C`debug\*(C'\fR method that returns a true value into the catalyst subclass if the \*(L"debug\*(R" level is passed in the comma-delimited list, or if the \f(CW$CATALYST_DEBUG\fR environment variable is set to a true value. .PP Note that if the log has already been setup, by either a previous call to \&\f(CW\*(C`setup_log\*(C'\fR or by a call such as \f(CW\*(C`_\|_PACKAGE_\|_\->log( MyLogger\->new )\*(C'\fR, that this method won't actually set up the log object. .ie n .SS "$c\->setup_plugins" .el .SS "\f(CW$c\fP\->setup_plugins" .IX Subsection "$c->setup_plugins" Sets up plugins. .ie n .SS "$c\->setup_stats" .el .SS "\f(CW$c\fP\->setup_stats" .IX Subsection "$c->setup_stats" Sets up timing statistics class. .ie n .SS "$c\->registered_plugins" .el .SS "\f(CW$c\fP\->registered_plugins" .IX Subsection "$c->registered_plugins" Returns a sorted list of the plugins which have either been stated in the import list. .PP If passed a given plugin name, it will report a boolean value indicating whether or not that plugin is loaded. A fully qualified name is required if the plugin name does not begin with \f(CW\*(C`Catalyst::Plugin::\*(C'\fR. .PP .Vb 3 \& if ($c\->registered_plugins(\*(AqSome::Plugin\*(Aq)) { \& ... \& } .Ve .SS "default_middleware" .IX Subsection "default_middleware" Returns a list of instantiated \s-1PSGI\s0 middleware objects which is the default middleware that is active for this application (taking any configuration options into account, excluding your custom added middleware via the \f(CW\*(C`psgi_middleware\*(C'\fR configuration option). You can override this method if you wish to change the default middleware (although do so at risk since some middleware is vital to application function.) .PP The current default middleware list is: .PP .Vb 7 \& Catalyst::Middleware::Stash \& Plack::Middleware::HTTPExceptions \& Plack::Middleware::RemoveRedundantBody \& Plack::Middleware::FixMissingBodyInRedirect \& Plack::Middleware::ContentLength \& Plack::Middleware::MethodOverride \& Plack::Middleware::Head .Ve .PP If the configuration setting \f(CW\*(C`using_frontend_proxy\*(C'\fR is true we add: .PP .Vb 1 \& Plack::Middleware::ReverseProxy .Ve .PP If the configuration setting \f(CW\*(C`using_frontend_proxy_path\*(C'\fR is true we add: .PP .Vb 1 \& Plack::Middleware::ReverseProxyPath .Ve .PP But \fB\s-1NOTE\s0\fR that Plack::Middleware::ReverseProxyPath is not a dependency of the Catalyst distribution so if you want to use this option you should add it to your project distribution file. .PP These middlewares will be added at \*(L"setup_middleware\*(R" during the \&\*(L"setup\*(R" phase of application startup. .SS "registered_middlewares" .IX Subsection "registered_middlewares" Read only accessor that returns an array of all the middleware in the order that they were added (which is the \s-1REVERSE\s0 of the order they will be applied). .PP The values returned will be either instances of Plack::Middleware or of a compatible interface, or a coderef, which is assumed to be inlined middleware .SS "setup_middleware (?@middleware)" .IX Subsection "setup_middleware (?@middleware)" Read configuration information stored in configuration key \f(CW\*(C`psgi_middleware\*(C'\fR or from passed \f(CW@args\fR. .PP See under \*(L"\s-1CONFIGURATION\*(R"\s0 information regarding \f(CW\*(C`psgi_middleware\*(C'\fR and how to use it to enable Plack::Middleware .PP This method is automatically called during 'setup' of your application, so you really don't need to invoke it. However you may do so if you find the idea of loading middleware via configuration weird :). For example: .PP .Vb 1 \& package MyApp; \& \& use Catalyst; \& \& _\|_PACKAGE_\|_\->setup_middleware(\*(AqHead\*(Aq); \& _\|_PACKAGE_\|_\->setup; .Ve .PP When we read middleware definitions from configuration, we reverse the list which sounds odd but is likely how you expect it to work if you have prior experience with Plack::Builder or if you previously used the plugin Catalyst::Plugin::EnableMiddleware (which is now considered deprecated) .PP So basically your middleware handles an incoming request from the first registered middleware, down and handles the response from the last middleware up. .SS "registered_data_handlers" .IX Subsection "registered_data_handlers" A read only copy of registered Data Handlers returned as a Hash, where each key is a content type and each value is a subref that attempts to decode that content type. .SS "setup_data_handlers (?@data_handler)" .IX Subsection "setup_data_handlers (?@data_handler)" Read configuration information stored in configuration key \f(CW\*(C`data_handlers\*(C'\fR or from passed \f(CW@args\fR. .PP See under \*(L"\s-1CONFIGURATION\*(R"\s0 information regarding \f(CW\*(C`data_handlers\*(C'\fR. .PP This method is automatically called during 'setup' of your application, so you really don't need to invoke it. .SS "default_data_handlers" .IX Subsection "default_data_handlers" Default Data Handlers that come bundled with Catalyst. Currently there are only two default data handlers, for 'application/json' and an alternative to \&'application/x\-www\-form\-urlencoded' which supposed nested form parameters via CGI::Struct or via CGI::Struct::XS \s-1IF\s0 you've installed it. .PP The 'application/json' data handler is used to parse incoming \s-1JSON\s0 into a Perl data structure. It uses JSON::MaybeXS. This allows you to fail back to \&\s-1JSON::PP\s0, which is a Pure Perl \s-1JSON\s0 decoder, and has the smallest dependency impact. .PP Because we don't wish to add more dependencies to Catalyst, if you wish to use this new feature we recommend installing Cpanel::JSON::XS in order to get the best performance. You should add either to your dependency list (Makefile.PL, dist.ini, cpanfile, etc.) .ie n .SS "$c\->stack" .el .SS "\f(CW$c\fP\->stack" .IX Subsection "$c->stack" Returns an arrayref of the internal execution stack (actions that are currently executing). .ie n .SS "$c\->stats" .el .SS "\f(CW$c\fP\->stats" .IX Subsection "$c->stats" Returns the current timing statistics object. By default Catalyst uses Catalyst::Stats, but can be set otherwise with stats_class. .PP Even if \-Stats is not enabled, the stats object is still available. By enabling it with \f(CW\*(C`$c\->stats\->enabled(1)\*(C'\fR, it can be used to profile explicitly, although MyApp.pm still won't profile nor output anything by itself. .ie n .SS "$c\->stats_class" .el .SS "\f(CW$c\fP\->stats_class" .IX Subsection "$c->stats_class" Returns or sets the stats (timing statistics) class. Catalyst::Stats is used by default. .ie n .SS "$app\->stats_class_traits" .el .SS "\f(CW$app\fP\->stats_class_traits" .IX Subsection "$app->stats_class_traits" A arrayref of Moose::Roles that are applied to the stats_class before creating it. .ie n .SS "$app\->composed_stats_class" .el .SS "\f(CW$app\fP\->composed_stats_class" .IX Subsection "$app->composed_stats_class" this is the stats_class composed with any 'stats_class_traits'. You can name the full namespace of the role, or a namespace suffix, which will then be tried against the following standard namespace prefixes. .PP .Vb 2 \& $MyApp::TraitFor::Stats::$trait_suffix \& Catalyst::TraitFor::Stats::$trait_suffix .Ve .PP So for example if you set: .PP .Vb 1 \& MyApp\->stats_class_traits([\*(AqFoo\*(Aq]); .Ve .PP We try each possible role in turn (and throw an error if none load) .PP .Vb 3 \& Foo \& MyApp::TraitFor::Stats::Foo \& Catalyst::TraitFor::Stats::Foo .Ve .PP The namespace part 'TraitFor::Stats' was chosen to assist in backwards compatibility with CatalystX::RoleApplicator which previously provided these features in a stand alone package. .ie n .SS "$c\->use_stats" .el .SS "\f(CW$c\fP\->use_stats" .IX Subsection "$c->use_stats" Returns 1 when stats collection is enabled. .PP Note that this is a static method, not an accessor and should be overridden by declaring \f(CW\*(C`sub use_stats { 1 }\*(C'\fR in your MyApp.pm, not by calling \f(CW\*(C`$c\->use_stats(1)\*(C'\fR. .ie n .SS "$c\->write( $data )" .el .SS "\f(CW$c\fP\->write( \f(CW$data\fP )" .IX Subsection "$c->write( $data )" Writes \f(CW$data\fR to the output stream. When using this method directly, you will need to manually set the \f(CW\*(C`Content\-Length\*(C'\fR header to the length of your output data, if known. .SS "version" .IX Subsection "version" Returns the Catalyst version number. Mostly useful for \*(L"powered by\*(R" messages in template systems. .SH "CONFIGURATION" .IX Header "CONFIGURATION" There are a number of 'base' config variables which can be set: .IP "\(bu" 4 \&\f(CW\*(C`always_catch_http_exceptions\*(C'\fR \- As of version 5.90060 Catalyst rethrows errors conforming to the interface described by Plack::Middleware::HTTPExceptions and lets the middleware deal with it. Set true to get the deprecated behaviour and have Catalyst catch \s-1HTTP\s0 exceptions. .IP "\(bu" 4 \&\f(CW\*(C`default_model\*(C'\fR \- The default model picked if you say \f(CW\*(C`$c\->model\*(C'\fR. See \*(L"$c\->model($name)\*(R". .IP "\(bu" 4 \&\f(CW\*(C`default_view\*(C'\fR \- The default view to be rendered or returned when \f(CW\*(C`$c\->view\*(C'\fR is called. See \*(L"$c\->view($name)\*(R". .IP "\(bu" 4 \&\f(CW\*(C`disable_component_resolution_regex_fallback\*(C'\fR \- Turns off the deprecated component resolution functionality so that if any of the component methods (e.g. \f(CW\*(C`$c\->controller(\*(AqFoo\*(Aq)\*(C'\fR) are called then regex search will not be attempted on string values and instead \f(CW\*(C`undef\*(C'\fR will be returned. .IP "\(bu" 4 \&\f(CW\*(C`home\*(C'\fR \- The application home directory. In an uninstalled application, this is the top level application directory. In an installed application, this will be the directory containing \f(CW\*(C`MyApp.pm\*(C'\fR. .IP "\(bu" 4 \&\f(CW\*(C`ignore_frontend_proxy\*(C'\fR \- See \*(L"\s-1PROXY SUPPORT\*(R"\s0 .IP "\(bu" 4 \&\f(CW\*(C`name\*(C'\fR \- The name of the application in debug messages and the debug and welcome screens .IP "\(bu" 4 \&\f(CW\*(C`parse_on_demand\*(C'\fR \- The request body (for example file uploads) will not be parsed until it is accessed. This allows you to (for example) check authentication (and reject the upload) before actually receiving all the data. See \*(L"ON-DEMAND \s-1PARSER\*(R"\s0 .IP "\(bu" 4 \&\f(CW\*(C`root\*(C'\fR \- The root directory for templates. Usually this is just a subdirectory of the home directory, but you can set it to change the templates to a different directory. .IP "\(bu" 4 \&\f(CW\*(C`search_extra\*(C'\fR \- Array reference passed to Module::Pluggable to for additional namespaces from which components will be loaded (and constructed and stored in \&\f(CW\*(C`$c\->components\*(C'\fR). .IP "\(bu" 4 \&\f(CW\*(C`show_internal_actions\*(C'\fR \- If true, causes internal actions such as \f(CW\*(C`_DISPATCH\*(C'\fR to be shown in hit debug tables in the test server. .IP "\(bu" 4 \&\f(CW\*(C`use_request_uri_for_path\*(C'\fR \- Controls if the \f(CW\*(C`REQUEST_URI\*(C'\fR or \f(CW\*(C`PATH_INFO\*(C'\fR environment variable should be used for determining the request path. .Sp Most web server environments pass the requested path to the application using environment variables, from which Catalyst has to reconstruct the request base (i.e. the top level path to / in the application, exposed as \f(CW\*(C`$c\->request\->base\*(C'\fR) and the request path below that base. .Sp There are two methods of doing this, both of which have advantages and disadvantages. Which method is used is determined by the \f(CW\*(C`$c\->config(use_request_uri_for_path)\*(C'\fR setting (which can either be true or false). .RS 4 .IP "use_request_uri_for_path => 0" 4 .IX Item "use_request_uri_for_path => 0" This is the default (and the) traditional method that Catalyst has used for determining the path information. The path is generated from a combination of the \f(CW\*(C`PATH_INFO\*(C'\fR and \f(CW\*(C`SCRIPT_NAME\*(C'\fR environment variables. The allows the application to behave correctly when \f(CW\*(C`mod_rewrite\*(C'\fR is being used to redirect requests into the application, as these variables are adjusted by mod_rewrite to take account for the redirect. .Sp However this method has the major disadvantage that it is impossible to correctly decode some elements of the path, as \s-1RFC 3875\s0 says: "\f(CW\*(C`Unlike a URI path, the PATH_INFO is not URL\-encoded, and cannot contain path\-segment parameters.\*(C'\fR" This means \s-1PATH_INFO\s0 is \fBalways\fR decoded, and therefore Catalyst can't distinguish / vs \f(CW%2F\fR in paths (in addition to other encoded values). .IP "use_request_uri_for_path => 1" 4 .IX Item "use_request_uri_for_path => 1" This method uses the \f(CW\*(C`REQUEST_URI\*(C'\fR and \f(CW\*(C`SCRIPT_NAME\*(C'\fR environment variables. As \f(CW\*(C`REQUEST_URI\*(C'\fR is never decoded, this means that applications using this mode can correctly handle URIs including the \f(CW%2F\fR character (i.e. with \f(CW\*(C`AllowEncodedSlashes\*(C'\fR set to \f(CW\*(C`On\*(C'\fR in Apache). .Sp Given that this method of path resolution is provably more correct, it is recommended that you use this unless you have a specific need to deploy your application in a non-standard environment, and you are aware of the implications of not being able to handle encoded \s-1URI\s0 paths correctly. .Sp However it also means that in a number of cases when the app isn't installed directly at a path, but instead is having paths rewritten into it (e.g. as a .cgi/fcgi in a public_html directory, with mod_rewrite in a \&.htaccess file, or when \s-1SSI\s0 is used to rewrite pages into the app, or when sub-paths of the app are exposed at other URIs than that which the app is 'normally' based at with \f(CW\*(C`mod_rewrite\*(C'\fR), the resolution of \&\f(CW\*(C`$c\->request\->base\*(C'\fR will be incorrect. .RE .RS 4 .RE .IP "\(bu" 4 \&\f(CW\*(C`using_frontend_proxy\*(C'\fR \- See \*(L"\s-1PROXY SUPPORT\*(R"\s0. .IP "\(bu" 4 \&\f(CW\*(C`using_frontend_proxy_path\*(C'\fR \- Enabled Plack::Middleware::ReverseProxyPath on your application (if installed, otherwise log an error). This is useful if your application is not running on the \&'root' (or /) of your host server. \fB\s-1NOTE\s0\fR if you use this feature you should add the required middleware to your project dependency list since its not automatically a dependency of Catalyst. This has been done since not all people need this feature and we wish to restrict the growth of Catalyst dependencies. .IP "\(bu" 4 \&\f(CW\*(C`encoding\*(C'\fR \- See \*(L"\s-1ENCODING\*(R"\s0 .Sp This now defaults to '\s-1UTF\-8\s0'. You my turn it off by setting this configuration value to undef. .IP "\(bu" 4 \&\f(CW\*(C`abort_chain_on_error_fix\*(C'\fR .Sp Defaults to true. .Sp When there is an error in an action chain, the default behavior is to abort the processing of the remaining actions to avoid running them when the application is in an unexpected state. .Sp Before version 5.90070, the default used to be false. To keep the old behaviour, you can explicitly set the value to false. E.g. .Sp .Vb 1 \& _\|_PACKAGE_\|_\->config(abort_chain_on_error_fix => 0); .Ve .Sp If this setting is set to false, then the remaining actions are performed and the error is caught at the end of the chain. .IP "\(bu" 4 \&\f(CW\*(C`use_hash_multivalue_in_request\*(C'\fR .Sp In Catalyst::Request the methods \f(CW\*(C`query_parameters\*(C'\fR, \f(CW\*(C`body_parametes\*(C'\fR and \f(CW\*(C`parameters\*(C'\fR return a hashref where values might be scalar or an arrayref depending on the incoming data. In many cases this can be undesirable as it leads one to writing defensive code like the following: .Sp .Vb 3 \& my ($val) = ref($c\->req\->parameters\->{a}) ? \& @{$c\->req\->parameters\->{a}} : \& $c\->req\->parameters\->{a}; .Ve .Sp Setting this configuration item to true will make Catalyst populate the attributes underlying these methods with an instance of Hash::MultiValue which is used by Plack::Request and others to solve this very issue. You may prefer this behavior to the default, if so enable this option (be warned if you enable it in a legacy application we are not sure if it is completely backwardly compatible). .IP "\(bu" 4 \&\f(CW\*(C`skip_complex_post_part_handling\*(C'\fR .Sp When creating body parameters from a \s-1POST,\s0 if we run into a multipart \s-1POST\s0 that does not contain uploads, but instead contains inlined complex data (very uncommon) we cannot reliably convert that into field => value pairs. So instead we create an instance of Catalyst::Request::PartData. If this causes issue for you, you can disable this by setting \f(CW\*(C`skip_complex_post_part_handling\*(C'\fR to true (default is false). .IP "\(bu" 4 \&\f(CW\*(C`skip_body_param_unicode_decoding\*(C'\fR .Sp Generally we decode incoming \s-1POST\s0 params based on your declared encoding (the default for this is to decode \s-1UTF\-8\s0). If this is causing you trouble and you do not wish to turn all encoding support off (with the \f(CW\*(C`encoding\*(C'\fR configuration parameter) you may disable this step atomically by setting this configuration parameter to true. .IP "\(bu" 4 \&\f(CW\*(C`do_not_decode_query\*(C'\fR .Sp If true, then do not try to character decode any wide characters in your request \s-1URL\s0 query or keywords. Most readings of the relevant specifications suggest these should be UTF\-* encoded, which is the default that Catalyst will use, however if you are creating a lot of URLs manually or have external evil clients, this might cause you trouble. If you find the changes introduced in Catalyst version 5.90080+ break some of your query code, you may disable the \s-1UTF\-8\s0 decoding globally using this configuration. .Sp This setting takes precedence over \f(CW\*(C`default_query_encoding\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`do_not_check_query_encoding\*(C'\fR .Sp Catalyst versions 5.90080 \- 5.90106 would decode query parts of an incoming request but would not raise an exception when the decoding failed due to incorrect unicode. It now does, but if this change is giving you trouble you may disable it by setting this configuration to true. .IP "\(bu" 4 \&\f(CW\*(C`default_query_encoding\*(C'\fR .Sp By default we decode query and keywords in your request \s-1URL\s0 using \s-1UTF\-8,\s0 which is our reading of the relevant specifications. This setting allows one to specify a fixed value for how to decode your query. You might need this if you are doing a lot of custom encoding of your URLs and not using \s-1UTF\-8.\s0 .IP "\(bu" 4 \&\f(CW\*(C`use_chained_args_0_special_case\*(C'\fR .Sp In older versions of Catalyst, when more than one action matched the same path \&\s-1AND\s0 all those matching actions declared \fBArgs\fR\|(0), we'd break the tie by choosing the first action defined. We now normalized how \fBArgs\fR\|(0) works so that it follows the same rule as Args(N), which is to say when we need to break a tie we choose the \s-1LAST\s0 action defined. If this breaks your code and you don't have time to update to follow the new normalized approach, you may set this value to true and it will globally revert to the original chaining behavior. .IP "\(bu" 4 \&\f(CW\*(C`psgi_middleware\*(C'\fR \- See \*(L"\s-1PSGI MIDDLEWARE\*(R"\s0. .IP "\(bu" 4 \&\f(CW\*(C`data_handlers\*(C'\fR \- See \*(L"\s-1DATA HANDLERS\*(R"\s0. .IP "\(bu" 4 \&\f(CW\*(C`stats_class_traits\*(C'\fR .Sp An arrayref of Moose::Roles that get composed into your stats class. .IP "\(bu" 4 \&\f(CW\*(C`request_class_traits\*(C'\fR .Sp An arrayref of Moose::Roles that get composed into your request class. .IP "\(bu" 4 \&\f(CW\*(C`response_class_traits\*(C'\fR .Sp An arrayref of Moose::Roles that get composed into your response class. .IP "\(bu" 4 \&\f(CW\*(C`inject_components\*(C'\fR .Sp A Hashref of Catalyst::Component subclasses that are 'injected' into configuration. For example: .Sp .Vb 10 \& MyApp\->config({ \& inject_components => { \& \*(AqController::Err\*(Aq => { from_component => \*(AqLocal::Controller::Errors\*(Aq }, \& \*(AqModel::Zoo\*(Aq => { from_component => \*(AqLocal::Model::Foo\*(Aq }, \& \*(AqModel::Foo\*(Aq => { from_component => \*(AqLocal::Model::Foo\*(Aq, roles => [\*(AqTestRole\*(Aq] }, \& }, \& \*(AqController::Err\*(Aq => { a => 100, b=>200, namespace=>\*(Aqerror\*(Aq }, \& \*(AqModel::Zoo\*(Aq => { a => 2 }, \& \*(AqModel::Foo\*(Aq => { a => 100 }, \& }); .Ve .Sp Generally Catalyst looks for components in your Model/View or Controller directories. However for cases when you which to use an existing component and you don't need any customization (where for when you can apply a role to customize it) you may inject those components into your application. Please note any configuration should be done 'in the normal way', with a key under configuration named after the component affix, as in the above example. .Sp Using this type of injection allows you to construct significant amounts of your application with only configuration!. This may or may not lead to increased code understanding. .Sp Please not you may also call the \->inject_components application method as well, although you must do so \s-1BEFORE\s0 setup. .SH "EXCEPTIONS" .IX Header "EXCEPTIONS" Generally when you throw an exception inside an Action (or somewhere in your stack, such as in a model that an Action is calling) that exception is caught by Catalyst and unless you either catch it yourself (via eval or something like Try::Tiny or by reviewing the \*(L"error\*(R" stack, it will eventually reach \*(L"finalize_errors\*(R" and return either the debugging error stack page, or the default error page. However, if your exception can be caught by Plack::Middleware::HTTPExceptions, Catalyst will instead rethrow it so that it can be handled by that middleware (which is part of the default middleware). For example this would allow .PP .Vb 1 \& use HTTP::Throwable::Factory \*(Aqhttp_throw\*(Aq; \& \& sub throws_exception :Local { \& my ($self, $c) = @_; \& \& http_throw(SeeOther => { location => \& $c\->uri_for($self\->action_for(\*(Aqredirect\*(Aq)) }); \& \& } .Ve .SH "INTERNAL ACTIONS" .IX Header "INTERNAL ACTIONS" Catalyst uses internal actions like \f(CW\*(C`_DISPATCH\*(C'\fR, \f(CW\*(C`_BEGIN\*(C'\fR, \f(CW\*(C`_AUTO\*(C'\fR, \&\f(CW\*(C`_ACTION\*(C'\fR, and \f(CW\*(C`_END\*(C'\fR. These are by default not shown in the private action table, but you can make them visible with a config parameter. .PP .Vb 1 \& MyApp\->config(show_internal_actions => 1); .Ve .SH "ON-DEMAND PARSER" .IX Header "ON-DEMAND PARSER" The request body is usually parsed at the beginning of a request, but if you want to handle input yourself, you can enable on-demand parsing with a config parameter. .PP .Vb 1 \& MyApp\->config(parse_on_demand => 1); .Ve .SH "PROXY SUPPORT" .IX Header "PROXY SUPPORT" Many production servers operate using the common double-server approach, with a lightweight frontend web server passing requests to a larger backend server. An application running on the backend server must deal with two problems: the remote user always appears to be \f(CW127.0.0.1\fR and the server's hostname will appear to be \f(CW\*(C`localhost\*(C'\fR regardless of the virtual host that the user connected through. .PP Catalyst will automatically detect this situation when you are running the frontend and backend servers on the same machine. The following changes are made to the request. .PP .Vb 2 \& $c\->req\->address is set to the user\*(Aqs real IP address, as read from \& the HTTP X\-Forwarded\-For header. \& \& The host value for $c\->req\->base and $c\->req\->uri is set to the real \& host, as read from the HTTP X\-Forwarded\-Host header. .Ve .PP Additionally, you may be running your backend application on an insecure connection (port 80) while your frontend proxy is running under \s-1SSL.\s0 If there is a discrepancy in the ports, use the \s-1HTTP\s0 header \f(CW\*(C`X\-Forwarded\-Port\*(C'\fR to tell Catalyst what port the frontend listens on. This will allow all URIs to be created properly. .PP In the case of passing in: .PP .Vb 1 \& X\-Forwarded\-Port: 443 .Ve .PP All calls to \f(CW\*(C`uri_for\*(C'\fR will result in an https link, as is expected. .PP Obviously, your web server must support these headers for this to work. .PP In a more complex server farm environment where you may have your frontend proxy server(s) on different machines, you will need to set a configuration option to tell Catalyst to read the proxied data from the headers. .PP .Vb 1 \& MyApp\->config(using_frontend_proxy => 1); .Ve .PP If you do not wish to use the proxy support at all, you may set: .PP .Vb 1 \& MyApp\->config(ignore_frontend_proxy => 0); .Ve .SS "Note about psgi files" .IX Subsection "Note about psgi files" Note that if you supply your own .psgi file, calling \&\f(CW\*(C`MyApp\->psgi_app(@_);\*(C'\fR, then \fBthis will not happen automatically\fR. .PP You either need to apply Plack::Middleware::ReverseProxy yourself in your psgi, for example: .PP .Vb 4 \& builder { \& enable "Plack::Middleware::ReverseProxy"; \& MyApp\->psgi_app \& }; .Ve .PP This will unconditionally add the ReverseProxy support, or you need to call \&\f(CW\*(C`$app = MyApp\->apply_default_middlewares($app)\*(C'\fR (to conditionally apply the support depending upon your config). .PP See Catalyst::PSGI for more information. .SH "THREAD SAFETY" .IX Header "THREAD SAFETY" Catalyst has been tested under Apache 2's threading \f(CW\*(C`mpm_worker\*(C'\fR, \&\f(CW\*(C`mpm_winnt\*(C'\fR, and the standalone forking \s-1HTTP\s0 server on Windows. We believe the Catalyst core to be thread-safe. .PP If you plan to operate in a threaded environment, remember that all other modules you are using must also be thread-safe. Some modules, most notably DBD::SQLite, are not thread-safe. .SH "DATA HANDLERS" .IX Header "DATA HANDLERS" The Catalyst::Request object uses HTTP::Body to populate 'classic' \s-1HTML\s0 form parameters and \s-1URL\s0 search query fields. However it has become common for various alternative content types to be \s-1PUT\s0 or POSTed to your controllers and actions. People working on RESTful APIs, or using \s-1AJAX\s0 often use \s-1JSON, XML\s0 and other content types when communicating with an application server. In order to better support this use case, Catalyst defines a global configuration option, \f(CW\*(C`data_handlers\*(C'\fR, which lets you associate a content type with a coderef that parses that content type into something Perl can readily access. .PP .Vb 1 \& package MyApp::Web; \& \& use Catalyst; \& use JSON::MaybeXS; \& \& _\|_PACKAGE_\|_\->config( \& data_handlers => { \& \*(Aqapplication/json\*(Aq => sub { local $/; decode_json $_\->getline }, \& }, \& ## Any other configuration. \& ); \& \& _\|_PACKAGE_\|_\->setup; .Ve .PP By default Catalyst comes with a generic \s-1JSON\s0 data handler similar to the example given above, which uses JSON::MaybeXS to provide either \s-1JSON::PP\s0 (a pure Perl, dependency free \s-1JSON\s0 parser) or Cpanel::JSON::XS if you have it installed (if you want the faster \s-1XS\s0 parser, add it to you project Makefile.PL or dist.ini, cpanfile, etc.) .PP The \f(CW\*(C`data_handlers\*(C'\fR configuration is a hashref whose keys are \s-1HTTP\s0 Content-Types (matched against the incoming request type using a regexp such as to be case insensitive) and whose values are coderefs that receive a localized version of \&\f(CW$_\fR which is a filehandle object pointing to received body. .PP This feature is considered an early access release and we reserve the right to alter the interface in order to provide a performant and secure solution to alternative request body content. Your reports welcomed! .SH "PSGI MIDDLEWARE" .IX Header "PSGI MIDDLEWARE" You can define middleware, defined as Plack::Middleware or a compatible interface in configuration. Your middleware definitions are in the form of an arrayref under the configuration key \f(CW\*(C`psgi_middleware\*(C'\fR. Here's an example with details to follow: .PP .Vb 1 \& package MyApp::Web; \& \& use Catalyst; \& use Plack::Middleware::StackTrace; \& \& my $stacktrace_middleware = Plack::Middleware::StackTrace\->new; \& \& _\|_PACKAGE_\|_\->config( \& \*(Aqpsgi_middleware\*(Aq, [ \& \*(AqDebug\*(Aq, \& \*(Aq+MyApp::Custom\*(Aq, \& $stacktrace_middleware, \& \*(AqSession\*(Aq => {store => \*(AqFile\*(Aq}, \& sub { \& my $app = shift; \& return sub { \& my $env = shift; \& $env\->{myapp.customkey} = \*(Aqhelloworld\*(Aq; \& $app\->($env); \& }, \& }, \& ], \& ); \& \& _\|_PACKAGE_\|_\->setup; .Ve .PP So the general form is: .PP .Vb 1 \& _\|_PACKAGE_\|_\->config(psgi_middleware => \e@middleware_definitions); .Ve .PP Where \f(CW@middleware\fR is one or more of the following, applied in the \s-1REVERSE\s0 of the order listed (to make it function similarly to Plack::Builder: .PP Alternatively, you may also define middleware by calling the \*(L"setup_middleware\*(R" package method: .PP .Vb 1 \& package MyApp::Web; \& \& use Catalyst; \& \& _\|_PACKAGE_\|_\->setup_middleware( \e@middleware_definitions); \& _\|_PACKAGE_\|_\->setup; .Ve .PP In the case where you do both (use 'setup_middleware' and configuration) the package call to setup_middleware will be applied earlier (in other words its middleware will wrap closer to the application). Keep this in mind since in some cases the order of middleware is important. .PP The two approaches are not exclusive. .IP "Middleware Object" 4 .IX Item "Middleware Object" An already initialized object that conforms to the Plack::Middleware specification: .Sp .Vb 1 \& my $stacktrace_middleware = Plack::Middleware::StackTrace\->new; \& \& _\|_PACKAGE_\|_\->config( \& \*(Aqpsgi_middleware\*(Aq, [ \& $stacktrace_middleware, \& ]); .Ve .IP "coderef" 4 .IX Item "coderef" A coderef that is an inlined middleware: .Sp .Vb 10 \& _\|_PACKAGE_\|_\->config( \& \*(Aqpsgi_middleware\*(Aq, [ \& sub { \& my $app = shift; \& return sub { \& my $env = shift; \& if($env\->{PATH_INFO} =~m/forced/) { \& Plack::App::File \& \->new(file=>TestApp\->path_to(qw/share static forced.txt/)) \& \->call($env); \& } else { \& return $app\->($env); \& } \& }, \& }, \& ]); .Ve .IP "a scalar" 4 .IX Item "a scalar" We assume the scalar refers to a namespace after normalizing it using the following rules: .Sp (1) If the scalar is prefixed with a \*(L"+\*(R" (as in \f(CW\*(C`+MyApp::Foo\*(C'\fR) then the full string is assumed to be 'as is', and we just install and use the middleware. .Sp (2) If the scalar begins with \*(L"Plack::Middleware\*(R" or your application namespace (the package name of your Catalyst application subclass), we also assume then that it is a full namespace, and use it. .Sp (3) Lastly, we then assume that the scalar is a partial namespace, and attempt to resolve it first by looking for it under your application namespace (for example if you application is \*(L"MyApp::Web\*(R" and the scalar is \*(L"MyMiddleware\*(R", we'd look under \*(L"MyApp::Web::Middleware::MyMiddleware\*(R") and if we don't find it there, we will then look under the regular Plack::Middleware namespace (i.e. for the previous we'd try \*(L"Plack::Middleware::MyMiddleware\*(R"). We look under your application namespace first to let you 'override' common Plack::Middleware locally, should you find that a good idea. .Sp Examples: .Sp .Vb 1 \& package MyApp::Web; \& \& _\|_PACKAGE_\|_\->config( \& \*(Aqpsgi_middleware\*(Aq, [ \& \*(AqDebug\*(Aq, ## MyAppWeb::Middleware::Debug\->wrap or Plack::Middleware::Debug\->wrap \& \*(AqPlack::Middleware::Stacktrace\*(Aq, ## Plack::Middleware::Stacktrace\->wrap \& \*(Aq+MyApp::Custom\*(Aq, ## MyApp::Custom\->wrap \& ], \& ); .Ve .IP "a scalar followed by a hashref" 4 .IX Item "a scalar followed by a hashref" Just like the previous, except the following \f(CW\*(C`HashRef\*(C'\fR is used as arguments to initialize the middleware object. .Sp .Vb 4 \& _\|_PACKAGE_\|_\->config( \& \*(Aqpsgi_middleware\*(Aq, [ \& \*(AqSession\*(Aq => {store => \*(AqFile\*(Aq}, \& ]); .Ve .PP Please see \s-1PSGI\s0 for more on middleware. .SH "ENCODING" .IX Header "ENCODING" Starting in Catalyst version 5.90080 encoding is automatically enabled and set to encode all body responses to \s-1UTF8\s0 when possible and applicable. Following is documentation on this process. If you are using an older version of Catalyst you should review documentation for that version since a lot has changed. .PP By default encoding is now '\s-1UTF\-8\s0'. You may turn it off by setting the encoding configuration to undef. .PP .Vb 1 \& MyApp\->config(encoding => undef); .Ve .PP This is recommended for temporary backwards compatibility only. .PP To turn it off for a single request use the clear_encoding method to turn off encoding for this request. This can be useful when you are setting the body to be an arbitrary block of bytes, especially if that block happens to be a block of \s-1UTF8\s0 text. .PP Encoding is automatically applied when the content-type is set to a type that can be encoded. Currently we encode when the content type matches the following regular expression: .PP .Vb 1 \& $content_type =~ /^text|xml$|javascript$/ .Ve .PP Encoding is set on the application, but it is copied to the context object so that you can override it on a request basis. .PP Be default we don't automatically encode 'application/json' since the most common approaches to generating this type of response (Either via Catalyst::View::JSON or Catalyst::Action::REST) will do so already and we want to avoid double encoding issues. .PP If you are producing \s-1JSON\s0 response in an unconventional manner (such as via a template or manual strings) you should perform the \s-1UTF8\s0 encoding manually as well such as to conform to the \s-1JSON\s0 specification. .PP \&\s-1NOTE:\s0 We also examine the value of \f(CW$c\fR\->response\->content_encoding. If you set this (like for example 'gzip', and manually gzipping the body) we assume that you have done all the necessary encoding yourself, since we cannot encode the gzipped contents. If you use a plugin like Catalyst::Plugin::Compress you need to update to a modern version in order to have this function correctly with the new \s-1UTF8\s0 encoding code, or you can use Plack::Middleware::Deflater or (probably best) do your compression on a front end proxy. .SS "Methods" .IX Subsection "Methods" .IP "encoding" 4 .IX Item "encoding" Returns an instance of an \f(CW\*(C`Encode\*(C'\fR encoding .Sp .Vb 1 \& print $c\->encoding\->name .Ve .IP "handle_unicode_encoding_exception ($exception_context)" 4 .IX Item "handle_unicode_encoding_exception ($exception_context)" Method called when decoding process for a request fails. .Sp An \f(CW$exception_context\fR hashref is provided to allow you to override the behaviour of your application when given data with incorrect encodings. .Sp The default method throws exceptions in the case of invalid request parameters (resulting in a 500 error), but ignores errors in upload filenames. .Sp The keys passed in the \f(CW$exception_context\fR hash are: .RS 4 .IP "param_value" 4 .IX Item "param_value" The value which was not able to be decoded. .IP "error_msg" 4 .IX Item "error_msg" The exception received from Encode. .IP "encoding_step" 4 .IX Item "encoding_step" What type of data was being decoded. Valid values are (currently) \&\f(CW\*(C`params\*(C'\fR \- for request parameters / arguments / captures and \f(CW\*(C`uploads\*(C'\fR \- for request upload filenames. .RE .RS 4 .RE .SH "SUPPORT" .IX Header "SUPPORT" \&\s-1IRC:\s0 .PP .Vb 1 \& Join #catalyst on irc.perl.org. .Ve .PP Mailing Lists: .PP .Vb 2 \& http://lists.scsys.co.uk/cgi\-bin/mailman/listinfo/catalyst \& http://lists.scsys.co.uk/cgi\-bin/mailman/listinfo/catalyst\-dev .Ve .PP Web: .PP .Vb 1 \& http://catalyst.perl.org .Ve .PP Wiki: .PP .Vb 1 \& http://dev.catalyst.perl.org .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" .SS "Task::Catalyst \- All you need to start with Catalyst" .IX Subsection "Task::Catalyst - All you need to start with Catalyst" .SS "Catalyst::Manual \- The Catalyst Manual" .IX Subsection "Catalyst::Manual - The Catalyst Manual" .SS "Catalyst::Component, Catalyst::Controller \- Base classes for components" .IX Subsection "Catalyst::Component, Catalyst::Controller - Base classes for components" .SS "Catalyst::Engine \- Core engine" .IX Subsection "Catalyst::Engine - Core engine" .SS "Catalyst::Log \- Log class." .IX Subsection "Catalyst::Log - Log class." .SS "Catalyst::Request \- Request object" .IX Subsection "Catalyst::Request - Request object" .SS "Catalyst::Response \- Response object" .IX Subsection "Catalyst::Response - Response object" .SS "Catalyst::Test \- The test suite." .IX Subsection "Catalyst::Test - The test suite." .SH "PROJECT FOUNDER" .IX Header "PROJECT FOUNDER" sri: Sebastian Riedel .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" abw: Andy Wardley .PP acme: Leon Brocard .PP abraxxa: Alexander Hartmaier .PP andrewalker: André Walker .PP Andrew Bramble .PP Andrew Ford .PP Andrew Ruthven .PP andyg: Andy Grundman .PP audreyt: Audrey Tang .PP bricas: Brian Cassidy .PP Caelum: Rafael Kitover .PP chansen: Christian Hansen .PP Chase Venters .PP chicks: Christopher Hicks .PP Chisel Wright .PP Danijel Milicevic .PP davewood: David Schmidt .PP David Kamholz .PP David Naughton .PP David E. Wheeler .PP dhoss: Devin Austin .PP dkubb: Dan Kubb .PP Drew Taylor .PP dwc: Daniel Westermann-Clark .PP esskar: Sascha Kiefer .PP fireartist: Carl Franks .PP frew: Arthur Axel \*(L"fREW\*(R" Schmidt .PP gabb: Danijel Milicevic .PP Gary Ashton Jones .PP Gavin Henry .PP Geoff Richards .PP groditi: Guillermo Roditi .PP hobbs: Andrew Rodland .PP ilmari: Dagfinn Ilmari Mannsåker .PP jcamacho: Juan Camacho .PP jester: Jesse Sheidlower .PP jhannah: Jay Hannah .PP Jody Belka .PP Johan Lindstrom .PP jon: Jon Schutz .PP Jonathan Rockway .PP Kieren Diment .PP konobi: Scott McWhirter .PP marcus: Marcus Ramberg .PP miyagawa: Tatsuhiko Miyagawa .PP mgrimes: Mark Grimes .PP mst: Matt S. Trout .PP mugwump: Sam Vilain .PP naughton: David Naughton .PP ningu: David Kamholz .PP nothingmuch: Yuval Kogman .PP numa: Dan Sully .PP obra: Jesse Vincent .PP Octavian Rasnita .PP omega: Andreas Marienborg .PP Oleg Kostyuk .PP phaylon: Robert Sedlacek .PP rafl: Florian Ragwitz .PP random: Roland Lammel .PP revmischa: Mischa Spiegelmock .PP Robert Sedlacek .PP rrwo: Robert Rothenberg .PP SpiceMan: Marcel Montes .PP sky: Arthur Bergman .PP szbalint: Balint Szilakszi .PP t0m: Tomas Doran .PP Ulf Edvinsson .PP vanstyn: Henry Van Styn .PP Viljo Marrandi .PP Will Hawes .PP willert: Sebastian Willert .PP wreis: Wallace Reis .PP Yuval Kogman .PP rainboxx: Matthias Dietrich .PP dd070: Dhaval Dhanani .PP Upasana .PP John Napiorkowski (jnap) .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (c) 2005\-2015, the above named \s-1PROJECT FOUNDER\s0 and \s-1CONTRIBUTORS.\s0 .SH "LICENSE" .IX Header "LICENSE" This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.