blib/lib/Yukki/Error.pm

filter: Statementstmt 74.5% 41 / 55 Branchbran 0.0% 0 / 2 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 81.2% 13 / 16 Podpod 50.0% 4 / 8 totaltotal 68.9% 60 / 87 CC 4 SCAR 6.7
CC
4
Cov
70%
__ANON__
6.0
http_exception
3.1
body
2.0
CRAP 2.0
« blib/lib/Yukki/Web/View/Login.pm ↑ Summary blib/lib/Yukki/Web/Settings.pm »
1 package Yukki::Error;
2 22 $Yukki::Error::VERSION = '0.991_007'; # TRIAL
3 22 $Yukki::Error::VERSION = '0.991007';
4 22 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 22 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 22 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 22 extends qw( HTTP::Throwable::Factory );
9  
10 22 ▶use Yukki::Web::View;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 22 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 22 ▶use Sub::Exporter -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
15 exports => [ qw< http_throw http_exception > ],
16 22 };
17  
18 # ABSTRACT: Yukki's exception class
19  
20  
21 1 ▶sub base_class { 'Yukki::Error' }
Subroutine base_class: called CC=1 SCAR=0.0
Pod documented
22 1 ▶sub extra_roles { 'Yukki::Error::Body' }
Subroutine extra_roles: called CC=1 SCAR=0.0
Pod documented
23  
24  
25 1 ▶sub http_exception {
Subroutine http_exception: called CC=3 SCAR=11.3
Pod documented
26 1 my ($name, $args) = @_;
27  
28 1 ▶ my %args = %{ $args // {} };
Condition50%1/2
$args // {}
l!l
10
MC/DC0%0/1
$args // {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
29 1 ▶ my $status = delete $args{status} // 'InternalServerError';
Condition50%1/2
delete $args{"status"} // "InternalServerError"
l!l
10
MC/DC0%0/1
delete $args{"status"} // "InternalServerError"
delete $args{"status"}
Truth table50%1/2
A
A= delete $args{"status"}
Aresult
11
00
30  
31 1 Yukki::Error->new_exception($status => {
32 %args,
33 message => "$name",
34 });
35 }
36  
37  
38 1 ▶sub http_throw {
Subroutine http_throw: called CC=1 SCAR=0.0
Pod documented
39 1 my ($name, $args) = @_;
40  
41 1 http_exception($name, $args)->throw;
42 }
43  
44 1 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=1 SCAR=0.0
Pod undocumented
45 1 my ($class, $args) = @_;
46 1 $args;
47 }
48  
49  
50 {
51 22 package Yukki::Error::Body;
52 22 $Yukki::Error::Body::VERSION = '0.991_007'; # TRIAL
53 22 $Yukki::Error::Body::VERSION = '0.991007';
54 22 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56  
57 0 ▶ sub body {
Subroutine body: not called CC=1 SCAR=6.9
Pod undocumented
58 0 my ($self, $env) = @_;
59  
60 0 my $app = $env->{'yukki.app'};
61 0 my $view = Yukki::Web::View->new(app => $app);
62 0 my $ctx = Yukki::Web::Context->new(env => $env);
63  
64 0 my $template = $view->prepare_template(
65 template => 'error.html',
66 directives => [
67 '#error-page' => 'error_message',
68 ],
69 );
70  
71 0 $ctx->response->page_title($self->reason);
72  
73 0 return $view->render_page(
74 template => $template,
75 context => $ctx,
76 vars => {
77 'error_message' => $self->message,
78 },
79 );
80 }
81  
82  
83 0 ▶ sub body_headers {
Subroutine body_headers: not called CC=1 SCAR=6.9
Pod undocumented
84 0 my ($self, $body) = @_;
85  
86 return [
87 0 'Content-type' => 'text/html',
88 'Content-length' => length $body,
89 ];
90 }
91  
92  
93 2 ▶ sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod undocumented
94 2 my $self = shift;
95 2 return $self->message;
96 }
97  
98 0 ▶ around as_psgi => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
99 0 shift; # original method is ignored
100 0 my ($self, $env) = @_;
101 0 my $body = $self->body( $env );
102 0 my $headers = $self->build_headers( $body );
103 0 ▶ [ $self->status_code, $headers, [ defined $body ? $body : () ] ];
Branch: 1 branch
BranchTrueFalseTotal
defined $body ? : 0 0 0
104 22 };
105  
106 }
107  
108 22 1;
109  
110 __END__
« blib/lib/Yukki/Web/View/Login.pm ↑ Summary blib/lib/Yukki/Web/Settings.pm »