File Coverage

blib/lib/Woothee/Browser.pm
Criterion Covered Total %
statement 105 110 95.4
branch 41 50 82.0
condition 6 9 66.6
subroutine 12 12 100.0
pod 0 7 0.0
total 164 188 87.2


line stmt bran cond sub pod time code
1             package Woothee::Browser;
2              
3 6     6   38 use strict;
  6         12  
  6         185  
4 6     6   34 use warnings;
  6         14  
  6         166  
5 6     6   31 use Carp;
  6         12  
  6         348  
6              
7 6     6   1673 use Woothee::Util qw/update_map update_category update_version update_os/;
  6         15  
  6         396  
8 6     6   40 use Woothee::DataSet qw/dataset/;
  6         13  
  6         8338  
9              
10             our $VERSION = "1.7.0";
11              
12             sub challenge_msie {
13 549     549 0 848 my ($ua,$result) = @_;
14              
15 549 100 100     3825 return 0 if index($ua, "compatible; MSIE") < 0 and index($ua, "Trident/") < 0 and index($ua, "IEMobile");
      66        
16              
17 66         104 my $version;
18 66 100 33     533 if ($ua =~ m{MSIE ([.0-9]+);}o) {
    50          
    0          
19 45         121 $version = $1;
20             } elsif ($ua =~ m{Trident/([.0-9]+);}o and $ua =~ m{ rv:([.0-9]+)}o) {
21 21         65 $version = $1;
22             } elsif ($ua =~ m{IEMobile/([.0-9]+);}o) {
23 0         0 $version = $1;
24             } else {
25 0         0 $version = Woothee::DataSet->const('VALUE_UNKNOWN');
26             }
27 66         180 update_map($result, dataset('MSIE'));
28 66         191 update_version($result, $version);
29 66         220 return 1;
30             }
31              
32             sub challenge_vivaldi {
33 483     483 0 868 my ($ua, $result) = @_;
34              
35 483 100       1589 return 0 if index($ua, "Vivaldi/") < 0;
36              
37 9         34 my $version = Woothee::DataSet->const('VALUE_UNKNOWN');
38              
39 9 50       71 if ($ua =~ m{Vivaldi/([.0-9]+)}o) {
40 9         30 $version = $1;
41             }
42 9         26 update_map($result, dataset('Vivaldi'));
43 9         29 update_version($result, $version);
44 9         36 return 1;
45             }
46              
47             sub challenge_safari_chrome { # and Opera(blink)
48 474     474 0 744 my ($ua,$result) = @_;
49              
50 474 100       1576 return 0 if index($ua, "Safari/") < 0;
51              
52 75         305 my $version = Woothee::DataSet->const('VALUE_UNKNOWN');
53              
54 75 100       295 if ($ua =~ m{Edge/([.0-9]+)}o) {
55             # MS Edge
56 3         9 $version = $1;
57 3         7 update_map($result, dataset("Edge"));
58 3         11 update_version($result, $version);
59 3         11 return 1;
60             }
61              
62 72 100       240 if ($ua =~ m{FxiOS/([.0-9]+)}o) {
63             # Firefox for iOS
64 3         11 $version = $1;
65 3         14 update_map($result, dataset("Firefox"));
66 3         12 update_version($result, $version);
67 3         14 return 1;
68             }
69              
70 69 100       378 if ($ua =~ m{(?:Chrome|CrMo|CriOS)/([.0-9]+)}o) {
71             # Opera (blink)
72 33 100       142 if ($ua =~ m{OPR/([.0-9]+)}o) {
73 9         27 $version = $1;
74 9         32 update_map($result, dataset("Opera"));
75 9         26 update_version($result, $version);
76 9         34 return 1;
77             }
78              
79             #WebView
80 24 100       81 if (index($ua, "wv") > -1) {
81 3         11 return 0;
82             }
83              
84             # Chrome
85 21         53 $version = $1;
86 21         57 update_map($result, dataset("Chrome"));
87 21         59 update_version($result, $version);
88 21         73 return 1;
89             }
90              
91             # Safari
92 36 100       225 if ($ua =~ m{Version/([.0-9]+)}o) {
93 30         82 $version = $1;
94             }
95 36         93 update_map($result, dataset("Safari"));
96 36         135 update_version($result, $version);
97 36         124 return 1;
98             }
99              
100             sub challenge_firefox {
101 402     402 0 676 my ($ua,$result) = @_;
102              
103 402 100       1246 return 0 if index($ua, "Firefox/") < 0;
104              
105 27         39 my $version;
106 27 50       170 if ($ua =~ m{Firefox/([.0-9]+)}o) {
107 27         74 $version = $1;
108             }
109             else {
110 0         0 $version = Woothee::DataSet->const('VALUE_UNKNOWN');
111             }
112 27         72 update_map($result, dataset("Firefox"));
113 27         77 update_version($result, $version);
114 27         101 return 1;
115             }
116              
117             sub challenge_opera {
118 375     375 0 583 my ($ua,$result) = @_;
119              
120 375 100       1137 return 0 if index($ua, "Opera") < 0;
121              
122 30         51 my $version;
123 30 100       215 if ($ua =~ m{Version/([.0-9]+)}o) {
    50          
124 12         33 $version = $1;
125             }
126             elsif ($ua =~ m{Opera[/ ]([.0-9]+)}o) {
127 18         47 $version = $1;
128             }
129             else {
130 0         0 $version = Woothee::DataSet->const('VALUE_UNKNOWN');
131             }
132 30         84 update_map($result, dataset("Opera"));
133 30         91 update_version($result, $version);
134 30         77 return 1;
135             }
136              
137             sub challenge_webview {
138 345     345 0 565 my ($ua,$result) = @_;
139              
140              
141 345         1036 my $version = Woothee::DataSet->const('VALUE_UNKNOWN');
142              
143             # iOS
144 345 100       1481 if ($ua =~ m{iP(hone;|ad;|od) .*like Mac OS X}o) {
    100          
145 9 50       67 return 0 if index($ua, "Safari/") > -1;
146              
147 9 100       51 if ($ua =~ m{Version/([.0-9]+)}o) {
148 3         10 $version = $1;
149             }
150              
151 9         38 update_version($result, $version);
152 9         31 update_map($result, dataset("Webview"));
153 9         36 return 1;
154             }
155             elsif (index($ua, "wv") > -1) { #WebView
156 3 50       20 if ($ua =~ m{Version/([.0-9]+)}o) {
157 3         8 $version = $1;
158             }
159              
160 3         13 update_version($result, $version);
161 3         71 update_map($result, dataset("Webview"));
162 3         47 return 1;
163             }
164              
165 333         768 return 0;
166             }
167              
168              
169             sub challenge_sleipnir {
170 168     168 0 275 my ($ua,$result) = @_;
171              
172 168 100       537 return 0 if index($ua, "Sleipnir/") < 0;
173              
174 3         5 my $version;
175 3 50       23 if ($ua =~ m{Sleipnir/([.0-9]+)}o) {
176 3         8 $version = $1;
177             }
178             else {
179 0         0 $version = Woothee::DataSet->const('VALUE_UNKNOWN');
180             }
181 3         9 update_map($result, dataset("Sleipnir"));
182 3         11 update_version($result, $version);
183              
184             # Sleipnir's user-agent doesn't contain Windows version, so put 'Windows UNKNOWN Ver'.
185             # Sleipnir is IE component browser, so for Windows only.
186 3         8 my $win = dataset("Win");
187 3         9 update_category($result, $win->{Woothee::DataSet->const('KEY_CATEGORY')});
188 3         9 update_os($result, $win->{Woothee::DataSet->const('KEY_NAME')});
189              
190 3         10 return 1;
191             }
192              
193             1;
194              
195             __END__