Catalyst/View/Errors/HTML.pm

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