1 package Catalyst::Action::RenderView;
8 use base 'Catalyst::Action';
11 use Data::Visitor::Callback;
13 my %ignore_classes = ();
17 my ($controller, $c ) = @_;
18 $self->next::method( @_ );
20 $c->config->{'Action::RenderView'}->{ignore_classes} =
21 ( ref($c->config->{'debug'}) eq 'HASH' ? $c->config->{'debug'}->{ignore_classes} : undef )
23 DBIx::Class::ResultSource::Table
24 DBIx::Class::ResultSourceHandle
26 / ] unless exists $c->config->{'Action::RenderView'}->{ignore_classes};
28 $c->config->{'Action::RenderView'}->{scrubber_func} =
29 ( ref($c->config->{'debug'}) eq 'HASH' ? $c->config->{'debug'}->{scrubber_func} : undef )
30 || sub { $_='[stringified to: ' . $_ . ']' }
31 unless exists $c->config->{'Action::RenderView'}->{scrubber_func};
33 if ($c->debug && $c->req->params->{dump_info}) {
34 unless ( keys %ignore_classes ) {
35 foreach my $class (@{$c->config->{'Action::RenderView'}->{ignore_classes}}) {
36 $ignore_classes{$class} = $c->config->{'Action::RenderView'}->{scrubber_func};
39 my $scrubber=Data::Visitor::Callback->new(
40 "ignore_return_values" => 1,
41 "object" => "visit_ref",
44 $scrubber->visit( $c->stash );
45 die('Forced debug - Scrubbed output');
48 if(! $c->response->content_type ) {
49 $c->response->content_type( 'text/html; charset=utf-8' );
51 return 1 if $c->req->method eq 'HEAD';
52 return 1 if defined $c->response->body && length( $c->response->body );
53 return 1 if scalar @{ $c->error } && !$c->stash->{template};
54 return 1 if $c->response->status =~ /^(?:204|3\d\d)$/;
56 || die "Catalyst::Action::RenderView could not find a view to forward to.\n";
64 Catalyst::Action::RenderView - Sensible default end action.
68 sub end : ActionClass('RenderView') {}
72 This action implements a sensible default end action, which will forward
73 to the first available view, unless C<< $c->res->status >> is a 3xx code
74 (redirection, not modified, etc.), 204 (no content), or C<< $c->res->body >> has
75 already been set. It also allows you to pass C<dump_info=1> to the url in
76 order to force a debug screen, while in debug mode.
78 If you have more than one view, you can specify which one to use with
79 the C<default_view> config setting and the C<current_view> and
80 C<current_view_instance> stash keys (see L<Catalyst>'s C<$c-E<gt>view($name)>
81 method -- this module simply calls C<< $c->view >> with no argument).
87 The default C<end> action. You can override this as required in your
88 application class; normal inheritance applies.
90 =head1 INTERNAL METHODS
94 Dispatches control to superclasses, then forwards to the default View.
96 See L<Catalyst::Action/METHODS/action>.
98 =head1 SCRUBBING OUTPUT
100 When you force debug with dump_info=1, RenderView is capable of removing
101 classes from the objects in your stash. By default it will replace any
102 DBIx::Class resultsource objects with the class name, which cleans up the
103 debug output considerably, but you can change what gets scrubbed by
104 setting a list of classes in
105 $c->config->{'Action::RenderView'}->{ignore_classes}.
108 $c->config->{'Action::RenderView'}->{ignore_classes} = [];
110 To disable the functionality. You can also set
111 config->{'Action::RenderView'}->{scrubber_func} to change what it does with the
112 classes. For instance, this will undef it instead of putting in the
115 $c->config->{'Action::RenderView'}->{scrubber_func} = sub { undef $_ };
117 =head2 Deprecation notice
119 This plugin used to be configured by setting C<< $c->config->{debug} >>.
120 That configuration key is still supported in this release, but is
121 deprecated, please use the C< 'Action::RenderView' > namespace as shown
122 above for configuration in new code.
126 To add something to an C<end> action that is called before rendering,
127 simply place it in the C<end> method:
129 sub end : ActionClass('RenderView') {
130 my ( $self, $c ) = @_;
131 # do stuff here; the RenderView action is called afterwards
134 To add things to an C<end> action that are called I<after> rendering,
135 you can set it up like this:
137 sub render : ActionClass('RenderView') { }
140 my ( $self, $c ) = @_;
141 $c->forward('render');
147 Marcus Ramberg <marcus@thefeed.no>
149 Florian Ragwitz E<lt>rafl@debian.orgE<gt>
153 Copyright (c) 2006 - 2009
154 the Catalyst::Action::RenderView L</AUTHOR>
159 This library is free software. You can redistribute it and/or modify it
160 under the same terms as Perl itself.