File Coverage

blib/lib/Dancer2/Core/Role/StandardResponses.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod 2 2 100.0
total 18 18 100.0


line stmt bran cond sub pod time code
1             package Dancer2::Core::Role::StandardResponses;
2             # ABSTRACT: Role to provide commonly used responses
3             $Dancer2::Core::Role::StandardResponses::VERSION = '0.400001';
4 145     145   82407 use Moo::Role;
  145         384  
  145         998  
5 145     145   60859 use Dancer2::Core::HTTP;
  145         373  
  145         21259  
6              
7             sub response {
8 2     2 1 35138 my ( $self, $app, $code, $message ) = @_;
9 2         13 $app->response->status($code);
10 2         2373 $app->response->header( 'Content-Type', 'text/plain' );
11 2         3638 return $message;
12             }
13              
14             sub standard_response {
15 1     1 1 1068 my ( $self, $app, $status_code ) = @_;
16              
17 1         11 return $self->response(
18             $app,
19             $status_code,
20             Dancer2::Core::HTTP->status_message($status_code),
21             );
22             }
23              
24             1;
25              
26             __END__
27              
28             =pod
29              
30             =encoding UTF-8
31              
32             =head1 NAME
33              
34             Dancer2::Core::Role::StandardResponses - Role to provide commonly used responses
35              
36             =head1 VERSION
37              
38             version 0.400001
39              
40             =head1 METHODS
41              
42             =head2 response
43              
44             Generic method that produces a custom response given with a code and a message:
45              
46             $self->response( $app, 404, 'Not Found' );
47              
48             This could be used to create your own, which is separate from the standard one:
49              
50             $self->response( $app, 404, 'File missing in action' );
51              
52             =head2 standard_response
53              
54             Produces a standard response using the code.
55              
56             # first example can be more easily written as
57             $self->standard_response( $app, 404 );
58              
59             =head1 AUTHOR
60              
61             Dancer Core Developers
62              
63             =head1 COPYRIGHT AND LICENSE
64              
65             This software is copyright (c) 2023 by Alexis Sukrieh.
66              
67             This is free software; you can redistribute it and/or modify it under
68             the same terms as the Perl 5 programming language system itself.
69              
70             =cut