| 1 | package Catalyst::View::Errors::Text; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Text::Template; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use CatalystX::Utils::ContentNegotiation; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use CatalystX::Utils::ErrorMessages; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | extends 'Catalyst::View'; | |||||||||
| 9 | 1 | with 'Catalyst::Component::ApplicationAttribute'; | |||||||||
| 10 | |||||||||||
| 11 | has template_engine_args => ( | ||||||||||
| 12 | is=>'ro', | ||||||||||
| 13 | required=>1, | ||||||||||
| 14 | lazy=>1, | ||||||||||
| 15 | 0 | ▶ | default=> sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 16 | 0 | my $self = shift; | |||||||||
| 17 | 0 | my $template = $self->_application->config->{root}->file($self->template_name); | |||||||||
| 18 | 0 | ▶ | my $source = -e $template ? $template->slurp : $self->text($self->_application); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 0 | return +{TYPE => 'STRING', SOURCE => $source}; | |||||||||
| 20 | }, | ||||||||||
| 21 | 1 | ); | |||||||||
| 22 | |||||||||||
| 23 | 1 | has template_name => (is=>'ro', required=>1, default=>'http_errors_text.tmpl'); | |||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | sub text { | ||||||||
|
Subroutine
text: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 26 | 0 | my ($self, $app) = @_; | |||||||||
| 27 | 0 | return q[{$status_code} {$title}:{$message}]."\n"; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | has template_engine => ( | ||||||||||
| 31 | is => 'ro', | ||||||||||
| 32 | required => 1, | ||||||||||
| 33 | init_arg => undef, | ||||||||||
| 34 | lazy => 1, | ||||||||||
| 35 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 36 | 0 | my %args = %{shift->template_engine_args}; | |||||||||
| 37 | 0 | my $engine = Text::Template->new(%args); | |||||||||
| 38 | 0 | $engine->compile; | |||||||||
| 39 | 0 | return $engine; | |||||||||
| 40 | } | ||||||||||
| 41 | 1 | ); | |||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | sub http_default { | ||||||||
|
Subroutine
http_default: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 44 | 0 | my ($self, $c, $code, %args) = @_; | |||||||||
| 45 | 0 | my $text = $self->render_template($c, \%args); | |||||||||
| 46 | |||||||||||
| 47 | 0 | $c->response->body($text); | |||||||||
| 48 | 0 | $c->response->content_type('text/plain'); | |||||||||
| 49 | 0 | $c->response->status($code); | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | sub render_template { | ||||||||
|
Subroutine
render_template: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 53 | 0 | my ($self, $c, $message_info) = @_; | |||||||||
| 54 | 0 | return my $text = $self->template_engine->fill_in(HASH => $message_info); | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 58 | |||||||||||
| 59 | =head1 NAME | ||||||||||
| 60 | |||||||||||
| 61 | Catalyst::View::Errors::Text - Standard HTTP Errors Responses in Plain Text. | ||||||||||
| 62 | |||||||||||
| 63 | =head1 SYNOPSIS | ||||||||||
| 64 | |||||||||||
| 65 | package MyApp::View::Text; | ||||||||||
| 66 | |||||||||||
| 67 | use Moose; | ||||||||||
| 68 | extends 'Catalyst::View::Errors::Text'; | ||||||||||
| 69 | |||||||||||
| 70 | __PACKAGE__->meta->make_immutable; | ||||||||||
| 71 | |||||||||||
| 72 | =head1 DESCRIPTION | ||||||||||
| 73 | |||||||||||
| 74 | View class for generating error responses. If you want a lot of customizations you can subclass | ||||||||||
| 75 | this in your application, or just use your own view. | ||||||||||
| 76 | |||||||||||
| 77 | =head1 METHODS | ||||||||||
| 78 | |||||||||||
| 79 | This view exposes the follow methods for public use or for a programmer to override | ||||||||||
| 80 | to change function. | ||||||||||
| 81 | |||||||||||
| 82 | The follow field arguments are passed to this template: | ||||||||||
| 83 | |||||||||||
| 84 | =over 4 | ||||||||||
| 85 | |||||||||||
| 86 | =item lang | ||||||||||
| 87 | |||||||||||
| 88 | Defaults to "en_US". This is the language code of the error response. | ||||||||||
| 89 | |||||||||||
| 90 | =item message | ||||||||||
| 91 | |||||||||||
| 92 | This is a text message of the error condition | ||||||||||
| 93 | |||||||||||
| 94 | =item status_code | ||||||||||
| 95 | |||||||||||
| 96 | This is the HTTP Status code of the error | ||||||||||
| 97 | |||||||||||
| 98 | =item title | ||||||||||
| 99 | |||||||||||
| 100 | The official HTTP Status error title (Not Found, Not Authorized, etc.) | ||||||||||
| 101 | |||||||||||
| 102 | =item uri | ||||||||||
| 103 | |||||||||||
| 104 | The URI that generated the error. Be careful displaying this in your template since if its not | ||||||||||
| 105 | properly escaped you can open yourself to HTML injection / Javascript injection attackes. | ||||||||||
| 106 | |||||||||||
| 107 | =back | ||||||||||
| 108 | |||||||||||
| 109 | In addition any other arguments passed in ->dispatch_error / ->detach_error. | ||||||||||
| 110 | |||||||||||
| 111 | =head2 text | ||||||||||
| 112 | |||||||||||
| 113 | Should return a string suitable for L<Text::Template> and is used to generate | ||||||||||
| 114 | a plain text error response. This is used if there's no file at C<$APPHOME/root/http_errors_text.tmpl> | ||||||||||
| 115 | |||||||||||
| 116 | =head1 CONFIGURATION | ||||||||||
| 117 | |||||||||||
| 118 | This View exposes the following configuration options | ||||||||||
| 119 | |||||||||||
| 120 | =head2 template_engine_args | ||||||||||
| 121 | |||||||||||
| 122 | Args that are used to start the L<Text::Template> template engin | ||||||||||
| 123 | |||||||||||
| 124 | =head2 template_name | ||||||||||
| 125 | |||||||||||
| 126 | Name of the files under $APPHOME/root that is used to render an error view. | ||||||||||
| 127 | Default is C<http_errors_text.tmpl>. If this this file doesn't exist we | ||||||||||
| 128 | instead use the return of L</text> method for the template string. | ||||||||||
| 129 | |||||||||||
| 130 | =head1 SEE ALSO | ||||||||||
| 131 | |||||||||||
| 132 | L<CatalystX::Errors>. | ||||||||||
| 133 | |||||||||||
| 134 | =head1 AUTHOR | ||||||||||
| 135 | |||||||||||
| 136 | L<CatalystX::Errors>. | ||||||||||
| 137 | |||||||||||
| 138 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 139 | |||||||||||
| 140 | L<CatalystX::Errors>. | ||||||||||
| 141 | |||||||||||
| 142 | =cut | ||||||||||