| 1 | package Kossy::Exception; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use HTTP::Status; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Text::Xslate qw/html_escape/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use Kossy::Response; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 10 | our $VERSION = '0.50'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub new { | ||||||||||||||||||||||||||||
| 12 | 17 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 17 | my $code = shift; | |||||||||||||||||||||||||||
| 14 | 17 | my %args = ( | |||||||||||||||||||||||||||
| 15 | code => $code, | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | 17 | ▶ | if ( @_ == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 18 | 1 | $args{message} = shift; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | elsif ( @_ % 2 == 0) { | ||||||||||||||||||||||||||||
| 21 | 15 | %args = ( | |||||||||||||||||||||||||||
| 22 | %args, | ||||||||||||||||||||||||||||
| 23 | @_ | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | 17 | bless \%args, $class; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub response { | ||||||||||||||||||||||||||||
| 30 | 17 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
response: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 17 | ▶ | my $code = $self->{code} || 500; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'code'} || 500
MC/DC100%1/1
$self->{'code'} || 500
$self->{'code'}
Truth table100%2/2
A
A= $self->{'code'}
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 17 | ▶ | if ($self->{response}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 6 | $self->{response}->code($code); | |||||||||||||||||||||||||||
| 35 | 6 | return $self->{response}->finalize; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | else { | ||||||||||||||||||||||||||||
| 38 | 11 | my $message = $self->{message}; | |||||||||||||||||||||||||||
| 39 | 11 | ▶ | $message ||= HTTP::Status::status_message($code); | ||||||||||||||||||||||||||
|
Condition66%2/3
$message ||= &HTTP::Status::status_message($code)
MC/DC0%0/2
$message ||= &HTTP::Status::status_message($code)
$message
&HTTP::Status::status_message($code)
Truth table66%2/3
A ||= B
A= $messageB= &HTTP::Status::status_message($code)
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 11 | my @headers = ( | |||||||||||||||||||||||||||
| 42 | 'Content-Type' => q!text/html; charset=UTF-8!, | ||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 11 | ▶ | if ($code =~ /^3/ && (my $loc = eval { $self->{location} })) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$code =~ /^3/ and my $loc = eval {
do {
$self->{"location"}
}
}
MC/DC100%2/2
$code =~ /^3/ and my $loc = eval {
do {
$self->{"location"}
}
}
$code =~ /^3/
my $loc = eval {
do {
$self->{"location"}
}
}
Truth table100%3/3
A and B
A= $code =~ /^3/B= my $loc = eval {
do {
$self->{"location"}
}
}
| |||||||||||||||||||||||||||||
| 46 | 1 | push(@headers, Location => $loc); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 11 | return Kossy::Response->new($code, \@headers, [$self->html($code,$message)])->finalize; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | sub html { | ||||||||||||||||||||||||||||
| 54 | 11 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
html: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 11 | my ($code,$message) = @_; | |||||||||||||||||||||||||||
| 56 | 11 | $code = html_escape($code); | |||||||||||||||||||||||||||
| 57 | 11 | $message = html_escape($message); | |||||||||||||||||||||||||||
| 58 | 11 | return <<EOF; | |||||||||||||||||||||||||||
| 59 | <!doctype html> | ||||||||||||||||||||||||||||
| 60 | <html> | ||||||||||||||||||||||||||||
| 61 | <head> | ||||||||||||||||||||||||||||
| 62 | <meta charset=utf-8 /> | ||||||||||||||||||||||||||||
| 63 | <style type="text/css"> | ||||||||||||||||||||||||||||
| 64 | .message { | ||||||||||||||||||||||||||||
| 65 | font-size: 200%; | ||||||||||||||||||||||||||||
| 66 | margin: 20px 20px; | ||||||||||||||||||||||||||||
| 67 | color: #666; | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | .message strong { | ||||||||||||||||||||||||||||
| 70 | font-size: 250%; | ||||||||||||||||||||||||||||
| 71 | font-weight: bold; | ||||||||||||||||||||||||||||
| 72 | color: #333; | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | </style> | ||||||||||||||||||||||||||||
| 75 | </head> | ||||||||||||||||||||||||||||
| 76 | <body> | ||||||||||||||||||||||||||||
| 77 | <p class="message"> | ||||||||||||||||||||||||||||
| 78 | <strong>$code</strong> $message | ||||||||||||||||||||||||||||
| 79 | </p> | ||||||||||||||||||||||||||||
| 80 | </div> | ||||||||||||||||||||||||||||
| 81 | </body> | ||||||||||||||||||||||||||||
| 82 | </html> | ||||||||||||||||||||||||||||
| 83 | EOF | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 10 | 1; | |||||||||||||||||||||||||||