| 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 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | |||
| 17 | 2 | ▶ | use Dancer2 ':syntax'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 2 | ▶ | use Dancer2::Plugin; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | |||
| 20 | 2 | ▶ | use HTTP::BrowserDetect; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 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 | _browser_detect(); | ||
| 33 | }; | ||
| 34 | |||
| 35 | sub _browser_detect { | ||
| 36 | 0 | ▶ | my $useragent = request->env->{HTTP_USER_AGENT}; |
|
Subroutine
_browser_detect: not called CC=1 SCAR=6.9
| |||
| 37 | 0 | my $browser = HTTP::BrowserDetect->new($useragent); | |
| 38 | |||
| 39 | 0 | return $browser; | |
| 40 | } | ||
| 41 | |||
| 42 | register_plugin for_versions => [2]; | ||
| 43 | |||
| 44 | |||
| 45 | 1; | ||
| 46 | |||
| 47 | __END__ | ||