| 1 |
package Dancer2::Core::Role::StandardResponses; |
| 2 |
# ABSTRACT: Role to provide commonly used responses |
| 3 |
$Dancer2::Core::Role::StandardResponses::VERSION = '2.2.2'; |
| 4 |
use Moo::Role; |
| 5 |
use Dancer2::Core::HTTP; |
| 6 |
|
| 7 |
sub response { |
| 8 |
my ( $self, $app, $code, $message ) = @_; |
| 9 |
$app->response->status($code); |
| 10 |
$app->response->header( 'Content-Type', 'text/plain' ); |
| 11 |
return $message; |
| 12 |
} |
| 13 |
|
| 14 |
sub standard_response { |
| 15 |
my ( $self, $app, $status_code ) = @_; |
| 16 |
|
| 17 |
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 2.2.2 |
| 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) 2026 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 |