1 use CatalystX::Declare;
3 # almost like a normal Moose role
4 controller_role MyApp::Web::ControllerRole::RenderView {
6 # we can use the whole Moose infrastructure
7 use MooseX::Types::Moose qw( Str );
9 # a normal attribute that can be passed by config
10 has default_content_type => (
14 default => 'text/html; charset=utf-8',
17 # this private end action is a cheap ripoff of Catalyst::Action::RenderView
20 # do nothing if rendering wouldn't make sense
22 if $ctx->request->method eq 'HEAD'
23 or ( defined( $ctx->response->body ) and length( $ctx->response->body ) )
24 or $ctx->response->status =~ /^(?:204|3\d\d)$/;
26 # set the content type from our attribute unless it is already set
27 $ctx->response->content_type( $self->default_content_type )
28 unless $ctx->response->content_type;
32 or die "Unable to find a view to forward to";
35 $ctx->forward( $view );