1 package Catalyst::Context;
5 use B::Hooks::EndOfScope ();
7 use Catalyst::Exception::Detach;
8 use Catalyst::Exception::Go;
10 use Catalyst::Request::Upload;
11 use Catalyst::Response;
14 use Text::SimpleTable ();
19 use Carp qw/croak carp shortmess/;
21 has stack => (is => 'ro', default => sub { [] });
22 has stash => (is => 'rw', default => sub { {} });
23 has state => (is => 'rw', default => 0);
24 has stats => (is => 'rw');
25 has action => (is => 'rw');
26 has counter => (is => 'rw', default => sub { {} });
27 has request => (is => 'rw', default => sub { $_[0]->request_class->new({}) }, required => 1, lazy => 1);
28 has response => (is => 'rw', default => sub { $_[0]->response_class->new({}) }, required => 1, lazy => 1);
29 has namespace => (is => 'rw');
32 has 'application' => (
80 sub depth { scalar @{ shift->stack || [] }; }
83 my $self = shift; return $self->request(@_);
86 my $self = shift; return $self->response(@_);
89 # For backwards compatibility
90 sub finalize_output { shift->finalize_body(@_) };
93 our $RECURSION = 1000;
97 =head2 INFORMATION ABOUT THE CURRENT REQUEST
101 Returns a L<Catalyst::Action> object for the current action, which
102 stringifies to the action name. See L<Catalyst::Action>.
106 Returns the namespace of the current action, i.e., the URI prefix
107 corresponding to the controller of the current action. For example:
109 # in Controller::Foo::Bar
110 $c->namespace; # returns 'foo/bar';
116 Returns the current L<Catalyst::Request> object, giving access to
117 information about the current client request (including parameters,
118 cookies, HTTP headers, etc.). See L<Catalyst::Request>.
120 =head2 REQUEST FLOW HANDLING
122 =head2 $c->forward( $action [, \@arguments ] )
124 =head2 $c->forward( $class, $method, [, \@arguments ] )
126 Forwards processing to another action, by its private name. If you give a
127 class name but no method, C<process()> is called. You may also optionally
128 pass arguments in an arrayref. The action will receive the arguments in
129 C<@_> and C<< $c->req->args >>. Upon returning from the function,
130 C<< $c->req->args >> will be restored to the previous values.
132 Any data C<return>ed from the action forwarded to, will be returned by the
135 my $foodata = $c->forward('/foo');
136 $c->forward('index');
137 $c->forward(qw/MyApp::Model::DBIC::Foo do_stuff/);
138 $c->forward('MyApp::View::TT');
140 Note that L<< forward|/"$c->forward( $action [, \@arguments ] )" >> implies
141 an C<< eval { } >> around the call (actually
142 L<< execute|/"$c->execute( $class, $coderef )" >> does), thus de-fatalizing
143 all 'dies' within the called action. If you want C<die> to propagate you
144 need to do something like:
147 die $c->error if $c->error;
149 Or make sure to always return true values from your actions and write
152 $c->forward('foo') || return;
154 Another note is that C<< $c->forward >> always returns a scalar because it
155 actually returns $c->state which operates in a scalar context.
156 Thus, something like:
160 in an action that is forwarded to is going to return a scalar,
161 i.e. how many items are in that array, which is probably not what you want.
162 If you need to return an array then return a reference to it,
165 $c->stash->{array} = \@array;
167 and access it from the stash.
171 sub forward { my $c = shift; no warnings 'recursion'; $c->dispatcher->forward( $c, @_ ) }
173 =head2 $c->detach( $action [, \@arguments ] )
175 =head2 $c->detach( $class, $method, [, \@arguments ] )
179 The same as L<< forward|/"$c->forward( $action [, \@arguments ] )" >>, but
180 doesn't return to the previous action when processing is finished.
182 When called with no arguments it escapes the processing chain entirely.
186 sub detach { my $c = shift; $c->dispatcher->detach( $c, @_ ) }
188 =head2 $c->visit( $action [, \@captures, \@arguments ] )
190 =head2 $c->visit( $class, $method, [, \@captures, \@arguments ] )
192 Almost the same as L<< forward|/"$c->forward( $action [, \@arguments ] )" >>,
193 but does a full dispatch, instead of just calling the new C<$action> /
194 C<< $class->$method >>. This means that C<begin>, C<auto> and the method
195 you go to are called, just like a new request.
197 In addition both C<< $c->action >> and C<< $c->namespace >> are localized.
198 This means, for example, that C<< $c->action >> methods such as
199 L<name|Catalyst::Action/name>, L<class|Catalyst::Action/class> and
200 L<reverse|Catalyst::Action/reverse> return information for the visited action
201 when they are invoked within the visited action. This is different from the
202 behavior of L<< forward|/"$c->forward( $action [, \@arguments ] )" >>, which
203 continues to use the $c->action object from the caller action even when
204 invoked from the callee.
206 C<< $c->stash >> is kept unchanged.
208 In effect, L<< visit|/"$c->visit( $action [, \@captures, \@arguments ] )" >>
209 allows you to "wrap" another action, just as it would have been called by
210 dispatching from a URL, while the analogous
211 L<< go|/"$c->go( $action [, \@captures, \@arguments ] )" >> allows you to
212 transfer control to another action as if it had been reached directly from a URL.
216 sub visit { my $c = shift; $c->dispatcher->visit( $c, @_ ) }
218 =head2 $c->go( $action [, \@captures, \@arguments ] )
220 =head2 $c->go( $class, $method, [, \@captures, \@arguments ] )
222 The relationship between C<go> and
223 L<< visit|/"$c->visit( $action [, \@captures, \@arguments ] )" >> is the same as
224 the relationship between
225 L<< forward|/"$c->forward( $class, $method, [, \@arguments ] )" >> and
226 L<< detach|/"$c->detach( $action [, \@arguments ] )" >>. Like C<< $c->visit >>,
227 C<< $c->go >> will perform a full dispatch on the specified action or method,
228 with localized C<< $c->action >> and C<< $c->namespace >>. Like C<detach>,
229 C<go> escapes the processing of the current request chain on completion, and
230 does not return to its caller.
234 sub go { my $c = shift; $c->dispatcher->go( $c, @_ ) }
240 Returns the current L<Catalyst::Response> object, see there for details.
244 Returns a hashref to the stash, which may be used to store data and pass
245 it between components during a request. You can also set hash keys by
246 passing arguments. The stash is automatically sent to the view. The
247 stash is cleared at the end of a request; it cannot be used for
248 persistent storage (for this you must use a session; see
249 L<Catalyst::Plugin::Session> for a complete system integrated with
252 $c->stash->{foo} = $bar;
253 $c->stash( { moose => 'majestic', qux => 0 } );
254 $c->stash( bar => 1, gorch => 2 ); # equivalent to passing a hashref
256 # stash is automatically passed to the view for use in a template
257 $c->forward( 'MyApp::View::TT' );
261 around stash => sub {
264 my $stash = $orig->($c);
266 my $new_stash = @_ > 1 ? {@_} : $_[0];
267 croak('stash takes a hash or hashref') unless ref $new_stash;
268 foreach my $key ( keys %$new_stash ) {
269 $stash->{$key} = $new_stash->{$key};
279 =head2 $c->error($error, ...)
281 =head2 $c->error($arrayref)
283 Returns an arrayref containing error messages. If Catalyst encounters an
284 error while processing a request, it stores the error in $c->error. This
285 method should only be used to store fatal error messages.
287 my @error = @{ $c->error };
291 $c->error('Something bad happened');
298 my $error = ref $_[0] eq 'ARRAY' ? $_[0] : [@_];
299 croak @$error unless ref $c;
300 push @{ $c->{error} }, @$error;
302 elsif ( defined $_[0] ) { $c->{error} = undef }
303 return $c->{error} || [];
309 Contains the return value of the last executed action.
310 Note that << $c->state >> operates in a scalar context which means that all
311 values it returns are scalar.
313 =head2 $c->clear_errors
315 Clear errors. You probably don't want to clear the errors unless you are
316 implementing a custom error screen.
318 This is equivalent to running
330 =head2 COMPONENT ACCESSORS
332 =head2 $c->controller($name)
334 Gets a L<Catalyst::Controller> instance by name.
336 $c->controller('Foo')->do_stuff;
338 If the name is omitted, will return the controller for the dispatched
341 If you want to search for controllers, pass in a regexp as the argument.
343 # find all controllers that start with Foo
344 my @foo_controllers = $c->controller(qr{^Foo});
349 =head2 $c->model($name)
351 Gets a L<Catalyst::Model> instance by name.
353 $c->model('Foo')->do_stuff;
355 Any extra arguments are directly passed to ACCEPT_CONTEXT.
357 If the name is omitted, it will look for
358 - a model object in $c->stash->{current_model_instance}, then
359 - a model name in $c->stash->{current_model}, then
360 - a config setting 'default_model', or
361 - check if there is only one model, and return it if that's the case.
363 If you want to search for models, pass in a regexp as the argument.
365 # find all models that start with Foo
366 my @foo_models = $c->model(qr{^Foo});
371 my ( $c, $name, @args ) = @_;
372 my $appclass = ref($c) || $c;
374 my @result = $c->_comp_search_prefixes( $name, qw/Model M/ );
375 return map { $c->_filter_component( $_, @args ) } @result if ref $name;
376 return $c->_filter_component( $result[ 0 ], @args );
380 return $c->stash->{current_model_instance}
381 if $c->stash->{current_model_instance};
382 return $c->model( $c->stash->{current_model} )
383 if $c->stash->{current_model};
385 return $c->model( $appclass->config->{default_model} )
386 if $appclass->config->{default_model};
388 my( $comp, $rest ) = $c->_comp_search_prefixes( undef, qw/Model M/);
391 $c->log->warn( Carp::shortmess('Calling $c->model() will return a random model unless you specify one of:') );
392 $c->log->warn( '* $c->config(default_model => "the name of the default model to use")' );
393 $c->log->warn( '* $c->stash->{current_model} # the name of the model to use for this request' );
394 $c->log->warn( '* $c->stash->{current_model_instance} # the instance of the model to use for this request' );
395 $c->log->warn( 'NB: in version 5.81, the "random" behavior will not work at all.' );
398 return $c->_filter_component( $comp );
402 =head2 $c->view($name)
404 Gets a L<Catalyst::View> instance by name.
406 $c->view('Foo')->do_stuff;
408 Any extra arguments are directly passed to ACCEPT_CONTEXT.
410 If the name is omitted, it will look for
411 - a view object in $c->stash->{current_view_instance}, then
412 - a view name in $c->stash->{current_view}, then
413 - a config setting 'default_view', or
414 - check if there is only one view, and return it if that's the case.
416 If you want to search for views, pass in a regexp as the argument.
418 # find all views that start with Foo
419 my @foo_views = $c->view(qr{^Foo});
424 my ( $c, $name, @args ) = @_;
427 my @result = $c->_comp_search_prefixes( $name, qw/View V/ );
428 return map { $c->_filter_component( $_, @args ) } @result if ref $name;
429 return $c->_filter_component( $result[ 0 ], @args );
433 return $c->stash->{current_view_instance}
434 if $c->stash->{current_view_instance};
435 return $c->view( $c->stash->{current_view} )
436 if $c->stash->{current_view};
438 return $c->view( $c->config->{default_view} )
439 if $c->config->{default_view};
440 my( $comp, $rest ) = $c->_comp_search_prefixes( undef, qw/View V/);
443 $c->log->warn( 'Calling $c->view() will return a random view unless you specify one of:' );
444 $c->log->warn( '* $c->config(default_view => "the name of the default view to use")' );
445 $c->log->warn( '* $c->stash->{current_view} # the name of the view to use for this request' );
446 $c->log->warn( '* $c->stash->{current_view_instance} # the instance of the view to use for this request' );
447 $c->log->warn( 'NB: in version 5.81, the "random" behavior will not work at all.' );
450 return $c->_filter_component( $comp );
453 =head2 UTILITY METHODS
455 =head2 $c->uri_for( $path?, @args?, \%query_values? )
457 =head2 $c->uri_for( $action, \@captures?, @args?, \%query_values? )
459 Constructs an absolute L<URI> object based on the application root, the
460 provided path, and the additional arguments and query parameters provided.
461 When used as a string, provides a textual URI.
463 If no arguments are provided, the URI for the current action is returned.
464 To return the current action and also provide @args, use
465 C<< $c->uri_for( $c->action, @args ) >>.
467 If the first argument is a string, it is taken as a public URI path relative
468 to C<< $c->namespace >> (if it doesn't begin with a forward slash) or
469 relative to the application root (if it does). It is then merged with
470 C<< $c->request->base >>; any C<@args> are appended as additional path
471 components; and any C<%query_values> are appended as C<?foo=bar> parameters.
473 If the first argument is a L<Catalyst::Action> it represents an action which
474 will have its path resolved using C<< $c->dispatcher->uri_for_action >>. The
475 optional C<\@captures> argument (an arrayref) allows passing the captured
476 variables that are needed to fill in the paths of Chained and Regex actions;
477 once the path is resolved, C<uri_for> continues as though a path was
478 provided, appending any arguments or parameters and creating an absolute
481 The captures for the current request can be found in
482 C<< $c->request->captures >>, and actions can be resolved using
483 C<< Catalyst::Controller->action_for($name) >>. If you have a private action
484 path, use C<< $c->uri_for_action >> instead.
486 # Equivalent to $c->req->uri
487 $c->uri_for($c->action, $c->req->captures,
488 @{ $c->req->args }, $c->req->params);
490 # For the Foo action in the Bar controller
491 $c->uri_for($c->controller('Bar')->action_for('Foo'));
493 # Path to a static resource
494 $c->uri_for('/static/images/logo.png');
499 my ( $c, $path, @args ) = @_;
501 if (blessed($path) && $path->isa('Catalyst::Controller')) {
502 $path = $path->path_prefix;
507 if ( blessed($path) ) { # action object
508 my $captures = [ map { s|/|%2F|; $_; }
509 ( scalar @args && ref $args[0] eq 'ARRAY'
513 $path = $c->dispatcher->uri_for_action($action, $captures);
514 if (not defined $path) {
515 $c->log->debug(qq/Can't find uri_for action '$action' @$captures/)
519 $path = '/' if $path eq '';
522 undef($path) if (defined $path && $path eq '');
525 ( scalar @args && ref $args[$#args] eq 'HASH' ? pop @args : {} );
527 carp "uri_for called with undef argument" if grep { ! defined $_ } @args;
528 s/([^$URI::uric])/$URI::Escape::escapes{$1}/go for @args;
531 unshift(@args, $path);
533 unless (defined $path && $path =~ s!^/!!) { # in-place strip
534 my $namespace = $c->namespace;
535 if (defined $path) { # cheesy hack to handle path '../foo'
536 $namespace =~ s{(?:^|/)[^/]+$}{} while $args[0] =~ s{^\.\./}{};
538 unshift(@args, $namespace || '');
541 # join args with '/', or a blank string
542 my $args = join('/', grep { defined($_) } @args);
543 $args =~ s/\?/%3F/g; # STUPID STUPID SPECIAL CASE
545 my $base = $c->req->base;
546 my $class = ref($base);
547 $base =~ s{(?<!/)$}{/};
551 if (my @keys = keys %$params) {
552 # somewhat lifted from URI::_query's query_form
553 $query = '?'.join('&', map {
554 my $val = $params->{$_};
555 s/([;\/?:@&=+,\$\[\]%])/$URI::Escape::escapes{$1}/go;
558 $val = '' unless defined $val;
561 utf8::encode( $param ) if utf8::is_utf8($param);
562 # using the URI::Escape pattern here so utf8 chars survive
563 $param =~ s/([^A-Za-z0-9\-_.!~*'() ])/$URI::Escape::escapes{$1}/go;
565 "${key}=$param"; } ( ref $val eq 'ARRAY' ? @$val : $val ));
569 my $res = bless(\"${base}${args}${query}", $class);
573 =head2 $c->uri_for_action( $path, \@captures?, @args?, \%query_values? )
575 =head2 $c->uri_for_action( $action, \@captures?, @args?, \%query_values? )
581 A private path to the Catalyst action you want to create a URI for.
583 This is a shortcut for calling C<< $c->dispatcher->get_action_by_path($path)
584 >> and passing the resulting C<$action> and the remaining arguments to C<<
587 You can also pass in a Catalyst::Action object, in which case it is passed to
595 my ( $c, $path, @args ) = @_;
596 my $action = blessed($path)
598 : $c->dispatcher->get_action_by_path($path);
599 unless (defined $action) {
600 croak "Can't find action for path '$path'";
602 return $c->uri_for( $action, @args );
605 =head1 INTERNAL METHODS
609 Returns a hashref containing coderefs and execution counts (needed for
610 deep recursion detection).
614 Returns the number of actions on the current internal execution stack.
618 Dispatches a request to actions.
622 sub dispatch { my $c = shift; $c->dispatcher->dispatch( $c, @_ ) }
624 =head2 $c->dump_these
626 Returns a list of 2-element array references (name, structure) pairs
627 that will be dumped on the error page in debug mode.
633 [ Request => $c->req ],
634 [ Response => $c->res ],
635 [ Stash => $c->stash ],
636 [ Config => $c->config ];
639 =head2 $c->execute( $class, $coderef )
641 Execute a coderef in given class and catch exceptions. Errors are available
647 my ( $c, $class, $code ) = @_;
648 $class = $c->component($class) || $class;
651 if ( $c->depth >= $RECURSION ) {
652 my $action = $code->reverse();
653 $action = "/$action" unless $action =~ /->/;
654 my $error = qq/Deep recursion detected calling "${action}"/;
655 $c->log->error($error);
661 my $stats_info = $c->_stats_start_execute( $code ) if $c->use_stats;
663 push( @{ $c->stack }, $code );
665 no warnings 'recursion';
666 eval { $c->state( $code->execute( $class, $c, @{ $c->req->args } ) || 0 ) };
668 $c->_stats_finish_execute( $stats_info ) if $c->use_stats and $stats_info;
670 my $last = pop( @{ $c->stack } );
672 if ( my $error = $@ ) {
673 if ( blessed($error) and $error->isa('Catalyst::Exception::Detach') ) {
674 $error->rethrow if $c->depth > 1;
676 elsif ( blessed($error) and $error->isa('Catalyst::Exception::Go') ) {
677 $error->rethrow if $c->depth > 0;
680 unless ( ref $error ) {
681 no warnings 'uninitialized';
683 my $class = $last->class;
684 my $name = $last->name;
685 $error = qq/Caught exception in $class->$name "$error"/;
694 sub _stats_start_execute {
695 my ( $c, $code ) = @_;
696 return if ( ( $code->name =~ /^_.*/ )
697 && ( !$c->config->{show_internal_actions} ) );
699 my $action_name = $code->reverse();
700 $c->counter->{$action_name}++;
702 my $action = $action_name;
703 $action = "/$action" unless $action =~ /->/;
705 # determine if the call was the result of a forward
706 # this is done by walking up the call stack and looking for a calling
707 # sub of Catalyst::forward before the eval
709 for my $index ( 2 .. 11 ) {
711 if ( ( caller($index) )[0] eq 'Catalyst'
712 && ( caller($index) )[3] eq '(eval)' );
714 if ( ( caller($index) )[3] =~ /forward$/ ) {
715 $callsub = ( caller($index) )[3];
716 $action = "-> $action";
721 my $uid = $action_name . $c->counter->{$action_name};
723 # is this a root-level call or a forwarded call?
724 if ( $callsub =~ /forward$/ ) {
725 my $parent = $c->stack->[-1];
727 # forward, locate the caller
728 if ( exists $c->counter->{"$parent"} ) {
731 parent => "$parent" . $c->counter->{"$parent"},
737 # forward with no caller may come from a plugin
756 sub _stats_finish_execute {
757 my ( $c, $info ) = @_;
758 $c->stats->profile( end => $info );
763 Finalizes the request.
770 for my $error ( @{ $c->error } ) {
771 $c->log->error($error);
774 # Allow engine to handle finalize flow (for POE)
775 my $engine = $c->engine;
776 if ( my $code = $engine->can('finalize') ) {
781 $c->finalize_uploads;
784 if ( $#{ $c->error } >= 0 ) {
788 $c->finalize_headers;
791 if ( $c->request->method eq 'HEAD' ) {
792 $c->response->body('');
799 my $elapsed = sprintf '%f', $c->stats->elapsed;
800 my $av = $elapsed == 0 ? '??' : sprintf '%.3f', 1 / $elapsed;
802 "Request took ${elapsed}s ($av/s)\n" . $c->stats->report . "\n" );
805 return $c->response->status;
808 =head2 $c->finalize_body
814 sub finalize_body { my $c = shift; $c->engine->finalize_body( $c, @_ ) }
816 =head2 $c->finalize_cookies
822 sub finalize_cookies { my $c = shift; $c->engine->finalize_cookies( $c, @_ ) }
824 =head2 $c->finalize_error
830 sub finalize_error { my $c = shift; $c->engine->finalize_error( $c, @_ ) }
832 =head2 $c->finalize_headers
838 sub finalize_headers {
841 my $response = $c->response; #accessor calls can add up?
843 # Check if we already finalized headers
844 return if $response->finalized_headers;
847 if ( my $location = $response->redirect ) {
848 $c->log->debug(qq/Redirecting to "$location"/) if $c->debug;
849 $response->header( Location => $location );
851 if ( !$response->has_body ) {
852 # Add a default body if none is already present
854 qq{<html><body><p>This item has moved <a href="$location">here</a>.</p></body></html>}
860 if ( $response->body && !$response->content_length ) {
862 # get the length from a filehandle
863 if ( blessed( $response->body ) && $response->body->can('read') )
865 my $stat = stat $response->body;
866 if ( $stat && $stat->size > 0 ) {
867 $response->content_length( $stat->size );
870 $c->log->warn('Serving filehandle without a content-length');
874 # everything should be bytes at this point, but just in case
875 $response->content_length( bytes::length( $response->body ) );
880 if ( $response->status =~ /^(1\d\d|[23]04)$/ ) {
881 $response->headers->remove_header("Content-Length");
885 $c->finalize_cookies;
887 $c->engine->finalize_headers( $c, @_ );
890 $response->finalized_headers(1);
893 =head2 $c->finalize_output
895 An alias for finalize_body.
897 =head2 $c->finalize_read
899 Finalizes the input after reading is complete.
903 sub finalize_read { my $c = shift; $c->engine->finalize_read( $c, @_ ) }
905 =head2 $c->finalize_uploads
907 Finalizes uploads. Cleans up any temporary files.
911 sub finalize_uploads { my $c = shift; $c->engine->finalize_uploads( $c, @_ ) }
913 =head2 $c->get_action( $action, $namespace )
915 Gets an action in a given namespace.
919 sub get_action { my $c = shift; $c->dispatcher->get_action(@_) }
921 =head2 $c->get_actions( $action, $namespace )
923 Gets all actions of a given name in a namespace and all parent
928 sub get_actions { my $c = shift; $c->dispatcher->get_actions( $c, @_ ) }
930 =head2 $c->prepare_action
932 Prepares action. See L<Catalyst::Dispatcher>.
936 sub prepare_action { my $c = shift; $c->dispatcher->prepare_action( $c, @_ ) }
938 =head2 $c->prepare_body
940 Prepares message body.
947 return if $c->request->_has_body;
949 # Initialize on-demand data
950 $c->engine->prepare_body( $c, @_ );
951 $c->prepare_parameters;
954 if ( $c->debug && keys %{ $c->req->body_parameters } ) {
955 my $t = Text::SimpleTable->new( [ 35, 'Parameter' ], [ 36, 'Value' ] );
956 for my $key ( sort keys %{ $c->req->body_parameters } ) {
957 my $param = $c->req->body_parameters->{$key};
958 my $value = defined($param) ? $param : '';
960 ref $value eq 'ARRAY' ? ( join ', ', @$value ) : $value );
962 $c->log->debug( "Body Parameters are:\n" . $t->draw );
966 =head2 $c->prepare_body_chunk( $chunk )
968 Prepares a chunk of data before sending it to L<HTTP::Body>.
970 See L<Catalyst::Engine>.
974 sub prepare_body_chunk {
976 $c->engine->prepare_body_chunk( $c, @_ );
979 =head2 $c->prepare_body_parameters
981 Prepares body parameters.
985 sub prepare_body_parameters {
987 $c->engine->prepare_body_parameters( $c, @_ );
990 =head2 $c->prepare_connection
996 sub prepare_connection {
998 $c->engine->prepare_connection( $c, @_ );
1001 =head2 $c->prepare_cookies
1007 sub prepare_cookies { my $c = shift; $c->engine->prepare_cookies( $c, @_ ) }
1009 =head2 $c->prepare_headers
1015 sub prepare_headers { my $c = shift; $c->engine->prepare_headers( $c, @_ ) }
1017 =head2 $c->prepare_parameters
1019 Prepares parameters.
1023 sub prepare_parameters {
1025 $c->prepare_body_parameters;
1026 $c->engine->prepare_parameters( $c, @_ );
1029 =head2 $c->prepare_path
1031 Prepares path and base.
1035 sub prepare_path { my $c = shift; $c->engine->prepare_path( $c, @_ ) }
1037 =head2 $c->prepare_query_parameters
1039 Prepares query parameters.
1043 sub prepare_query_parameters {
1046 $c->engine->prepare_query_parameters( $c, @_ );
1048 if ( $c->debug && keys %{ $c->request->query_parameters } ) {
1049 my $t = Text::SimpleTable->new( [ 35, 'Parameter' ], [ 36, 'Value' ] );
1050 for my $key ( sort keys %{ $c->req->query_parameters } ) {
1051 my $param = $c->req->query_parameters->{$key};
1052 my $value = defined($param) ? $param : '';
1054 ref $value eq 'ARRAY' ? ( join ', ', @$value ) : $value );
1056 $c->log->debug( "Query Parameters are:\n" . $t->draw );
1060 =head2 $c->prepare_read
1062 Prepares the input for reading.
1066 sub prepare_read { my $c = shift; $c->engine->prepare_read( $c, @_ ) }
1068 =head2 $c->prepare_request
1070 Prepares the engine request.
1074 sub prepare_request { my $c = shift; $c->engine->prepare_request( $c, @_ ) }
1076 =head2 $c->prepare_uploads
1082 sub prepare_uploads {
1085 $c->engine->prepare_uploads( $c, @_ );
1087 if ( $c->debug && keys %{ $c->request->uploads } ) {
1088 my $t = Text::SimpleTable->new(
1089 [ 12, 'Parameter' ],
1094 for my $key ( sort keys %{ $c->request->uploads } ) {
1095 my $upload = $c->request->uploads->{$key};
1096 for my $u ( ref $upload eq 'ARRAY' ? @{$upload} : ($upload) ) {
1097 $t->row( $key, $u->filename, $u->type, $u->size );
1100 $c->log->debug( "File Uploads are:\n" . $t->draw );
1104 =head2 $c->prepare_write
1106 Prepares the output for writing.
1110 sub prepare_write { my $c = shift; $c->engine->prepare_write( $c, @_ ) }
1112 =head2 $c->read( [$maxlength] )
1114 Reads a chunk of data from the request body. This method is designed to
1115 be used in a while loop, reading C<$maxlength> bytes on every call.
1116 C<$maxlength> defaults to the size of the request if not specified.
1118 You have to set C<< MyApp->config(parse_on_demand => 1) >> to use this
1121 Warning: If you use read(), Catalyst will not process the body,
1122 so you will not be able to access POST parameters or file uploads via
1123 $c->request. You must handle all body parsing yourself.
1127 sub read { my $c = shift; return $c->engine->read( $c, @_ ) }
1131 Returns an arrayref of the internal execution stack (actions that are
1132 currently executing).
1135 =head2 $c->write( $data )
1137 Writes $data to the output stream. When using this method directly, you
1138 will need to manually set the C<Content-Length> header to the length of
1139 your output data, if known.
1146 # Finalize headers if someone manually writes output
1147 $c->finalize_headers;
1149 return $c->engine->write( $c, @_ );
1153 __PACKAGE__->meta->make_immutable;
1161 Catalyst::Context - object for keeping request related state
1171 =head3 request_class
1175 =head3 response_class
1189 L<Catalyst>, L<Catalyst::Model>, L<Catalyst::View>, L<Catalyst::Controller>.
1193 Catalyst Contributors, see Catalyst.pm
1197 This library is free software. You can redistribute it and/or modify it under
1198 the same terms as Perl itself.