blib/lib/Kossy/Exception.pm

filter: Statementstmt 92.1% 35 / 38 Branchbran 50.0% 3 / 6 Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 3 totaltotal 72.0% 49 / 68 CC 7 SCAR 12.7
CC
7
Cov
79%
response
6.9
new
3.2
BEGIN
1.0
CRAP 3.6
« blib/lib/Kossy/Response.pm ↑ Summary blib/lib/Kossy/Request.pm »
1 package Kossy::Exception;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use HTTP::Status;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Text::Xslate qw/html_escape/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Kossy::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 our $VERSION = '0.38';
10  
11 sub new {
12 4 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=11.6
Pod undocumented
13 4 my $code = shift;
14 4 my %args = (
15 code => $code,
16 );
17 4 ▶ if ( @_ == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1) { } 0 4 4
elsif (@_ % 2 == 0) { } 4 0 4
18 0 $args{message} = shift;
19 }
20 elsif ( @_ % 2 == 0) {
21 4 %args = (
22 %args,
23 @_
24 );
25 }
26 4 bless \%args, $class;
27 }
28  
29 sub response {
30 4 ▶ my $self = shift;
Subroutine response: called CC=5 SCAR=19.3
Pod undocumented
31 4 ▶ my $code = $self->{code} || 500;
Condition50%1/2
$self->{'code'} || 500
l!l
40
MC/DC0%0/1
$self->{'code'} || 500
$self->{'code'}
Truth table50%1/2
A
A= $self->{'code'}
Aresult
11
00
32 4 my $message = $self->{message};
33 4 ▶ $message ||= HTTP::Status::status_message($code);
Condition33%1/3
$message ||= &HTTP::Status::status_message($code)
l!l&&r!l&&!r
040
MC/DC0%0/2
$message ||= &HTTP::Status::status_message($code)
$message &HTTP::Status::status_message($code)
Truth table33%1/3
A ||= B
A= $messageB= &HTTP::Status::status_message($code)
ABresult
1X1
011
000
34  
35 4 my @headers = (
36 'Content-Type' => q!text/html; charset=UTF-8!,
37 );
38  
39 4 ▶ if ($code =~ /^3/ && (my $loc = eval { $self->{location} })) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code =~ /^3/ and my $loc = eval { do { $self->{"location"} } }) 0 4 4
Condition33%1/3
$code =~ /^3/ and my $loc = eval { do { $self->{"location"} } }
!ll&&!rl&&r
400
MC/DC0%0/2
$code =~ /^3/ and my $loc = eval { do { $self->{"location"} } }
$code =~ /^3/ my $loc = eval { do { $self->{"location"} } }
Truth table33%1/3
A and B
A= $code =~ /^3/B= my $loc = eval { do { $self->{"location"} } }
ABresult
0X0
100
111
40 0 push(@headers, Location => $loc);
41 }
42  
43 4 return Kossy::Response->new($code, \@headers, [$self->html($code,$message)])->finalize;
44 }
45  
46 sub html {
47 4 ▶ my $self = shift;
Subroutine html: called CC=1 SCAR=0.0
Pod undocumented
48 4 my ($code,$message) = @_;
49 4 $code = html_escape($code);
50 4 $message = html_escape($message);
51 4 return <<EOF;
52 <!doctype html>
53 <html>
54 <head>
55 <meta charset=utf-8 />
56 <style type="text/css">
57 .message {
58 font-size: 200%;
59 margin: 20px 20px;
60 color: #666;
61 }
62 .message strong {
63 font-size: 250%;
64 font-weight: bold;
65 color: #333;
66 }
67 </style>
68 </head>
69 <body>
70 <p class="message">
71 <strong>$code</strong> $message
72 </p>
73 </div>
74 </body>
75 </html>
76 EOF
77 }
78  
79 6 1;
« blib/lib/Kossy/Response.pm ↑ Summary blib/lib/Kossy/Request.pm »