| 1 | package Kelp::Response; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 30 | ▶ | use Kelp::Base 'Plack::Response'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 30 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 30 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 30 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 30 | ▶ | use HTTP::Status qw(status_message); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 30 | ▶ | use Kelp::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 30 | our @CARP_NOT = qw(Kelp); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | attr -app => sub { croak "app is required" }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 14 | 30 | attr charset => undef; | |||||||||||||||||||||||||||
| 15 | 30 | attr rendered => 0; | |||||||||||||||||||||||||||
| 16 | 30 | attr partial => 0; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub new | ||||||||||||||||||||||||||||
| 19 | 262 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 262 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 21 | 262 | my $self = $class->SUPER::new(); | |||||||||||||||||||||||||||
| 22 | 262 | $self->{$_} = $args{$_} for keys %args; | |||||||||||||||||||||||||||
| 23 | 262 | return $self; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub set_content_type | ||||||||||||||||||||||||||||
| 27 | 250 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_content_type: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 250 | my ($self, $type, $charset) = @_; | |||||||||||||||||||||||||||
| 29 | 250 | $self->content_type($type); | |||||||||||||||||||||||||||
| 30 | 250 | ▶ | $self->charset($charset) if $charset; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 250 | return $self; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub charset_encode | ||||||||||||||||||||||||||||
| 35 | 235 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
charset_encode: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 235 | my ($self, $string) = @_; | |||||||||||||||||||||||||||
| 37 | 235 | ▶ | return Kelp::Util::charset_encode( | ||||||||||||||||||||||||||
|
Condition100%3/3
Kelp::Util::effective_charset($self->charset) // $self->app->charset
MC/DC100%2/2
Kelp::Util::effective_charset($self->charset) // $self->app->charset
Kelp::Util::effective_charset($self->charset)
$self->app->charset
Truth table100%3/3
A // B
A= Kelp::Util::effective_charset($self->charset)B= $self->app->charset
| |||||||||||||||||||||||||||||
| 38 | Kelp::Util::effective_charset($self->charset) // $self->app->charset, | ||||||||||||||||||||||||||||
| 39 | $string, | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | sub _apply_charset | ||||||||||||||||||||||||||||
| 44 | 257 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_apply_charset: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 45 | 257 | my ($self) = @_; | |||||||||||||||||||||||||||
| 46 | 257 | my $charset = $self->charset; | |||||||||||||||||||||||||||
| 47 | 257 | ▶ | return unless $charset; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 236 | my $ct = $self->content_type; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 236 | ▶ | croak 'Cannot apply charset to response without content_type' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | unless $ct; | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # content_type is actually an array, getting it in scalar context only | ||||||||||||||||||||||||||||
| 55 | # yields the actual type without charset. It will be split after setting it | ||||||||||||||||||||||||||||
| 56 | # like this | ||||||||||||||||||||||||||||
| 57 | 236 | $self->content_type("$ct; charset=$charset"); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | sub text | ||||||||||||||||||||||||||||
| 61 | 33 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
text: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 33 | my $self = shift; | |||||||||||||||||||||||||||
| 63 | 33 | ▶ | $self->set_content_type('text/plain', $self->charset || $self->app->charset); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->charset || $self->app->charset
MC/DC0%0/2
$self->charset || $self->app->charset
$self->charset
$self->app->charset
Truth table66%2/3
A || B
A= $self->charsetB= $self->app->charset
| |||||||||||||||||||||||||||||
| 64 | 33 | return $self; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | sub html | ||||||||||||||||||||||||||||
| 68 | 179 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
html: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 179 | my $self = shift; | |||||||||||||||||||||||||||
| 70 | 179 | ▶ | $self->set_content_type('text/html', $self->charset || $self->app->charset); | ||||||||||||||||||||||||||
|
Condition100%3/3
$self->charset || $self->app->charset
MC/DC100%2/2
$self->charset || $self->app->charset
$self->charset
$self->app->charset
Truth table100%3/3
A || B
A= $self->charsetB= $self->app->charset
| |||||||||||||||||||||||||||||
| 71 | 179 | return $self; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | sub json | ||||||||||||||||||||||||||||
| 75 | 33 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
json: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 33 | my $self = shift; | |||||||||||||||||||||||||||
| 77 | 33 | ▶ | $self->set_content_type('application/json', $self->charset || $self->app->charset); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->charset || $self->app->charset
MC/DC0%0/2
$self->charset || $self->app->charset
$self->charset
$self->app->charset
Truth table66%2/3
A || B
A= $self->charsetB= $self->app->charset
| |||||||||||||||||||||||||||||
| 78 | 33 | return $self; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | sub xml | ||||||||||||||||||||||||||||
| 82 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
xml: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 84 | 2 | ▶ | $self->set_content_type('application/xml', $self->charset || $self->app->charset); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->charset || $self->app->charset
MC/DC0%0/2
$self->charset || $self->app->charset
$self->charset
$self->app->charset
Truth table66%2/3
A || B
A= $self->charsetB= $self->app->charset
| |||||||||||||||||||||||||||||
| 85 | 2 | return $self; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | sub finalize | ||||||||||||||||||||||||||||
| 89 | 257 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
finalize: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | 257 | my $self = shift; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 257 | $self->_apply_charset; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 257 | my $arr = $self->SUPER::finalize(@_); | |||||||||||||||||||||||||||
| 95 | 257 | ▶ | pop @$arr if $self->partial; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 257 | return $arr; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | sub set_header | ||||||||||||||||||||||||||||
| 100 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_header: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 102 | 1 | $self->SUPER::header(@_); | |||||||||||||||||||||||||||
| 103 | 1 | return $self; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | sub no_cache | ||||||||||||||||||||||||||||
| 107 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
no_cache: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 109 | 0 | $self->set_header('Cache-Control' => 'no-cache, no-store, must-revalidate'); | |||||||||||||||||||||||||||
| 110 | 0 | $self->set_header('Pragma' => 'no-cache'); | |||||||||||||||||||||||||||
| 111 | 0 | $self->set_header('Expires' => '0'); | |||||||||||||||||||||||||||
| 112 | 0 | return $self; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | sub set_code | ||||||||||||||||||||||||||||
| 116 | 238 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_code: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | 238 | my $self = shift; | |||||||||||||||||||||||||||
| 118 | 238 | $self->SUPER::code(@_); | |||||||||||||||||||||||||||
| 119 | 238 | return $self; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | sub render | ||||||||||||||||||||||||||||
| 123 | 240 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
render: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 124 | 240 | my ($self, $body) = @_; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 240 | ▶ | my $method = ref $body ? '_render_ref' : '_render_nonref'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 240 | $body = $self->$method($body); | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | # Set code 200 if the code has not been set | ||||||||||||||||||||||||||||
| 130 | 235 | ▶ | $self->set_code(200) unless $self->code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 235 | $self->body($self->charset_encode($body)); | |||||||||||||||||||||||||||
| 133 | 235 | $self->rendered(1); | |||||||||||||||||||||||||||
| 134 | 235 | return $self; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | # override to change how references are serialized | ||||||||||||||||||||||||||||
| 138 | sub _render_ref | ||||||||||||||||||||||||||||
| 139 | 27 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_render_ref: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||
| 140 | 27 | my ($self, $body) = @_; | |||||||||||||||||||||||||||
| 141 | 27 | my $ct = $self->content_type; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 27 | ▶ | if (!$ct || $ct =~ m{^application/json}i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $ct or $ct =~ m[^application/json]i
MC/DC0%0/2
not $ct or $ct =~ m[^application/json]i
not $ct
$ct =~ m[^application/json]i
Truth table66%2/3
not(A) or B
A= not $ctB= $ct =~ m[^application/json]i
| |||||||||||||||||||||||||||||
| 144 | 27 | ▶ | $self->json if !$ct; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 27 | return $self->app->get_encoder(json => 'internal')->encode($body); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | else { | ||||||||||||||||||||||||||||
| 148 | 0 | croak "Don't know how to handle reference for $ct in response (forgot to serialize?)"; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | # override to change how non-references are handled | ||||||||||||||||||||||||||||
| 153 | sub _render_nonref | ||||||||||||||||||||||||||||
| 154 | 213 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_render_nonref: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 155 | 213 | my ($self, $body) = @_; | |||||||||||||||||||||||||||
| 156 | 213 | ▶ | $self->html if !$self->content_type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 213 | return $body; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | sub render_binary | ||||||||||||||||||||||||||||
| 162 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
render_binary: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 163 | 2 | my ($self, $body) = @_; | |||||||||||||||||||||||||||
| 164 | 2 | ▶ | $body //= ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$body //= ""
MC/DC0%0/1
$body //= ""
$body
Truth table50%1/2
A
A= $body
| |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | # Set code 200 if the code has not been set | ||||||||||||||||||||||||||||
| 167 | 2 | ▶ | $self->set_code(200) unless $self->code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 2 | ▶ | if (!$self->content_type) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 1 | croak "Content-type must be explicitly set for binaries"; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 1 | $self->body($body); | |||||||||||||||||||||||||||
| 174 | 1 | $self->rendered(1); | |||||||||||||||||||||||||||
| 175 | 1 | return $self; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | sub render_error | ||||||||||||||||||||||||||||
| 179 | 68 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
render_error: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 180 | 68 | my ($self, $code, $error) = @_; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 68 | ▶ | $code //= 500; | ||||||||||||||||||||||||||
|
Condition100%2/2
$code //= 500
MC/DC100%1/1
$code //= 500
$code
Truth table100%2/2
A
A= $code
| |||||||||||||||||||||||||||||
| 183 | 68 | ▶ | $error //= status_message($code) // 'Error'; | ||||||||||||||||||||||||||
|
Condition75%3/4
$error //= &status_message($code) // "Error"
&status_message($code) // "Error"
MC/DC100%1/1
$error //= &status_message($code) // "Error"
$error
Truth table100%2/2
A
A= $error
| |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 68 | $self->set_code($code); | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | # Look for a template and if not found, then show a generic text | ||||||||||||||||||||||||||||
| 188 | 68 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 189 | 68 | local $SIG{__DIE__}; # Silence StackTrace | |||||||||||||||||||||||||||
| 190 | 68 | $self->template( | |||||||||||||||||||||||||||
| 191 | "error/$code", { | ||||||||||||||||||||||||||||
| 192 | error => $error | ||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | ); | ||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | 24 | ▶ | catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 197 | 24 | $self->text->render("$code - $error"); | |||||||||||||||||||||||||||
| 198 | 68 | }; | |||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 68 | return $self; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | sub render_exception | ||||||||||||||||||||||||||||
| 204 | 11 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
render_exception: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 205 | 11 | my ($self, $exception) = @_; | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | # If the error is 500, do the same thing normal errors do: provide more | ||||||||||||||||||||||||||||
| 208 | # info on non-production | ||||||||||||||||||||||||||||
| 209 | 11 | ▶ | return $self->render_500($exception->body) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | if $exception->code == 500; | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 9 | return $self->render_error($exception->code); | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | sub render_401 | ||||||||||||||||||||||||||||
| 216 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
render_401: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 217 | 0 | $_[0]->render_error(401); | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | sub render_403 | ||||||||||||||||||||||||||||
| 221 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
render_403: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 222 | 2 | $_[0]->render_error(403); | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | sub render_404 | ||||||||||||||||||||||||||||
| 226 | 15 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
render_404: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 227 | 15 | $_[0]->render_error(404); | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | sub render_500 | ||||||||||||||||||||||||||||
| 231 | 38 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
render_500: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 232 | 38 | my ($self, $error) = @_; | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | # Do not leak information on production! | ||||||||||||||||||||||||||||
| 235 | 38 | ▶ | if ($self->app->is_production) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 14 | return $self->render_error; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | # if render_500 gets blessed object as error, stringify it | ||||||||||||||||||||||||||||
| 240 | 24 | ▶ | $error = "$error" if blessed $error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | 24 | ▶ | $error //= 'No error, something is wrong'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$error //= "No error, something is wrong"
MC/DC100%1/1
$error //= "No error, something is wrong"
$error
Truth table100%2/2
A
A= $error
| |||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | # at this point, error will never be in HTML, since the exception body | ||||||||||||||||||||||||||||
| 244 | # would have to be HTML itself. Try to nest it inside a template. NOTE: We | ||||||||||||||||||||||||||||
| 245 | # don't currently handle ref errors here which aren't objects | ||||||||||||||||||||||||||||
| 246 | 24 | return $self->render_error(500, $error); | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | sub redirect | ||||||||||||||||||||||||||||
| 250 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
redirect: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 251 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 252 | 7 | $self->rendered(1); | |||||||||||||||||||||||||||
| 253 | 7 | $self->SUPER::redirect(@_); | |||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | sub redirect_to | ||||||||||||||||||||||||||||
| 257 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
redirect_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 258 | 7 | my ($self, $where, $args, $code) = @_; | |||||||||||||||||||||||||||
| 259 | 7 | my $url = $self->app->url_for($where, %$args); | |||||||||||||||||||||||||||
| 260 | 7 | $self->redirect($url, $code); | |||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | sub template | ||||||||||||||||||||||||||||
| 264 | 74 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
template: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 265 | 74 | my ($self, $template, $vars, @rest) = @_; | |||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | # Do we have a template module loaded? | ||||||||||||||||||||||||||||
| 268 | 74 | ▶ | croak "No template module loaded" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | unless $self->app->can('template'); | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | # run template in current controller context | ||||||||||||||||||||||||||||
| 272 | 74 | my $output = $self->app->context->run_method('template', $template, $vars, @rest); | |||||||||||||||||||||||||||
| 273 | 50 | $self->render($output); | |||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 30 | 1; | |||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | __END__ | ||||||||||||||||||||||||||||