File Coverage

lib/Dancer/Plugin/MobileDevice.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition 2 2 100.0
subroutine 6 6 100.0
pod n/a
total 24 24 100.0


line stmt bran cond sub pod time code
1             package Dancer::Plugin::MobileDevice;
2             our $AUTHORITY = 'cpan:YANICK';
3             #ABSTRACT: make a Dancer app mobile-aware
4             $Dancer::Plugin::MobileDevice::VERSION = '0.06';
5 3     3   726389 use strict;
  3         23  
  3         79  
6 3     3   12 use warnings;
  3         6  
  3         65  
7              
8 3     3   13 use Dancer ':syntax';
  3         3  
  3         12  
9 3     3   1961 use Dancer::Plugin;
  3         3444  
  3         172  
10              
11             register 'is_mobile_device' => sub {
12 3     3   17 no warnings 'uninitialized';
  3         6  
  3         638  
13 25   100 25   1354 return request->user_agent
14             =~ /(?:iP(?:ad|od|hone)|Android|BlackBerry|Mobile|Palm)/ || 0 ;
15             };
16              
17             hook before => sub {
18             # If we don't have a mobile layout declared, do nothing.
19             my $mobile_layout = plugin_setting->{mobile_layout}
20             and is_mobile_device()
21             or return;
22              
23             var orig_layout => setting('layout');
24             setting layout => $mobile_layout;
25             };
26              
27             hook after => sub {
28             setting layout => delete vars->{orig_layout}
29             if plugin_setting->{mobile_layout}
30             and is_mobile_device();
31             };
32              
33             hook before_template => sub {
34             my $tokens = shift;
35             $tokens->{'is_mobile_device'} = is_mobile_device();
36             };
37              
38             register_plugin;
39              
40             1;
41              
42             __END__