File Coverage

blib/lib/Dancer2/Plugin/BrowserDetect.pm
Criterion Covered Total %
statement 18 18 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 24 24 100.0


line stmt bran cond sub pod time code
1             #
2             # This file is part of Dancer-Plugin-Browser
3             #
4             # This software is copyright (c) 2016 by Natal Ngétal.
5             #
6             # This is free software; you can redistribute it and/or modify it under
7             # the same terms as the Perl 5 programming language system itself.
8             #
9             package Dancer2::Plugin::BrowserDetect;
10             $Dancer2::Plugin::BrowserDetect::VERSION = '1.160190';
11 2     2   495767 use strict;
  2         4  
  2         51  
12 2     2   10 use warnings;
  2         4  
  2         51  
13              
14 2     2   1530 use Dancer2::Plugin;
  2         1719179  
  2         19  
15              
16 2     2   5276 use HTTP::BrowserDetect;
  2         33509  
  2         418  
17              
18             #ABSTRACT: Provides an easy to have info of the browser.
19              
20              
21             on_plugin_import {
22             my $dsl = shift;
23             $dsl->app->add_hook(
24             Dancer2::Core::Hook->new(
25             name => 'before_template',
26             code => sub {
27             my $tokens = shift;
28             $tokens->{browser_detect} = _browser_detect($dsl);
29             },
30             )
31             );
32             };
33              
34             register browser_detect => sub {
35 1     1   11954 my $dsl = shift;
36 1         5 _browser_detect($dsl);
37             };
38              
39             sub _browser_detect {
40 1     1   2 my $dsl = shift;
41 1         12 my $useragent = $dsl->app->request->env->{HTTP_USER_AGENT};
42 1         14 my $browser = HTTP::BrowserDetect->new($useragent);
43              
44 1         106 return $browser;
45             }
46              
47             register_plugin;
48              
49              
50             1;
51              
52             __END__