blib/lib/Kossy/Exception.pm

filter: Statementstmt 100% 41 / 41 Branchbran 100% 8 / 8 Conditioncond 87.5% 7 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 3 totaltotal 91.7% 67 / 73 CC 8 SCAR 12.2
CC
8
Cov
98%
response
6.0
new
3.0
BEGIN
1.0
CRAP 3.4
« blib/lib/Kossy.pm ↑ Summary blib/lib/Kossy/Request.pm »
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
BranchTrueFalseTotal
if (@_ == 1) { } 1 16 17
elsif (@_ % 2 == 0) { } 15 1 16
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
l!l
143
MC/DC100%1/1
$self->{'code'} || 500
$self->{'code'}
Truth table100%2/2
A
A= $self->{'code'}
Aresult
11
00
32  
33 17 ▶ if ($self->{response}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'response'}) { } 6 11 17
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)
l!l&&r!l&&!r
290
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)
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($code =~ /^3/ and my $loc = eval { do { $self->{"location"} } }) 1 10 11
Condition100%3/3
$code =~ /^3/ and my $loc = eval { do { $self->{"location"} } }
!ll&&!rl&&r
911
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"} } }
ABresult
0X0
100
111
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;
« blib/lib/Kossy.pm ↑ Summary blib/lib/Kossy/Request.pm »