blib/lib/Dancer2/Plugin/BrowserDetect.pm

filter: Statementstmt 77.7% 21 / 27 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 50.0% 1 / 2 totaltotal 75.6% 28 / 37 CC 1 SCAR 2.3
CC
1
Cov
78%
__ANON__
2.0
browser_detect
2.0
BUILD
1.1
CRAP 1.3
↑ Summary
1 #
2 # This file is part of Dancer2-Plugin-BrowserDetect
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 2 $Dancer2::Plugin::BrowserDetect::VERSION = '1.163590';
11 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use Dancer2::Plugin 0.200000;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use HTTP::BrowserDetect ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 #ABSTRACT: Provides an easy to have info of the browser.
20  
21  
22 1 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.6
Pod undocumented
23 1 my $plugin = shift;
24 # Create a weakened plugin that we can close over to avoid leaking.
25 1 Scalar::Util::weaken( my $weak_plugin = $plugin );
26 $plugin->app->add_hook(
27 Dancer2::Core::Hook->new(
28 name => 'before_template',
29 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 0 my $tokens = shift;
31 0 $tokens->{browser_detect} = $weak_plugin->browser_detect;
32 },
33 )
34 1 );
35 }
36  
37 2 plugin_keywords 'browser_detect';
38  
39 0 ▶sub browser_detect {
Subroutine browser_detect: not called CC=1 SCAR=6.9
Pod documented
40 0 my $plugin = shift;
41 0 my $useragent = $plugin->app->request->env->{HTTP_USER_AGENT};
42 0 my $browser = HTTP::BrowserDetect->new($useragent);
43  
44 0 return $browser;
45 }
46  
47  
48 2 1;
49  
50 __END__
↑ Summary