blib/lib/Dancer/Plugin/MobileDevice.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 8 / 8 Conditioncond 71.4% 5 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 93.1% 54 / 58 SCAR 20.8
CC
8
Cov
96%
__ANON__
4.0
__ANON__
4.0
__ANON__
2.0
CRAP 8.0
« Build ↑ Summary
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
BranchTrueFalseTotal
request()->user_agent =~ /(?:iP(?:ad|od|hone)|Android|BlackBerry|Mobile|Palm)/ ? : 14 10 24
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() || {}
l!l
160
MC/DC0%0/1
plugin_setting() || {}
plugin_setting()
Truth table50%1/2
A
A= plugin_setting()
Aresult
11
00
22  
23 16 ▶ if (my $mobile_layout = $settings->{mobile_layout}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mobile_layout = $settings->{"mobile_layout"}) 4 12 16
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
BranchTrueFalseTotal
if (is_mobile_device()) 2 2 4
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() || {}
l!l
160
MC/DC0%0/1
plugin_setting() || {}
plugin_setting()
Truth table50%1/2
A
A= plugin_setting()
Aresult
11
00
35 16 ▶ if ( $settings->{mobile_layout} && is_mobile_device() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($settings->{"mobile_layout"} and is_mobile_device()) 2 14 16
Condition100%3/3
$settings->{"mobile_layout"} and is_mobile_device()
!ll&&!rl&&r
1222
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()
ABresult
0X0
100
111
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__
« Build ↑ Summary