File Coverage

blib/lib/Dancer2/Plugin/BrowserDetect.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 26 26 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) 2014 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             {
11             $Dancer2::Plugin::BrowserDetect::VERSION = '1.141180';
12             }
13              
14 2     2   493009 use strict;
  2         5  
  2         52  
15 2     2   10 use warnings;
  2         6  
  2         58  
16              
17 2     2   891 use Dancer2 ':syntax';
  2         439807  
  2         13  
18 2     2   85028 use Dancer2::Plugin;
  2         4926  
  2         14  
19              
20 2     2   4220 use HTTP::BrowserDetect;
  2         36783  
  2         401  
21              
22             #ABSTRACT: Provides an easy to have info of the browser.
23              
24              
25             hook before_template => sub {
26             my $tokens = shift;
27              
28             $tokens->{browser_detect} = _browser_detect();
29             };
30              
31             register browser_detect => sub {
32 1     1   12065 _browser_detect();
33             };
34              
35             sub _browser_detect {
36 1     1   6 my $useragent = request->env->{HTTP_USER_AGENT};
37 1         255 my $browser = HTTP::BrowserDetect->new($useragent);
38              
39 1         158 return $browser;
40             }
41              
42             register_plugin for_versions => [2];
43              
44              
45             1;
46              
47             __END__
48              
49             =pod
50              
51             =head1 NAME
52              
53             Dancer2::Plugin::BrowserDetect - Provides an easy to have info of the browser.
54              
55             =head1 VERSION
56              
57             version 1.141180
58              
59             =head1 SYNOPSIS
60              
61             use Dancer2;
62             use Dancer2::Plugin::BrowserDetect;
63              
64             get '/' => sub {
65             my $browser = browser_detect();
66              
67             if ( $browser->windows && $browser->ie && $browser->major() < 6 ) {
68             return "You have big failed, change your os, browser, and come back late.";
69             }
70             };
71              
72             dance;
73              
74             =head1 DESCRIPTION
75              
76             Provides an easy to have info of the browser.
77             keyword within your L<Dancer> application.
78              
79             =head1 METHODS
80              
81             =head2 browser_detect
82              
83             browser_detect()
84             or
85             <% browser_detect %>
86              
87             To have info of the browser
88              
89             input: none
90             output: A HTTP::BrowserDetect object
91              
92             =encoding utf8
93              
94             =head1 CONTRIBUTING
95              
96             This module is developed on Github at:
97              
98             L<https://github.com/hobbestigrou/Dancer2-Plugin-Browser>
99              
100             Feel free to fork the repo and submit pull requests
101              
102             =head1 BUGS
103              
104             Please report any bugs or feature requests in github.
105              
106             =head1 SUPPORT
107              
108             You can find documentation for this module with the perldoc command.
109              
110             perldoc Dancer2::Plugin::BrowserDetect
111              
112             =head1 SEE ALSO
113              
114             L<Dancer>
115             L<HTTP::BrowserDetect>
116             L<Catalyst::TraitFor::Request::BrowserDetect>
117             L<Mojolicious::Plugin::BrowserDetect>
118             L<Dancer::Plugin::Browser>
119              
120             =head1 AUTHOR
121              
122             Natal Ngétal
123              
124             =head1 COPYRIGHT AND LICENSE
125              
126             This software is copyright (c) 2014 by Natal Ngétal.
127              
128             This is free software; you can redistribute it and/or modify it under
129             the same terms as the Perl 5 programming language system itself.
130              
131             =cut