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