| 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 | 2 | $Dancer2::Plugin::BrowserDetect::VERSION = '1.162360'; | |
| 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; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | |||
| 16 | 2 | ▶ | use HTTP::BrowserDetect; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | |||
| 18 | #ABSTRACT: Provides an easy to have info of the browser. | ||
| 19 | |||
| 20 | |||
| 21 | on_plugin_import { | ||
| 22 | 1 | ▶ | my $dsl = shift; |
|
Subroutine
__ANON__: called CC=1 SCAR=1.2
| |||
| 23 | $dsl->app->add_hook( | ||
| 24 | Dancer2::Core::Hook->new( | ||
| 25 | name => 'before_template', | ||
| 26 | code => sub { | ||
| 27 | 0 | ▶ | my $tokens = shift; |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 28 | 0 | $tokens->{browser_detect} = _browser_detect($dsl); | |
| 29 | }, | ||
| 30 | ) | ||
| 31 | 1 | ); | |
| 32 | 2 | }; | |
| 33 | |||
| 34 | register browser_detect => sub { | ||
| 35 | 0 | ▶ | my $dsl = shift; |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 36 | 0 | _browser_detect($dsl); | |
| 37 | 2 | }; | |
| 38 | |||
| 39 | sub _browser_detect { | ||
| 40 | 0 | ▶ | my $dsl = shift; |
|
Subroutine
_browser_detect: not called CC=1 SCAR=6.9
| |||
| 41 | 0 | my $useragent = $dsl->app->request->env->{HTTP_USER_AGENT}; | |
| 42 | 0 | my $browser = HTTP::BrowserDetect->new($useragent); | |
| 43 | |||
| 44 | 0 | return $browser; | |
| 45 | } | ||
| 46 | |||
| 47 | 2 | register_plugin; | |
| 48 | |||
| 49 | |||
| 50 | 2 | 1; | |
| 51 | |||
| 52 | __END__ | ||