-
-
18 May 2012 09:21:47 UTC
- Distribution: Dancer-Plugin-Res
- Module version: 0.0003
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues
- Testers (152 / 0 / 0)
- Kwalitee
Bus factor: 1- % Coverage
- License: perl_5
- Activity
24 month- Tools
- Download (9.01KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- Dancer
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Dancer::Plugin::Res - Syntax sugar for setting the status and returning a response
VERSION
version 0.0003
SYNOPSIS
use Dancer; use Dancer::Plugin::Res; post '/widgets' => sub { return res 400 => to_json { err => 'name is required' } unless param 'name'; # ... return res 201 => to_json { widget => $widget }; }; dance;
DESCRIPTION
This Dancer plugin provides the keyword
res()
, which stands for response. It allows you to set the response and return a body in one shot.return res 400, { msg => reason };
is equivalent to:
status 400; return { msg => reason };
I made this plugin because I wanted a function like send_error() that behaved more consistently.
send_error("reason ...", 500)
will not always render the first argument you give it in the response. When your app is running in production mode withshow_errors
set to false, it will attempt to render a generic 500.html page. This is great for front-end only applications, but not for creating an api where you always want your application to render the thing that you told it to render.FUNCTIONS
res
res($status, [$reason])
Sets the status to $status and returns $reason. If $reason is not provided, returns an empty string.
AUTHOR
Naveed Massjouni <naveedm9@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Naveed Massjouni.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Module Install Instructions
To install Dancer::Plugin::Res, copy and paste the appropriate command in to your terminal.
cpanm Dancer::Plugin::Res
perl -MCPAN -e shell install Dancer::Plugin::Res
For more information on module installation, please visit the detailed CPAN module installation guide.