line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer::Plugin::Device::Layout; |
2
|
|
|
|
|
|
|
############################################################################ |
3
|
|
|
|
|
|
|
# Dancer::Plugin::Device::Layout - Dancer v1 plugin Dancer::Plugin::Device::Layout dynamically changes layout to match user agent's best layout. |
4
|
|
|
|
|
|
|
# @author BURNERSK |
5
|
|
|
|
|
|
|
# @license http://opensource.org/licenses/artistic-license-2.0 Artistic License 2.0 |
6
|
|
|
|
|
|
|
# @copyright © 2013, BURNERSK. Some rights reserved. |
7
|
|
|
|
|
|
|
############################################################################ |
8
|
2
|
|
|
2
|
|
95877
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
84
|
|
9
|
2
|
|
|
2
|
|
10
|
use warnings FATAL => 'all'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
89
|
|
10
|
2
|
|
|
2
|
|
11
|
use utf8; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
15
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
BEGIN { |
13
|
2
|
|
|
2
|
|
1947
|
use version 0.77; our $VERSION = version->new('v0.1'); |
|
2
|
|
|
2
|
|
4684
|
|
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
2437
|
|
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
2268
|
use Dancer 1.3111 qw( :syntax ); |
|
2
|
|
|
|
|
1080330
|
|
|
2
|
|
|
|
|
18
|
|
17
|
2
|
|
|
2
|
|
2948
|
use Dancer::Plugin; |
|
2
|
|
|
|
|
2968
|
|
|
2
|
|
|
|
|
173
|
|
18
|
2
|
|
|
2
|
|
2461
|
use HTTP::BrowserDetect 1.51; |
|
2
|
|
|
|
|
53348
|
|
|
2
|
|
|
|
|
1921
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
############################################################################ |
21
|
|
|
|
|
|
|
sub device_layout { |
22
|
5
|
|
|
5
|
|
3071
|
my ( $self, %args ) = plugin_args(@_); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Load plugin settings and defined defaults. |
25
|
5
|
|
|
|
|
90
|
my $conf = plugin_setting; |
26
|
5
|
|
100
|
|
|
123
|
$conf->{normal_layout} //= 'normal'; |
27
|
5
|
|
100
|
|
|
18
|
$conf->{mobile_layout} //= 'mobile'; |
28
|
5
|
|
100
|
|
|
18
|
$conf->{tablet_layout} //= 'tablet'; |
29
|
5
|
|
100
|
|
|
16
|
$conf->{no_tablet} //= 0; |
30
|
5
|
|
100
|
|
|
16
|
$conf->{tablet_as_mobile} //= 0; |
31
|
5
|
|
100
|
|
|
14
|
$conf->{no_mobile} //= 0; |
32
|
|
|
|
|
|
|
|
33
|
5
|
|
|
|
|
16
|
my $request = request; |
34
|
5
|
50
|
|
|
|
71
|
my $browser = HTTP::BrowserDetect->new( $request ? $request->user_agent : q{} ); |
35
|
5
|
50
|
|
|
|
3390
|
my $is_tablet = $browser->tablet ? 1 : 0; |
36
|
5
|
50
|
|
|
|
60
|
my $is_mobile = $browser->mobile ? 1 : 0; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Diagnostics. |
39
|
5
|
50
|
|
|
|
55
|
if ( $args{override_device} ) { |
40
|
5
|
100
|
|
|
|
22
|
if ( $args{override_device} eq 'normal' ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
41
|
3
|
|
|
|
|
5
|
$is_tablet = $is_mobile = 0; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
elsif ( $args{override_device} eq 'tablet' ) { |
44
|
1
|
|
|
|
|
3
|
$is_tablet = $is_mobile = 1; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif ( $args{override_device} eq 'mobile' ) { |
47
|
1
|
|
|
|
|
2
|
$is_tablet = 0; |
48
|
1
|
|
|
|
|
2
|
$is_mobile = 1; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
5
|
|
|
|
|
12
|
my $device_layout = $conf->{normal_layout}; |
53
|
5
|
100
|
66
|
|
|
36
|
if ( $is_tablet && !$conf->{no_tablet} ) { |
|
|
100
|
66
|
|
|
|
|
54
|
1
|
|
|
|
|
3
|
$device_layout = $conf->{tablet_layout}; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# treat tablet as mobile. |
57
|
1
|
50
|
|
|
|
5
|
if ( $conf->{tablet_as_mobile} ) { |
58
|
0
|
|
|
|
|
0
|
$device_layout = $conf->{mobile_layout}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
elsif ( $is_mobile && !$conf->{no_mobile} ) { |
62
|
1
|
|
|
|
|
2
|
$device_layout = $conf->{mobile_layout}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
5
|
100
|
|
|
|
162
|
return wantarray ? ( layout => $device_layout ) : $device_layout; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
register device_layout => \&device_layout; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
############################################################################ |
70
|
|
|
|
|
|
|
register_plugin; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
############################################################################ |
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
__END__ |