File Coverage

blib/lib/Dancer2/Plugin/Res.pm
Criterion Covered Total %
statement 18 18 100.0
branch 1 2 50.0
condition n/a
subroutine 6 6 100.0
pod n/a
total 25 26 96.1


line stmt bran cond sub pod time code
1             package Dancer2::Plugin::Res;
2              
3             $Dancer2::Plugin::Res::VERSION = '0.10';
4             $Dancer2::Plugin::Res::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             Dancer2::Plugin::Res - Dancer2 add-on for setting status/response.
9              
10             =head1 VERSION
11              
12             Version 0.10
13              
14             =cut
15              
16 2     2   787905 use 5.006;
  2         12  
17 2     2   10 use strict; use warnings;
  2     2   4  
  2         43  
  2         10  
  2         4  
  2         62  
18 2     2   557 use Data::Dumper;
  2         5679  
  2         105  
19              
20 2     2   926 use Dancer2::Plugin;
  2         202168  
  2         14  
21              
22             =head1 DESCRIPTION
23              
24             This is an honest attempt to make L to be Dancer2 friendly.
25             It should behave same as it's twin as nothing has changed in functionality.
26              
27             I needed a Dancer2 compatible version of L for my other work
28             available on L.
29              
30             =head1 SYNOPSIS
31              
32             As used in L project
33              
34             use Dancer2::Plugin::Res;
35             use Dancer2::Plugin::Captcha;
36              
37             post '/login' => sub {
38              
39             return res(400 => 'Invalid captcha code')
40             unless (is_valid_captcha(request->params->{captcha}));
41              
42             ...
43             ...
44             ...
45             }
46              
47             =head1 METHODS
48              
49             =head2 res($status, $reason)
50              
51             The param C<$status> is required, whereas C<$reason> is optional. It sets the
52             status and returns the reason, if provided, otherwise an empty string.
53              
54             =cut
55              
56             register res => sub {
57 1     1   181331 my ($dsl, $status, $body) = @_;
58              
59 1 50       4 $body = '' unless defined $body;
60 1         19 $dsl->status($status);
61              
62 1         104 return $body;
63             };
64              
65             register_plugin;
66              
67             =head1 AUTHOR
68              
69             Mohammad S Anwar, C<< >>
70              
71             =head1 REPOSITORY
72              
73             L
74              
75             =head1 ACKNOWLEDGEMENTS
76              
77             Inspired by the package L (Naveed Massjouni ).
78              
79             =head1 SEE ALSO
80              
81             L
82              
83             =head1 BUGS
84              
85             Please report any bugs or feature requests to C,
86             or through the web interface at L.
87             I will be notified and then you'll automatically be notified of progress on your
88             bug as I make changes.
89              
90             =head1 SUPPORT
91              
92             You can find documentation for this module with the perldoc command.
93              
94             perldoc Dancer2::Plugin::Res
95              
96             You can also look for information at:
97              
98             =over 4
99              
100             =item * RT: CPAN's request tracker (report bugs here)
101              
102             L
103              
104             =item * AnnoCPAN: Annotated CPAN documentation
105              
106             L
107              
108             =item * CPAN Ratings
109              
110             L
111              
112             =item * Search CPAN
113              
114             L
115              
116             =back
117              
118             =head1 LICENSE AND COPYRIGHT
119              
120             Copyright (C) 2015 - 2019 Mohammad S Anwar.
121              
122             This program is free software; you can redistribute it and / or modify it under
123             the terms of the the Artistic License (2.0). You may obtain a copy of the full
124             license at:
125              
126             L
127              
128             Any use, modification, and distribution of the Standard or Modified Versions is
129             governed by this Artistic License.By using, modifying or distributing the Package,
130             you accept this license. Do not use, modify, or distribute the Package, if you do
131             not accept this license.
132              
133             If your Modified Version has been derived from a Modified Version made by someone
134             other than you,you are nevertheless required to ensure that your Modified Version
135             complies with the requirements of this license.
136              
137             This license does not grant you the right to use any trademark, service mark,
138             tradename, or logo of the Copyright Holder.
139              
140             This license includes the non-exclusive, worldwide, free-of-charge patent license
141             to make, have made, use, offer to sell, sell, import and otherwise transfer the
142             Package with respect to any patent claims licensable by the Copyright Holder that
143             are necessarily infringed by the Package. If you institute patent litigation
144             (including a cross-claim or counterclaim) against any party alleging that the
145             Package constitutes direct or contributory patent infringement,then this Artistic
146             License to you shall terminate on the date that such litigation is filed.
147              
148             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
149             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
150             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
151             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
152             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
153             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
154             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
155              
156             =cut
157              
158             1; # End of Dancer2::Plugin::Res