lib/PAGI/App/NotFound.pm

filter: Statementstmt 100% 25 / 25 Branchbran 100% 2 / 2 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 95.5% 43 / 45 CC 5 SCAR 8.2
CC
5
Cov
100%
new
4.0
__ANON__
2.0
BEGIN
1.0
CRAP 2.3
« blib/lib/PAGI/Test/ConnectionState.pm ↑ Summary examples/endpoint-router-demo/lib/MyApp/Main.pm »
1 package PAGI::App::NotFound;
2 1 $PAGI::App::NotFound::VERSION = '0.002002';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use PAGI::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 PAGI::App::NotFound - Customizable 404 response
11  
12 =head1 SYNOPSIS
13  
14 # A fixed 404 is just a response value (preferred):
15 use PAGI::Response;
16 $router->mount('/missing' => PAGI::Response->text('Not Found')->status(404));
17  
18 # PAGI::App::NotFound is for a computed body or custom defaults
19 # (e.g. a Cascade fallback):
20 use PAGI::App::NotFound;
21 my $app = PAGI::App::NotFound->new(
22 status => 404,
23 content_type => 'text/html',
24 body => sub { my ($scope) = @_; render_404($scope) },
25 )->to_app;
26  
27 =cut
28  
29 5 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod undocumented
30 5 my ($class, %args) = @_;
31  
32 return bless {
33 body => $args{body} // 'Not Found',
34 content_type => $args{content_type} // 'text/plain',
35 5 ▶ status => $args{status} // 404,
Condition100%6/6
$args{"body"} // "Not Found"
l!l
23
$args{"content_type"} // "text/plain"
l!l
14
$args{"status"} // 404
l!l
14
MC/DC100%1/1
$args{"body"} // "Not Found"
$args{"body"}
MC/DC100%1/1
$args{"content_type"} // "text/plain"
$args{"content_type"}
MC/DC100%1/1
$args{"status"} // 404
$args{"status"}
Truth table100%2/2
A
A= $args{"body"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"content_type"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"status"}
Aresult
11
00
36 }, $class;
37 }
38  
39 5 ▶sub to_app {
Subroutine to_app: called CC=1 SCAR=0.0
Pod undocumented
40 5 my ($self) = @_;
41  
42 5 my $body = $self->{body};
43 5 my $content_type = $self->{content_type};
44 5 my $status = $self->{status};
45  
46 5 ▶ return async sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
47 5 my ($scope, $receive, $send) = @_;
48 5 ▶ my $b = ref $body eq 'CODE' ? $body->($scope) : $body;
Branch: 1 branch
BranchTrueFalseTotal
ref $body eq 'CODE' ? : 1 4 5
49  
50 5 await PAGI::Response->new($scope)
51 ->status($status)
52 ->content_type($content_type)
53 ->send_raw($b)
54 ->respond($send);
55 5 };
56 }
57  
58 1 1;
59  
60 __END__
« blib/lib/PAGI/Test/ConnectionState.pm ↑ Summary examples/endpoint-router-demo/lib/MyApp/Main.pm »