Dancer2-Plugin-BrowserDetect
view release on metacpan or search on metacpan
lib/Dancer2/Plugin/BrowserDetect.pm view on Meta::CPAN
#
# This file is part of Dancer2-Plugin-BrowserDetect
#
# This software is copyright (c) 2016 by Natal Ngétal.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
package Dancer2::Plugin::BrowserDetect;
$Dancer2::Plugin::BrowserDetect::VERSION = '1.163590';
use strict;
use warnings;
use Dancer2::Plugin 0.200000;
use HTTP::BrowserDetect ();
use Scalar::Util ();
#ABSTRACT: Provides an easy to have info of the browser.
sub BUILD {
my $plugin = shift;
# Create a weakened plugin that we can close over to avoid leaking.
Scalar::Util::weaken( my $weak_plugin = $plugin );
$plugin->app->add_hook(
Dancer2::Core::Hook->new(
name => 'before_template',
code => sub {
my $tokens = shift;
$tokens->{browser_detect} = $weak_plugin->browser_detect;
},
)
);
}
plugin_keywords 'browser_detect';
sub browser_detect {
my $plugin = shift;
my $useragent = $plugin->app->request->env->{HTTP_USER_AGENT};
my $browser = HTTP::BrowserDetect->new($useragent);
return $browser;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Dancer2::Plugin::BrowserDetect - Provides an easy to have info of the browser.
=head1 VERSION
version 1.163590
=head1 SYNOPSIS
use Dancer2;
use Dancer2::Plugin::BrowserDetect;
get '/' => sub {
my $browser = browser_detect();
if ( $browser->windows && $browser->ie && $browser->major() < 6 ) {
return "You have big failed, change your os, browser, and come back late.";
}
};
dance;
=head1 DESCRIPTION
Provides an easy to have info of the browser.
keyword within your L<Dancer> application.
=head1 METHODS
( run in 3.063 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )