Dancer::Plugin::Negotiate - Content negotiation plugin for Dancer
Version 0.031
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
This module is a wrapper for HTTP::Negotiate.
choose_variant(%variants)
%options is a hash like this:
%options
%variants = ( $identifier => \%options )
The key $identifier is a string that will be returned by choose_variant().
$identifier
choose_variant()
Valid keywords of hashref \%options:
\%options
A float point value between 0.000 and 1.000, describing the source quality (defaults to 1)
A MIME media type (with no charset attributes, but other attributes like version)
An encoding like gzip or compress
An encoding like utf-8 or iso-8859-1
A language tag conforming to RFC 3066
Number of bytes used to represent
Returns undef if no variant matched.
undef
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.
choose_variant
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.
$template_name
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.
template()
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' });
David Zurborg, <zurborg@cpan.org>
<zurborg@cpan.org>
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.
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
http://annocpan.org/dist/Dancer-Plugin-Negotiate
CPAN Ratings
http://cpanratings.perl.org/d/Dancer-Plugin-Negotiate
Search CPAN
http://search.cpan.org/dist/Dancer-Plugin-Negotiate/
Copyright 2014 David Zurborg, all rights reserved.
This program is released under the following license: open-source
To install Dancer::Plugin::Negotiate, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Plugin::Negotiate
CPAN shell
perl -MCPAN -e shell install Dancer::Plugin::Negotiate
For more information on module installation, please visit the detailed CPAN module installation guide.