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.162360';
11 2     2   387245 use strict;
  2         2  
  2         43  
12 2     2   6 use warnings;
  2         2  
  2         35  
13              
14 2     2   871 use Dancer2::Plugin;
  2         61178  
  2         11  
15              
16 2     2   15797 use HTTP::BrowserDetect;
  2         21563  
  2         289  
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   9114 my $dsl = shift;
36 1         3 _browser_detect($dsl);
37             };
38              
39             sub _browser_detect {
40 1     1   2 my $dsl = shift;
41 1         8 my $useragent = $dsl->app->request->env->{HTTP_USER_AGENT};
42 1         8 my $browser = HTTP::BrowserDetect->new($useragent);
43              
44 1         84 return $browser;
45             }
46              
47             register_plugin;
48              
49              
50             1;
51              
52             __END__