| 1 | package Dancer::Plugin::MobileDevice; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 6 | $Dancer::Plugin::MobileDevice::VERSION = '0.05'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | #ABSTRACT: make a Dancer app mobile-aware | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Dancer ':syntax'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use Dancer::Plugin; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | register 'is_mobile_device' => sub { | ||||||||||||||||||||||||||||
| 14 | 24 | ▶ | return request->user_agent =~ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | /(?:iP(?:ad|od|hone)|Android|BlackBerry|Mobile|Palm)/ | ||||||||||||||||||||||||||||
| 16 | ? 1 : 0; | ||||||||||||||||||||||||||||
| 17 | 6 | }; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | hook before => sub { | ||||||||||||||||||||||||||||
| 20 | # If we don't have a mobile layout declared, do nothing. | ||||||||||||||||||||||||||||
| 21 | 16 | ▶ | my $settings = plugin_setting || {}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
Condition50%1/2
plugin_setting() || {}
MC/DC0%0/1
plugin_setting() || {}
plugin_setting()
Truth table50%1/2
A
A= plugin_setting()
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 16 | ▶ | if (my $mobile_layout = $settings->{mobile_layout}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | # OK, remember the original layout setting (so we can restore it | ||||||||||||||||||||||||||||
| 25 | # after the request), and override it with the specified mobile layout. | ||||||||||||||||||||||||||||
| 26 | 4 | ▶ | if (is_mobile_device()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 2 | var orig_layout => setting('layout'); | |||||||||||||||||||||||||||
| 28 | 2 | setting layout => $mobile_layout; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | 6 | }; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | hook after => sub { | ||||||||||||||||||||||||||||
| 34 | 16 | ▶ | my $settings = plugin_setting || {}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
Condition50%1/2
plugin_setting() || {}
MC/DC0%0/1
plugin_setting() || {}
plugin_setting()
Truth table50%1/2
A
A= plugin_setting()
| |||||||||||||||||||||||||||||
| 35 | 16 | ▶ | if ( $settings->{mobile_layout} && is_mobile_device() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$settings->{"mobile_layout"} and is_mobile_device()
MC/DC100%2/2
$settings->{"mobile_layout"} and is_mobile_device()
$settings->{"mobile_layout"}
is_mobile_device()
Truth table100%3/3
A and B
A= $settings->{"mobile_layout"}B= is_mobile_device()
| |||||||||||||||||||||||||||||
| 36 | 2 | setting layout => delete vars->{orig_layout}; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 6 | }; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | hook before_template => sub { | ||||||||||||||||||||||||||||
| 41 | 9 | ▶ | my $tokens = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | 9 | $tokens->{'is_mobile_device'} = is_mobile_device(); | |||||||||||||||||||||||||||
| 43 | 6 | }; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 6 | register_plugin for_versions => [ 1, 2 ]; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 6 | 1; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | __END__ | ||||||||||||||||||||||||||||