NAME
Dancer::Plugin::Negotiate - Content negotiation plugin for Dancer
VERSION
Version 0.031
SYNOPSIS
use Dancer::Plugin::Negotiate;
$variant = choose_variant(
var1 => {
Quality => 1.000,
Type => 'text/html',
Charset => 'iso-8859-1',
Language => 'en',
Size => 3000
},
var2 => {
Quality => 0.950,
Type => 'text/plain',
Charset => 'us-ascii',
Language => 'no',
Size => 400
},
var3 => {
Quality => 0.3,
Type => 'image/gif',
Size => 43555
}
); # returns 'var1' or 'var2' or 'var3' or undef
DESCRIPTION
This module is a wrapper for HTTP::Negotiate.
KEYWORDS
choose_variant(%variants)
%options
is a hash like this:
%variants = (
$identifier => \%options
)
The key $identifier
is a string that will be returned by choose_variant()
.
Valid keywords of hashref \%options
:
- Quality
-
A float point value between 0.000 and 1.000, describing the source quality (defaults to 1)
- Type
-
A MIME media type (with no charset attributes, but other attributes like version)
- Encoding
-
An encoding like gzip or compress
- Charset
-
An encoding like utf-8 or iso-8859-1
- Language
-
A language tag conforming to RFC 3066
- Size
-
Number of bytes used to represent
Returns undef
if no variant matched.
See HTTP::Negotiate for more information.
apply_variant(%options)
This method behaves like choose_variant
but sets the according response headers if a variant matched.
negotiate($template_name)
This method returns $template_name
with a suffixed language tag. The file needs to exist. This method behaves similiary to mod_negotiate of apache httpd's.
Language tags must be specified in plugin settings and ordered by priority:
plugin:
Negotiate:
languages:
- en
- de
- fr
The result of this method can be propagated to template()
in order to render a localized version of the file.
get '/index' => sub {
return template negotiate 'index';
}; # renders index.de.tt or index.en.tt or index.fr.tt or index.tt
Falls back to $template_name
if negotiaten fails.
Hint: additional arguments applies to template()
:
template negotiate index => { foo => 'bar' };
# is the same as
template(negotiate('index'), { foo => 'bar' });
AUTHOR
David Zurborg, <zurborg@cpan.org>
BUGS
Please report any bugs or feature requests through my project management tool at http://development.david-zurb.org/projects/libdancer-plugin-negotiate-perl/issues/new. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Dancer::Plugin::Negotiate
You can also look for information at:
Redmine: Homepage of this module
http://development.david-zurb.org/projects/libdancer-plugin-negotiate-perl
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dancer-Plugin-Negotiate
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
COPYRIGHT & LICENSE
Copyright 2014 David Zurborg, all rights reserved.
This program is released under the following license: open-source