This file is indexed.

/usr/share/perl5/HTTP/BrowserDetect.pm is in libhttp-browserdetect-perl 3.14-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
use strict;
use warnings;

use 5.006;

package HTTP::BrowserDetect;
$HTTP::BrowserDetect::VERSION = '3.14';
use vars qw(@ALL_TESTS);

# Operating Systems
our @OS_TESTS = qw(
    windows  mac     os2
    unix     linux   vms
    bsd      amiga   brew
    bb10     rimtabletos
    chromeos ios
    firefoxos
);

# More precise Windows
our @WINDOWS_TESTS = qw(
    win16      win3x        win31
    win95      win98        winnt
    winme      win32        win2k
    winxp      win2k3       winvista
    win7       win8         win8_0
    win8_1     win10        win10_0
    wince      winphone     winphone7
    winphone7_5 winphone8   winphone8_1
    winphone10
);

# More precise Mac
our @MAC_TESTS = qw(
    macosx mac68k macppc
);

# More precise Unix
our @UNIX_TESTS = qw(
    sun     sun4     sun5
    suni86  irix     irix5
    irix6   hpux     hpux9
    hpux10  aix      aix1
    aix2    aix3     aix4
    sco     unixware mpras
    reliant dec      sinix
);

# More precise BSDs
our @BSD_TESTS = qw(
    freebsd
);

# Gaming devices
our @GAMING_TESTS = qw(
    ps3gameos pspgameos
);

# Device related tests
our @DEVICE_TESTS = qw(
    android audrey blackberry dsi iopener ipad
    iphone ipod kindle kindlefire n3ds palm ps3 psp wap webos
    mobile tablet
);

# Browsers
our @BROWSER_TESTS = qw(
    mosaic         netscape         firefox
    chrome         safari           ie
    opera          lynx             links
    elinks         neoplanet        neoplanet2
    avantgo        emacs            mozilla
    konqueror      realplayer       netfront
    mobile_safari  obigo            aol
    lotusnotes     staroffice       icab
    webtv          browsex          silk
    applecoremedia galeon           seamonkey
    epiphany       ucbrowser        dalvik
    edge           pubsub           adm
    brave          imagesearcherpro polaris
);

our @IE_TESTS = qw(
    ie3         ie4         ie4up
    ie5         ie5up       ie55
    ie55up      ie6         ie7
    ie8         ie9         ie10
    ie11
    ie_compat_mode
);

our @OPERA_TESTS = qw(
    opera3      opera4     opera5
    opera6      opera7
);

our @AOL_TESTS = qw(
    aol3        aol4
    aol5        aol6
);

our @NETSCAPE_TESTS = qw(
    nav2   nav3   nav4
    nav4up nav45  nav45up
    nav6   nav6up navgold
);

# Firefox variants
our @FIREFOX_TESTS = qw(
    firebird    iceweasel   phoenix
    namoroka
);

# Engine tests
our @ENGINE_TESTS = qw(
    gecko       trident     webkit
    presto      khtml       edgehtml
);

our @ROBOT_TESTS = qw(
    puf             curl           wget
    getright        robot          slurp
    yahoo           mj12bot        ahrefs
    altavista       lycos          infoseek
    lwp             linkexchange
    googlemobile    msn            msnmobile
    facebook        baidu          googleadsbot
    askjeeves       googleadsense  googlebotvideo
    googlebotnews   googlebotimage google
    googlefavicon   yandeximages   specialarchiver
    yandex          java           lib
    indy            golib          rubylib
    apache          malware        phplib
    msoffice        ipsagent       nutch
    linkchecker     bingbot
);

our @MISC_TESTS = qw(
    dotnet      x11
);

push @ALL_TESTS,
    (
    @OS_TESTS,      @WINDOWS_TESTS,
    @MAC_TESTS,     @UNIX_TESTS,
    @BSD_TESTS,     @GAMING_TESTS,
    @DEVICE_TESTS,  @BROWSER_TESTS,
    @IE_TESTS,      @OPERA_TESTS,
    @AOL_TESTS,     @NETSCAPE_TESTS,
    @FIREFOX_TESTS, @ENGINE_TESTS,
    @ROBOT_TESTS,   @MISC_TESTS,
    );

sub _all_tests {
    return @ALL_TESTS;
}

# https://support.google.com/webmasters/answer/1061943?hl=en

my %ROBOT_NAMES = (
    ahrefs          => 'Ahrefs',
    altavista       => 'AltaVista',
    apache          => 'Apache http client',
    askjeeves       => 'AskJeeves',
    baidu           => 'Baidu Spider',
    bingbot         => 'Bingbot',
    curl            => 'curl',
    facebook        => 'Facebook',
    getright        => 'GetRight',
    google          => 'Googlebot',
    googleadsbot    => 'Google AdsBot',
    googleadsense   => 'Google AdSense',
    googlebotimage  => 'Googlebot Images',
    googlebotnews   => 'Googlebot News',
    googlebotvideo  => 'Googlebot Video',
    googlefavicon   => 'Google Favicon',
    googlemobile    => 'Googlebot Mobile',
    golib           => 'Go language http library',
    indy            => 'Indy Library',
    infoseek        => 'InfoSeek',
    ipsagent        => 'Verisign ips-agent',
    java            => 'Java',
    linkchecker     => 'LinkChecker',
    linkexchange    => 'LinkExchange',
    lwp             => 'LWP::UserAgent',
    lycos           => 'Lycos',
    malware         => 'Malware / hack attempt',
    mj12bot         => 'Majestic-12 DSearch',
    msn             => 'MSN',
    msnmobile       => 'MSN Mobile',
    msoffice        => 'Microsoft Office',
    nutch           => 'Apache Nutch',
    phplib          => 'PHP http library',
    puf             => 'puf',
    robot           => 'robot',
    rubylib         => 'Ruby http library',
    slurp           => 'Yahoo! Slurp',
    specialarchiver => 'archive.org_bot',
    wget            => 'wget',
    yahoo           => 'Yahoo',
    yandex          => 'Yandex',
    yandeximages    => 'YandexImages',
);

my %BROWSER_NAMES = (
    adm              => 'Android Download Manager',
    aol              => 'AOL Browser',
    applecoremedia   => 'AppleCoreMedia',
    blackberry       => 'BlackBerry',
    brave            => 'Brave',
    browsex          => 'BrowseX',
    chrome           => 'Chrome',
    curl             => 'curl',
    dalvik           => 'Dalvik',
    dsi              => 'Nintendo DSi',
    edge             => 'Edge',
    elinks           => 'ELinks',
    epiphany         => 'Epiphany',
    firefox          => 'Firefox',
    galeon           => 'Galeon',
    icab             => 'iCab',
    iceweasel        => 'IceWeasel',
    ie               => 'MSIE',
    imagesearcherpro => 'ImageSearcherPro',
    konqueror        => 'Konqueror',
    links            => 'Links',
    lotusnotes       => 'Lotus Notes',
    lynx             => 'Lynx',
    mobile_safari    => 'Mobile Safari',
    mosaic           => 'Mosaic',
    mozilla          => 'Mozilla',
    n3ds             => 'Nintendo 3DS',
    netfront         => 'NetFront',
    netscape         => 'Netscape',
    obigo            => 'Obigo',
    opera            => 'Opera',
    polaris          => 'Polaris',
    pubsub           => 'Safari RSS Reader',
    puf              => 'puf',
    realplayer       => 'RealPlayer',
    safari           => 'Safari',
    seamonkey        => 'SeaMonkey',
    silk             => 'Silk',
    staroffice       => 'StarOffice',
    ucbrowser        => 'UCBrowser',
    webtv            => 'WebTV',
);

# Device names
my %DEVICE_NAMES = (
    android    => 'Android',
    audrey     => 'Audrey',
    blackberry => 'BlackBerry',
    dsi        => 'Nintendo DSi',
    iopener    => 'iopener',
    ipad       => 'iPad',
    iphone     => 'iPhone',
    ipod       => 'iPod',
    kindle     => 'Amazon Kindle',
    n3ds       => 'Nintendo 3DS',
    palm       => 'Palm',
    ps3        => 'Sony PlayStation 3',
    psp        => 'Sony PlayStation Portable',
    wap        => 'WAP capable phone',
    webos      => 'webOS',
);

my %OS_NAMES = (
    amiga       => 'Amiga',
    android     => 'Android',
    bb10        => 'BlackBerry 10',
    brew        => 'Brew',
    chromeos    => 'Chrome OS',
    firefoxos   => 'Firefox OS',
    ios         => 'iOS',
    linux       => 'Linux',
    mac         => 'Mac',
    macosx      => 'Mac OS X',
    os2         => 'OS/2',
    ps3gameos   => 'Playstation 3 GameOS',
    pspgameos   => 'Playstation Portable GameOS',
    rimtabletos => 'RIM Tablet OS',
    unix        => 'Unix',
    vms         => 'VMS',
    win2k       => 'Win2k',
    win2k3      => 'Win2k3',
    win3x       => 'Win3x',
    win7        => 'Win7',
    win8        => 'Win8',
    win8_0      => 'Win8.0',
    win8_1      => 'Win8.1',
    win10       => 'Win10',
    win10_0     => 'Win10.0',
    win95       => 'Win95',
    win98       => 'Win98',
    winme       => 'WinME',
    winnt       => 'WinNT',
    winphone    => 'Windows Phone',
    winvista    => 'WinVista',
    winxp       => 'WinXP',
);

# Safari build -> version map for versions prior to 3.0
# (since then, version appears in the user-agent string)

my %safari_build_to_version = qw(
    48      0.8
    51      0.8.1
    60      0.8.2
    73      0.9
    74      1.0b2v74
    85      1.0
    85.7    1.0.2
    85.8    1.0.3
    100     1.1
    100.1   1.1.1
    125     1.2
    125.1   1.2.1
    125.7   1.2.2
    125.9   1.2.3
    125.11  1.2.4
    312     1.3
    312.3   1.3.1
    312.5   1.3.2
    412     2.0
    412.5   2.0.1
    416.12  2.0.2
    417.8   2.0.3
    419.3   2.0.4
);

#######################################################################################################
# BROWSER OBJECT

my $default = undef;

sub new {
    my ( $class, $user_agent ) = @_;

    my $self = {};
    bless $self, $class;

    unless ( defined $user_agent ) {
        $user_agent = $ENV{'HTTP_USER_AGENT'};
    }

    $self->{user_agent} = defined $user_agent ? $user_agent : q{};
    $self->_init_core;

    return $self;
}

### Accessors for computed-on-demand test attributes

foreach my $test ( @ENGINE_TESTS, @MISC_TESTS ) {
    no strict 'refs';
    *{$test} = sub {
        my ($self) = @_;
        return $self->{tests}->{$test} || 0;
    };
}

foreach my $test (
    @OS_TESTS,  @WINDOWS_TESTS, @MAC_TESTS, @UNIX_TESTS,
    @BSD_TESTS, @GAMING_TESTS
    ) {
    no strict 'refs';
    *{$test} = sub {
        my ($self) = @_;
        $self->_init_os() unless $self->{os_tests};
        return $self->{os_tests}->{$test} || 0;
    };
}

foreach my $test ( @BROWSER_TESTS, @FIREFOX_TESTS ) {
    no strict 'refs';
    *{$test} = sub {
        my ($self) = @_;
        return $self->{browser_tests}->{$test} || 0;
    };
}

foreach my $test (@ROBOT_TESTS) {
    no strict 'refs';

    # For the 'robot' test, we return undef instead of 0 if it's
    # false, to match os() and browser() and the like.
    my $false_result = ( $test eq 'robot' ? undef : 0 );

    *{$test} = sub {
        my ($self) = @_;
        $self->_init_robots() unless $self->{robot_tests};
        return $self->{robot_tests}->{$test} || $false_result;
    };
}

foreach my $test (
    @NETSCAPE_TESTS, @IE_TESTS, @AOL_TESTS,
    @OPERA_TESTS
    ) {
    no strict 'refs';
    *{$test} = sub {
        my ($self) = @_;
        $self->_init_version() unless $self->{version_tests};
        return $self->{version_tests}->{$test} || 0;
    };
}

foreach my $test (@DEVICE_TESTS) {
    no strict 'refs';
    *{$test} = sub {
        my ($self) = @_;
        $self->_init_device() unless $self->{device_tests};
        return $self->{device_tests}->{$test} || 0;
    };
}

sub user_agent {
    my ( $self, $user_agent ) = @_;
    if ( defined($user_agent) ) {
        die
            'Calling HTTP::BrowserDetect::user_agent() with an argument is no longer allowed; please use new().';
    }
    else {
        return $self->{user_agent};
    }
}

### Code for initializing various pieces of the object. Since it would
### be needlessly slow if we examined every user agent for every piece
### of information we might possibly need, we only initialize things
### when they're actually queried about. Specifically:
###
### _init_core() sets up:
###     $self->{browser_tests}
###     $self->{browser}
###     $self->{browser_string}
###     $self->{tests}
###     $self->{engine_version}
###     $self->{realplayer_version}
###
### _init_version() sets up:
###     $self->{version_tests}
###     $self->{major}
###     $self->{minor}
###     $self->{beta}
###     $self->{realplayer_version}
###
### _init_os() sets up:
###     $self->{os}
###     $self->{os_string}
###     $self->{os_tests}
###     $self->{os_version}
###
### _init_os_version() sets up:
###     $self->{os_version}
###
### _init_device() sets up:
###     $self->{device_tests}
###     $self->{device}
###     $self->{device_string}
###
### _init_robots() sets up:
###     $self->{robot}
###     $self->{robot_tests}
###     $self->{robot_string}
###     $self->{robot_version}
###

# Private method -- Set up the basics (browser and misc attributes)
# for a new user-agent string
sub _init_core {
    my ( $self, $new_ua ) = @_;

    my $ua = lc $self->{user_agent};

    # any UA via Google Translate gets this appended
    $ua =~ s{,gzip\(gfe\)\z}{};

    # These get filled in immediately
    $self->{tests}         = {};
    $self->{browser_tests} = {};

    my $tests          = $self->{tests};
    my $browser_tests  = $self->{browser_tests};
    my $browser        = undef;
    my $browser_string = undef;

    # Detect engine
    $self->{engine_version} = undef;

    if ( $ua =~ m{edge/([\d.]+)$} ) {
        $tests->{edgehtml}      = 1;
        $self->{engine_version} = $1;
    }
    elsif ( $ua =~ /trident\/([\w\.\d]*)/ ) {
        $tests->{trident}       = 1;
        $self->{engine_version} = $1;
    }
    elsif ( index( $ua, 'gecko' ) != -1 && index( $ua, 'like gecko' ) == -1 )
    {
        $tests->{gecko} = 1;
        if ( $ua =~ /\([^)]*rv:([\w.\d]*)/ ) {
            $self->{engine_version} = $1;
        }
    }
    elsif ( $ua =~ m{applewebkit/([\d.\+]+)} ) {
        $tests->{webkit}        = 1;
        $self->{engine_version} = $1;
    }
    elsif ( $ua =~ m{presto/([\d.]+)} ) {
        $tests->{presto}        = 1;
        $self->{engine_version} = $1;
    }
    elsif ( $ua =~ m{khtml/([\d.]+)} ) {
        $tests->{khtml}         = 1;
        $self->{engine_version} = $1;
    }

    # Detect browser

    if ( index( $ua, 'galeon' ) != -1 ) {

        # Needs to go above firefox

        $browser = 'galeon';
        $browser_tests->{galeon} = 1;
    }
    elsif ( index( $ua, 'epiphany' ) != -1 ) {

        # Needs to go above firefox + mozilla

        $browser = 'epiphany';
        $browser_tests->{epiphany} = 1;
    }
    elsif ( $ua
        =~ m{^mozilla/.+windows (?:nt|phone) \d{2}\.\d+;?.+ applewebkit/.+ chrome/.+ safari/.+ edge/[\d.]+$}
        ) {
        $browser        = 'edge';
        $browser_string = 'Edge';

        $browser_tests->{edge} = 1;
    }
    elsif (
        $ua =~ m{
                (firebird|iceweasel|phoenix|namoroka|firefox)
                \/
                ( [^.]* )           # Major version number is everything before first dot
                \.                  # The first dot
                ( [\d]* )           # Minor version nnumber is digits after first dot
            }xo
        && index( $ua, 'not firefox' ) == -1
        )    # Hack for Yahoo Slurp
    {
        # Browser is Firefox, possibly under an alternate name

        $browser        = 'firefox';
        $browser_string = ucfirst $1;

        $browser_tests->{$1} = 1;
        $browser_tests->{firefox} = 1;
    }
    elsif ( $ua =~ m{opera|opr\/} ) {

        # Browser is Opera

        $browser = 'opera';
        $browser_tests->{opera} = 1;
    }
    elsif ($tests->{trident}
        || index( $ua, 'msie' ) != -1
        || index( $ua, 'microsoft internet explorer' ) != -1 ) {

        # Browser is MSIE (possibly AOL branded)

        $browser = 'ie';
        $browser_tests->{ie} = 1;

        if (   index( $ua, 'aol' ) != -1
            || index( $ua, 'america online browser' ) != -1 ) {
            $browser_string = 'AOL Browser';
            $browser_tests->{aol} = 1;
        }

        # Disabled for now -- need to figure out how to deal with version numbers
        #elsif ( index ( $ua, 'acoobrowser' ) != -1 ) {
        #    $browser_string = 'Acoo Browser';
        #}
        #elsif ( index( $ua, 'avant' ) != -1 ) {
        #    $browser_string = 'Avant Browser';
        #}
        #elsif ( index( $ua, 'crazy browser' ) != -1 ) {
        #    $browser_string = 'Crazy Browser';
        #}
        #elsif ( index( $ua, 'deepnet explorer' ) != -1 ) {
        #    $browser_string = 'Deepnet Explorer';
        #}
        #elsif ( index( $ua, 'maxthon' ) != -1 ) {
        #    $browser_string = 'Maxthon';
        #}
    }
    elsif ( index( $ua, 'brave' ) != -1 ) {

        # Has to go above Chrome, it includes 'like Chrome/'

        $browser = 'brave';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'silk' ) != -1 ) {

        # Has to go above Chrome, it includes 'like Chrome/'

        $browser = 'silk';
        $browser_tests->{$browser} = 1;
    }
    elsif (index( $ua, 'chrome/' ) != -1
        || index( $ua, 'crios' ) != -1 ) {

        # Browser is Chrome

        $browser = 'chrome';
        $browser_tests->{chrome} = 1;

        if ( index( $ua, 'chromium' ) != -1 ) {
            $browser_string = 'Chromium';
        }
    }
    elsif (index( $ua, 'blackberry' ) != -1
        || index( $ua, 'bb10' ) != -1
        || index( $ua, 'rim tablet os' ) != -1 ) {

        # Has to go above Safari
        $browser = 'blackberry';    # test gets set during device check
    }
    elsif ( index( $ua, 'ucbrowser' ) != -1 ) {

        # Has to go above both Safari and Mozilla

        $browser = 'ucbrowser';
        $browser_tests->{$browser} = 1;
    }
    elsif (( index( $ua, 'safari' ) != -1 )
        || ( index( $ua, 'applewebkit' ) != -1 ) ) {

        # Browser is Safari

        $browser_tests->{safari} = 1;
        $browser = 'safari';
        if (   index( $ua, ' mobile safari/' ) != -1
            || index( $ua, 'mobilesafari' ) != -1 ) {
            $browser_string = 'Mobile Safari';
            $browser_tests->{mobile_safari} = 1;
        }
        if ( index( $ua, 'puffin' ) != -1 ) {
            $browser_string = 'Puffin';
        }
    }
    elsif ( index( $ua, 'neoplanet' ) != -1 ) {

        # Browser is Neoplanet

        $browser                    = 'ie';
        $browser_tests->{$browser}  = 1;
        $browser_tests->{neoplanet} = 1;
        $browser_tests->{neoplanet2} = 1 if ( index( $ua, '2.' ) != -1 );
    }

    ## The following browsers all need to be tested for *before*
    ## Mozilla, otherwise we'll think they are Mozilla because they
    ## look very much like it.
    elsif ( index( $ua, 'webtv' ) != -1 ) {
        $browser = 'webtv';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'nintendo 3ds' ) != -1 ) {
        $browser = 'n3ds';    # Test gets set during device check
    }
    elsif ( index( $ua, 'nintendo dsi' ) != -1 ) {
        $browser = 'dsi';     # Test gets set during device check
    }
    elsif (index( $ua, 'playstation 3' ) != -1
        || index( $ua, 'playstation portable' ) != -1
        || index( $ua, 'netfront' ) != -1 ) {
        $browser = 'netfront';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'browsex' ) != -1 ) {
        $browser = 'browsex';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'polaris' ) != -1 ) {
        $browser = 'polaris';
        $browser_tests->{$browser} = 1;
    }

    ## At this point if it looks like Mozilla but we haven't found
    ## anything else for it to be, it's probably Mozilla.
    elsif (index( $ua, 'mozilla' ) != -1
        && index( $ua, 'compatible' ) == -1 ) {

        # Browser is a Gecko-powered Netscape (i.e. Mozilla) version

        $browser = 'mozilla';
        if ( index( $ua, 'netscape' ) != -1
            || !$tests->{gecko} ) {
            $browser = 'netscape';
        }
        elsif ( index( $ua, 'seamonkey' ) != -1 ) {
            $browser = 'seamonkey';
        }
        $browser_tests->{$browser} = 1;
        $browser_tests->{netscape} = 1;
        $browser_tests->{mozilla}  = ( $tests->{gecko} );
    }

    ## Long series of unlikely browsers (ones that don't look like Mozilla)
    elsif ( index( $ua, 'staroffice' ) != -1 ) {
        $browser = 'staroffice';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'icab' ) != -1 ) {
        $browser = 'icab';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'lotus-notes' ) != -1 ) {
        $browser = 'lotusnotes';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'konqueror' ) != -1 ) {
        $browser = 'konqueror';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'lynx' ) != -1 ) {
        $browser = 'lynx';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'elinks' ) != -1 ) {
        $browser = 'elinks';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'links' ) != -1 ) {
        $browser = 'links';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'mosaic' ) != -1 ) {
        $browser = 'mosaic';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'emacs' ) != -1 ) {
        $browser = 'emacs';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'obigo' ) != -1 ) {
        $browser = 'obigo';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'teleca' ) != -1 ) {
        $browser                   = 'obigo';
        $browser_string            = 'Teleca';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'libcurl' ) != -1 || $ua =~ /^curl/ ) {
        $browser = 'curl';    # Test gets set during robot check
    }
    elsif ( index( $ua, 'puf/' ) != -1 ) {
        $browser = 'puf';     # Test gets set during robot check
    }
    elsif ( index( $ua, 'applecoremedia/' ) != -1 ) {
        $browser = 'applecoremedia';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'androiddownloadmanager' ) != -1 ) {
        $browser = 'adm';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'dalvik' ) != -1 ) {
        $browser = 'dalvik';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'apple-pubsub' ) != -1 ) {
        $browser = 'pubsub';
        $browser_tests->{$browser} = 1;
    }
    elsif ( index( $ua, 'imagesearcherpro' ) != -1 ) {
        $browser = 'imagesearcherpro';
        $browser_tests->{$browser} = 1;
    }

    $self->{browser} = $browser;
    $self->{browser_string} = $browser_string || $BROWSER_NAMES{$browser}
        if defined($browser);

    # Other random tests

    $tests->{x11}    = 1 if index( $ua, 'x11' ) != -1;
    $tests->{dotnet} = 1 if index( $ua, '.net clr' ) != -1;

    if ( index( $ua, 'realplayer' ) != -1 ) {

        # Hack for Realplayer -- fix the version and 'real' browser

        $self->_init_version;  # Set appropriate tests for whatever the 'real'
                               # browser is.

        # Now set the browser to Realplayer.
        $self->{browser}             = 'realplayer';
        $self->{browser_string}      = 'RealPlayer';
        $browser_tests->{realplayer} = 1;

        # Now override the version with the Realplayer version (but leave
        # alone the tests we already set, which might have been based on the
        # 'real' browser's version).
        $self->{realplayer_version} = undef;

        if ( $ua =~ /realplayer\/([\d+\.]+)/ ) {
            $self->{realplayer_version} = $1;
            ( $self->{major}, $self->{minor} )
                = split( /\./, $self->{realplayer_version} );
            $self->{minor} = ".$self->{minor}" if defined( $self->{minor} );
        }
        elsif ( $ua =~ /realplayer\s(\w+)/ ) {
            $self->{realplayer_version} = $1;
        }
    }

    if ( index( $ua, '(r1 ' ) != -1 ) {

        # Realplayer plugin -- don't override browser but do set property
        $browser_tests->{realplayer} = 1;
    }

}

# Any of these fragments within a user-agent generally indicates it's
# a robot.
my @ROBOT_FRAGMENTS = qw(
    agent
    analy
    appender
    babya
    checker
    bot
    copy
    crawl
    explorador
    fetch
    find
    ia_archive
    index
    netcraft
    reap
    resolver
    sleuth
    scan
    service
    spider
    thumbtack-thunderdome
    tiscali
    validator
    verif
    webcapture
    worm
    zyborg
);

sub _init_robots {
    my $self = shift;

    my $ua            = lc $self->{user_agent};
    my $tests         = $self->{tests};
    my $browser_tests = $self->{browser_tests};

    my $robot_tests = $self->{robot_tests} = {};
    my $r = undef;

    my $robot_fragment;    # The text that indicates it's a robot (we'll
                           # use this later to detect robot version, and
                           # maybe robot_string)

    if ( index( $ua, 'libwww-perl' ) != -1 || index( $ua, 'lwp-' ) != -1 ) {
        $r                  = 'lwp';
        $robot_tests->{lib} = 1;
        $robot_fragment     = (
            ( index( $ua, 'libwww-perl' ) != -1 ) ? 'libwww-perl' : 'lwp-' );
    }
    elsif ( index( $ua, 'slurp' ) != -1 ) {
        $r = 'slurp';
        $robot_tests->{yahoo} = 1;
    }
    elsif (index( $ua, 'yahoo' ) != -1
        && index( $ua, 'jp.co.yahoo.android' ) == -1 ) {
        $r = 'yahoo';
    }
    elsif ( index( $ua, 'msnbot-mobile' ) != -1 ) {
        $r                  = 'msnmobile';
        $robot_tests->{msn} = 1;
        $robot_fragment     = 'msnbot';
    }
    elsif ( index( $ua, 'bingbot-mobile' ) != -1 ) {
        $r                      = 'bingbot';
        $robot_tests->{bingbot} = 1;
        $robot_fragment         = 'bingbot';
    }
    elsif ( index( $ua, 'msnbot' ) != -1 ) {
        $r              = 'msn';
        $robot_fragment = 'msnbot';
    }
    elsif (index( $ua, 'binglocalsearch' ) != -1
        || index( $ua, 'bingbot' ) != -1 ) {
        $r                      = 'bingbot';
        $robot_tests->{bingbot} = 1;
        $robot_fragment         = 'bingbot';
    }
    elsif ( index( $ua, 'microsoft office existence discovery' ) != -1 ) {
        $r              = 'msoffice';
        $robot_fragment = 'office';
    }
    elsif ( index( $ua, 'ahrefsbot' ) != -1 ) {
        $r = 'ahrefs';
    }
    elsif ( index( $ua, 'altavista' ) != -1 ) {
        $r = 'altavista';
    }
    elsif ( index( $ua, 'apache-httpclient' ) != -1 ) {
        $r = 'apache';
    }
    elsif ( $ua =~ m{\( *\) *\{ *\: *\; *} ) {

        # Shellcode for spawning a process, i.e. (){:;} with some kind of whitespace interleaved
        $r = 'malware';
    }
    elsif ( index( $ua, 'ask jeeves/teoma' ) != -1 ) {
        $r              = 'askjeeves';
        $robot_fragment = 'teoma';
    }
    elsif ( index( $ua, 'baiduspider' ) != -1 ) {
        $r = 'baidu';
    }
    elsif ( index( $ua, 'libcurl' ) != -1 || $ua =~ /^curl/ ) {
        $r = 'curl';
        $robot_tests->{lib} = 1;
    }
    elsif ( index( $ua, 'facebookexternalhit' ) != -1 ) {
        $r = 'facebook';
    }
    elsif ( index( $ua, 'getright' ) != -1 ) {
        $r = 'getright';
    }
    elsif ( index( $ua, 'adsbot-google' ) != -1 ) {
        $r                     = 'googleadsbot';
        $robot_tests->{google} = 1;
        $robot_fragment        = 'adsbot-google';
    }
    elsif ( index( $ua, 'mediapartners-google' ) != -1 ) {
        $r                     = 'googleadsense';
        $robot_tests->{google} = 1;
        $robot_fragment        = 'mediapartners-google';
    }
    elsif ( index( $ua, 'google favicon' ) != -1 ) {
        $r                     = 'googlefavicon';
        $robot_tests->{google} = 1;
        $robot_fragment        = 'favicon';
    }
    elsif ( index( $ua, 'googlebot-image' ) != -1 ) {
        $r                     = 'googlebotimage';
        $robot_tests->{google} = 1;
        $robot_fragment        = 'googlebot-image';
    }
    elsif ( index( $ua, 'googlebot-news' ) != -1 ) {
        $r                     = 'googlebotnews';
        $robot_tests->{google} = 1;
        $robot_fragment        = 'googlebot-news';
    }
    elsif ( index( $ua, 'googlebot-video' ) != -1 ) {
        $r                     = 'googlebotvideo';
        $robot_tests->{google} = 1;
        $robot_fragment        = 'googlebot-video';
    }
    elsif ( index( $ua, 'googlebot-mobile' ) != -1 ) {
        $r                     = 'googlemobile';
        $robot_tests->{google} = 1;
        $robot_fragment        = 'googlebot-mobile';
    }
    elsif ( index( $ua, 'googlebot' ) != -1 ) {
        $r = 'google';
    }
    elsif ( $ua =~ m{go.*package http} ) {
        $r                  = 'golib';
        $robot_tests->{lib} = 1;
        $robot_fragment     = 'package';
    }
    elsif ( $ua =~ m{^http_request} ) {
        $r                  = 'phplib';
        $robot_tests->{lib} = 1;
        $robot_fragment     = 'http_request';
    }
    elsif ( $ua =~ m{^http_request} ) {
        $r = 'phplib';
        $robot_tests->{lib} = 1;
    }
    elsif ( index( $ua, 'indy library' ) != -1 ) {
        $r = 'indy';
        $robot_tests->{lib} = 1;
    }
    elsif ( index( $ua, 'infoseek' ) != -1 ) {
        $r = 'infoseek';
    }
    elsif ( index( $ua, 'ips-agent' ) != -1 ) {
        $r              = 'ipsagent';
        $robot_fragment = 'ips-agent';
    }
    elsif ( index( $ua, 'lecodechecker' ) != -1 ) {
        $r              = 'linkexchange';
        $robot_fragment = 'lecodechecker';
    }
    elsif ( index( $ua, 'linkchecker' ) != -1 ) {
        $r = 'linkchecker';
    }
    elsif ( index( $ua, 'lycos' ) != -1 ) {
        $r = 'lycos';
    }
    elsif ( index( $ua, 'mechanize' ) != -1 ) {
        $r                  = 'rubylib';
        $robot_tests->{lib} = 1;
        $robot_fragment     = 'mechanize';
    }
    elsif ( index( $ua, 'mj12bot/' ) != -1 ) {
        $r = 'mj12bot';
    }
    elsif ( index( $ua, 'nutch' ) != -1 ) {
        $r = 'nutch';
    }
    elsif ( index( $ua, 'puf/' ) != -1 ) {
        $r = 'puf';
        $robot_tests->{lib} = 1;
    }
    elsif ( index( $ua, 'scooter' ) != -1 ) {
        $r = 'scooter';
    }
    elsif ( index( $ua, 'special_archiver' ) != -1 ) {
        $r              = 'specialarchiver';
        $robot_fragment = 'special_archiver';
    }
    elsif ( index( $ua, 'wget' ) == 0 ) {
        $r = 'wget';
    }
    elsif ( index( $ua, 'yandexbot' ) != -1 ) {
        $r = 'yandex';
    }
    elsif ( index( $ua, 'yandeximages' ) != -1 ) {
        $r = 'yandeximages';
    }
    elsif ( $ua =~ m{^java} && !$self->{browser} ) {
        $r = 'java';
        $robot_tests->{lib} = 1;
    }
    elsif ( index( $ua, 'jdk' ) != -1 ) {
        $r                  = 'java';
        $robot_tests->{lib} = 1;
        $robot_fragment     = 'jdk';
    }
    elsif ( index( $ua, 'jakarta commons-httpclient' ) != -1 ) {
        $r                  = 'java';
        $robot_tests->{lib} = 1;
        $robot_fragment     = 'jakarta';
    }
    elsif ( index( $ua, 'google-http-java-client' ) != -1 ) {
        $r                  = 'java';
        $robot_tests->{lib} = 1;
        $robot_fragment     = 'google';
    }

    if (   $browser_tests->{applecoremedia}
        || $browser_tests->{dalvik}
        || $browser_tests->{adm} ) {
        $robot_tests->{lib} = 1;
    }

    if ($r) {

        # Got a named robot
        $robot_tests->{$r}    = 1;
        $self->{robot_string} = $ROBOT_NAMES{$r};    # Including undef
        $robot_tests->{robot} = $r;
        $robot_fragment = $r if !defined($robot_fragment);
    }
    elsif ( $ua =~ /seek (?! mo (?: toolbar )? \s+ \d+\.\d+ )/x ) {

        # Store the fragment for later, to determine full name
        $robot_fragment = 'seek';
        $robot_tests->{robot} = 'unknown';
    }
    elsif ( $ua =~ /search (?! [\w\s]* toolbar \b | bar \b | erpro \b )/x ) {

        # Store the fragment for later, to determine full name
        $robot_fragment = 'search';
        $robot_tests->{robot} = 'unknown';
    }
    elsif ( $self->{user_agent} =~ /([\w \/\.\-]+)[ \;\(\)]*\+https?\:/i ) {

        # Something followed by +http
        $self->{robot_string} = $1;
        $self->{robot_string} =~ s/^ *(.+?)[ \;\(\)]*?( *\/[\d\.]+ *)?$/$1/;
        $robot_fragment = $1;
        $robot_tests->{robot} = 'unknown';
    }
    else {
        # See if we have a simple fragment
        for my $fragment (@ROBOT_FRAGMENTS) {
            if ( index( $ua, $fragment ) != -1 ) {
                $robot_fragment = $fragment;
                $robot_tests->{robot} = 'unknown';
                last;
            }
        }
    }

    if ( defined($robot_fragment) ) {

        # Examine what surrounds the fragment; that leads us to the
        # version and the string (if we haven't explicitly set one).

        if (
            $self->{user_agent} =~ m{\s*                # Beginning whitespace
                                      ([\w .:,\-\@\/]*  # Words before fragment
                                       $robot_fragment  # Match the fragment
                                       [\w .:,\-\@\/]*) # Words after fragment
                                     }ix
            ) {
            my $full_string = $1;
            $full_string =~ s/ *$//;    # Trim whitespace at end
            if (
                   $self->{user_agent} eq $full_string
                && $self->{user_agent} =~ m{\/.*\/}
                && $self->{user_agent} =~ m{
                                      ([\w]*               # Words before fragment
                                       $robot_fragment     # Match the fragment
                                       (\/[\d\.]+)?        # Version
                                       [\w]*)              # Beta stuff
                                     }ix
                ) {
                # We matched the whole string, but it seems to
                # make more sense as whitespace-separated
                # 'thing/ver' tokens
                $full_string = $1;
            }

            # Figure out robot version based on the string
            if (    $full_string
                and $full_string =~ s/[\/ \.v]*(\d+)(\.\d+)?([\.\w]*)$// ) {
                $self->{robot_version} = [ $1, $2, $3 ];
            }
            else {
                $self->{robot_version} = undef;
            }

            # Set robot_string, if we don't already have an explictly set
            # one
            if ( !defined( $self->{robot_string} ) ) {
                $self->{robot_string} = $full_string;
            }
        }
    }

    if ( !exists( $self->{robot_version} ) ) {
        $self->{robot_version} = undef;
    }
}

### OS tests, only run on demand

sub _init_os {
    my $self = shift;

    my $tests         = $self->{tests};
    my $browser_tests = $self->{browser_tests};
    my $ua            = lc $self->{user_agent};

    my $os_tests = $self->{os_tests} = {};
    my $os = undef;
    my $os_string = undef;

    # Windows

    if ( index( $ua, '16bit' ) != -1 ) {
        $os        = 'windows';
        $os_string = '16-bit Windows';
        $os_tests->{win16} = $os_tests->{windows} = 1;
    }

    if ( index( $ua, 'win' ) != -1 ) {
        if (   index( $ua, 'win16' ) != -1
            || index( $ua, 'windows 3' ) != -1
            || index( $ua, 'windows 16-bit' ) != -1 ) {
            $os_tests->{win16} = 1;
            $os_tests->{win3x} = 1;
            $os                = 'windows';
            if ( index( $ua, 'windows 3.1' ) != -1 ) {
                $os_tests->{win31} = 1;
                $os_string = 'Win3x';    # FIXME bug compatibility
            }
            else {
                $os_string = 'Win3x';
            }
        }
        elsif (index( $ua, 'win95' ) != -1
            || index( $ua, 'windows 95' ) != -1 ) {
            $os        = 'windows';
            $os_string = 'Win95';
            $os_tests->{win95} = $os_tests->{win32} = 1;
        }
        elsif (
            index( $ua, 'win 9x 4.90' ) != -1    # whatever
            || index( $ua, 'windows me' ) != -1
            ) {
            $os        = 'windows';
            $os_string = 'WinME';
            $os_tests->{winme} = $os_tests->{win32} = 1;
        }
        elsif (index( $ua, 'win98' ) != -1
            || index( $ua, 'windows 98' ) != -1 ) {
            $os        = 'windows';
            $os_string = 'Win98';
            $os_tests->{win98} = $os_tests->{win32} = 1;
        }
        elsif ( index( $ua, 'windows 2000' ) != -1 ) {
            $os        = 'windows';
            $os_string = 'Win2k';
            $os_tests->{win2k} = $os_tests->{winnt} = $os_tests->{win32} = 1;
        }
        elsif ( index( $ua, 'windows ce' ) != -1 ) {
            $os                = 'windows';
            $os_string         = 'WinCE';
            $os_tests->{wince} = 1;
        }
        elsif ( index( $ua, 'windows phone' ) != -1 ) {
            $os = 'winphone';
            $os_tests->{winphone} = 1;

            if ( index( $ua, 'windows phone os 7.0' ) != -1 ) {
                $os_tests->{winphone7} = 1;
            }
            elsif ( index( $ua, 'windows phone os 7.5' ) != -1 ) {
                $os_tests->{winphone7_5} = 1;
            }
            elsif ( index( $ua, 'windows phone 8.0' ) != -1 ) {
                $os_tests->{winphone8} = 1;
            }
            elsif ( index( $ua, 'windows phone 8.1' ) != -1 ) {
                $os_tests->{winphone8_1} = 1;
            }
            elsif ( index( $ua, 'windows phone 10.0' ) != -1 ) {
                $os_tests->{winphone10} = 1;
            }
        }
    }

    if ( index( $ua, 'nt' ) != -1 ) {
        if (   index( $ua, 'nt 5.0' ) != -1
            || index( $ua, 'nt5' ) != -1 ) {
            $os        = 'windows';
            $os_string = 'Win2k';
            $os_tests->{win2k} = $os_tests->{winnt} = $os_tests->{win32} = 1;
        }
        elsif ( index( $ua, 'nt 5.1' ) != -1 ) {
            $os        = 'windows';
            $os_string = 'WinXP';
            $os_tests->{winxp} = $os_tests->{winnt} = $os_tests->{win32} = 1;
        }
        elsif ( index( $ua, 'nt 5.2' ) != -1 ) {
            $os        = 'windows';
            $os_string = 'Win2k3';
            $os_tests->{win2k3} = $os_tests->{winnt} = $os_tests->{win32} = 1;
        }
        elsif ( index( $ua, 'nt 6.0' ) != -1 ) {
            $os        = 'windows';
            $os_string = 'WinVista';
            $os_tests->{winvista} = $os_tests->{winnt} = $os_tests->{win32}
                = 1;
        }
        elsif ( index( $ua, 'nt 6.1' ) != -1 ) {
            $os        = 'windows';
            $os_string = 'Win7';
            $os_tests->{win7} = $os_tests->{winnt} = $os_tests->{win32} = 1;
        }
        elsif ( index( $ua, 'nt 6.2' ) != -1 ) {
            $os        = 'windows';
            $os_string = 'Win8.0';
            $os_tests->{win8_0} = $os_tests->{win8} = $os_tests->{winnt}
                = $os_tests->{win32} = 1;
        }
        elsif ( index( $ua, 'nt 6.3' ) != -1 ) {
            $os        = 'windows';
            $os_string = 'Win8.1';
            $os_tests->{win8_1} = $os_tests->{win8} = $os_tests->{winnt}
                = $os_tests->{win32} = 1;
        }
        elsif ( index( $ua, 'nt 10.0' ) != -1 ) {
            $os        = 'windows';
            $os_string = 'Win10.0';
            $os_tests->{win10_0} = $os_tests->{win10} = $os_tests->{winnt}
                = $os_tests->{win32} = 1;
        }
        elsif (index( $ua, 'winnt' ) != -1
            || index( $ua, 'windows nt' ) != -1
            || index( $ua, 'nt4' ) != -1
            || index( $ua, 'nt3' ) != -1 ) {
            $os        = 'windows';
            $os_string = 'WinNT';
            $os_tests->{winnt} = $os_tests->{win32} = 1;
        }
    }

    if ($os) {

        # windows, set through some path above
        $os_tests->{windows} = 1;
        $os_tests->{win32} = 1 if index( $ua, 'win32' ) != -1;
    }
    elsif ( index( $ua, 'macintosh' ) != -1 || index( $ua, 'mac_' ) != -1 ) {

        # Mac operating systems
        $os_tests->{mac} = 1;
        if ( index( $ua, 'mac os x' ) != -1 ) {
            $os = 'macosx';
            $os_tests->{$os} = 1;
        }
        else {
            $os = 'mac';
        }
        if ( index( $ua, '68k' ) != -1 || index( $ua, '68000' ) != -1 ) {
            $os_tests->{mac68k} = 1;
        }
        elsif ( index( $ua, 'ppc' ) != -1 || index( $ua, 'powerpc' ) != -1 ) {
            $os_tests->{macppc} = 1;
        }
    }
    elsif (index( $ua, 'ipod' ) != -1
        || index( $ua, 'iphone' ) != -1
        || index( $ua, 'ipad' ) != -1 ) {

        # iOS
        $os = 'ios';
        $os_tests->{$os} = 1;
    }
    elsif ( index( $ua, 'android' ) != -1 ) {

        # Android
        $os = 'android';    # Test gets set in the device testing
    }
    elsif ( index( $ua, 'inux' ) != -1 ) {

        # Linux
        $os = 'linux';
        $os_tests->{linux} = $os_tests->{unix} = 1;
    }
    elsif ( $tests->{x11} && index( $ua, 'cros' ) != -1 ) {

        # ChromeOS
        $os = 'chromeos';
        $os_tests->{chromeos} = 1;
    }
    ## Long series of unlikely OSs
    elsif ( index( $ua, 'amiga' ) != -1 ) {
        $os = 'amiga';
        $os_tests->{$os} = 1;
    }
    elsif ( index( $ua, 'os/2' ) != -1 ) {
        $os = 'os2';
        $os_tests->{$os} = 1;
    }
    elsif ( index( $ua, 'solaris' ) != -1 ) {
        $os        = 'unix';
        $os_string = 'Solaris';
        $os_tests->{sun} = $os_tests->{unix} = 1;
    }
    elsif ( index( $ua, 'samsung' ) == -1 && index( $ua, 'sun' ) != -1 ) {
        $os        = 'unix';
        $os_string = 'SunOS';
        $os_tests->{sun} = $os_tests->{unix} = 1;
        $os_tests->{suni86} = 1 if index( $ua, 'i86' ) != -1;
        $os_tests->{sun4}   = 1 if index( $ua, 'sunos 4' ) != -1;
        $os_tests->{sun5}   = 1 if index( $ua, 'sunos 5' ) != -1;
    }
    elsif ( index( $ua, 'irix' ) != -1 ) {
        $os        = 'unix';
        $os_string = 'Irix';
        $os_tests->{irix} = $os_tests->{unix} = 1;
        $os_tests->{irix5} = 1 if ( index( $ua, 'irix5' ) != -1 );
        $os_tests->{irix6} = 1 if ( index( $ua, 'irix6' ) != -1 );
    }
    elsif ( index( $ua, 'hp-ux' ) != -1 ) {
        $os        = 'unix';
        $os_string = 'HP-UX';
        $os_tests->{hpux} = $os_tests->{unix} = 1;
        $os_tests->{hpux9}  = 1 if index( $ua, '09.' ) != -1;
        $os_tests->{hpux10} = 1 if index( $ua, '10.' ) != -1;
    }
    elsif ( index( $ua, 'aix' ) != -1 ) {
        $os        = 'unix';
        $os_string = 'AIX';
        $os_tests->{aix} = $os_tests->{unix} = 1;
        $os_tests->{aix1} = 1 if ( index( $ua, 'aix 1' ) != -1 );
        $os_tests->{aix2} = 1 if ( index( $ua, 'aix 2' ) != -1 );
        $os_tests->{aix3} = 1 if ( index( $ua, 'aix 3' ) != -1 );
        $os_tests->{aix4} = 1 if ( index( $ua, 'aix 4' ) != -1 );
    }
    elsif ( $ua =~ m{\bsco\b} || index( $ua, 'unix_sv' ) != -1 ) {
        $os        = 'unix';
        $os_string = 'SCO Unix';
        $os_tests->{sco} = $os_tests->{unix} = 1;
    }
    elsif ( index( $ua, 'unix_system_v' ) != -1 ) {
        $os        = 'unix';
        $os_string = 'System V Unix';
        $os_tests->{unixware} = $os_tests->{unix} = 1;
    }
    elsif ( $ua =~ m{\bncr\b} ) {
        $os        = 'unix';
        $os_string = 'NCR Unix';
        $os_tests->{mpras} = $os_tests->{unix} = 1;
    }
    elsif ( index( $ua, 'reliantunix' ) != -1 ) {
        $os        = 'unix';
        $os_string = 'Reliant Unix';
        $os_tests->{reliant} = $os_tests->{unix} = 1;
    }
    elsif (index( $ua, 'dec' ) != -1
        || index( $ua, 'osf1' ) != -1
        || index( $ua, 'declpha' ) != -1
        || index( $ua, 'alphaserver' ) != -1
        || index( $ua, 'ultrix' ) != -1
        || index( $ua, 'alphastation' ) != -1 ) {
        $os = 'unix';
        $os_tests->{dec} = $os_tests->{unix} = 1;
    }
    elsif ( index( $ua, 'sinix' ) != -1 ) {
        $os = 'unix';
        $os_tests->{sinix} = $os_tests->{unix} = 1;
    }
    elsif ( index( $ua, 'bsd' ) != -1 ) {
        $os = 'unix';
        if ( $self->{user_agent} =~ m{(\w*bsd\w*)}i ) {
            $os_string = $1;
        }
        $os_tests->{bsd} = $os_tests->{unix} = 1;
        $os_tests->{freebsd} = 1 if index( $ua, 'freebsd' ) != -1;
    }
    elsif ( $tests->{x11} ) {

        # Some Unix we didn't identify
        $os = 'unix';
        $os_tests->{unix} = 1;
    }
    elsif ( index( $ua, 'vax' ) != -1 || index( $ua, 'openvms' ) != -1 ) {

        $os = 'vms';
        $os_tests->{vms} = 1;
    }
    elsif ( index( $ua, 'bb10' ) != -1 ) {
        $os = 'bb10';
        $os_tests->{bb10} = 1;
    }
    elsif ( index( $ua, 'rim tablet os' ) != -1 ) {
        $os = 'rimtabletos';
        $os_tests->{rimtabletos} = 1;
    }
    elsif ( index( $ua, 'playstation 3' ) != -1 ) {
        $os = 'ps3gameos';
        $os_tests->{ps3gameos} = 1;
    }
    elsif ( index( $ua, 'playstation portable' ) != -1 ) {
        $os = 'pspgameos';
        $os_tests->{pspgameos} = 1;
    }
    elsif ( index( $ua, 'windows' ) != -1 ) {

        # Windows again, the super generic version
        $os_tests->{windows} = 1;
    }
    elsif ( index( $ua, 'win32' ) != -1 ) {
        $os_tests->{win32} = $os_tests->{windows} = 1;
    }
    elsif ( $self->{user_agent} =~ m{(brew)|(\bbmp\b)}i ) {
        $os = 'brew';
        if ($1) {
            $os_string = 'Brew';
        }
        else {
            $os_string = 'Brew MP';
        }
        $os_tests->{brew} = 1;
    }
    else {
        $os = undef;
    }

    # To deal with FirefoxOS we seem to have to load-on-demand devices
    # also, by calling ->mobile and ->tablet. We have to be careful;
    # if we ever created a loop back from _init_devices to _init_os
    # we'd run forever.
    if (  !$os
        && $browser_tests->{firefox}
        && index( $ua, 'fennec' ) == -1
        && ( $self->mobile || $self->tablet ) ) {
        $os = 'firefoxos';
        $os_tests->{firefoxos} = 1;
    }

    $self->{os} = $os;
    if ( $os and !$os_string ) {
        $os_string = $OS_NAMES{$os};
    }
    $self->{os_string} = $os_string;
}

sub _init_os_version {
    my ($self) = @_;

    my $os        = $self->os;
    my $os_string = $self->os_string;
    my $ua        = lc $self->{user_agent};

    my $os_version = undef;

    if ( !defined($os) ) {

        # Nothing is going to work if we have no OS. Skip everything.
    }
    elsif ( $os eq 'winphone' ) {
        if ( $ua =~ m{windows phone (?:os )?(\d+)(\.?\d*)([\.\d]*)} ) {
            $os_version = [ $1, $2, $3 ];
        }
    }
    elsif ( $os eq 'macosx' ) {
        if ( $ua =~ m{os x (\d+)[\._](\d+)[\._]?(\d*)} ) {
            $os_version = [ $1, ".$2", length($3) ? ".$3" : q{} ];
        }
    }
    elsif ( $os eq 'ios' ) {
        if ( $ua =~ m{ os (\d+)[\._ ](\d+)[\._ ]?(\d*)} ) {
            $os_version = [ $1, ".$2", length($3) ? ".$3" : q{} ];
        }
    }
    elsif ( $os eq 'chromeos' ) {
        if ( $ua =~ m{ cros \S* (\d+)(\.?\d*)([\.\d]*)} ) {
            $os_version = [ $1, $2, $3 ];
        }
    }
    elsif ( $os eq 'android' ) {
        if ( $ua =~ m{android (\d+)(\.?\d*)([\w\-\.]*)[\;\)]} ) {
            $os_version = [ $1, $2, $3 ];
        }
    }
    elsif ( $os eq 'firefoxos' ) {
        if ( $ua =~ m{firefox/(\d+)(\.?\d*)([\.\d]*)} ) {
            $os_version = [ $1, $2, $3 ];
        }
    }
    elsif ( $os eq 'brew' ) {
        if ( $ua =~ m{(brew|\bbmp) (\d+)(\.?\d*)([\.\d]*)} ) {
            $os_version = [ $2, $3, $4 ];
        }
    }

    # Set the version. It might be set to undef, in which case we know
    # not to go through this next time.
    $self->{os_version} = $os_version;
}

### Version determination, only run on demand

sub _init_version {
    my ($self) = @_;

    my $ua            = lc $self->{user_agent};
    my $tests         = $self->{tests};
    my $browser_tests = $self->{browser_tests};
    my $browser       = $self->{browser};

    $self->{version_tests} = {};
    my $version_tests = $self->{version_tests};

    my ( $major, $minor, $beta );

    ### First figure out version numbers. First, we test if we're
    ### using a browser that needs some special method to determine
    ### the version.

    if ( defined($browser) && $browser eq 'opera' ) {

        # Opera has a 'compatible; ' section, but lies sometimes. It needs
        # special handling.

        # http://dev.opera.com/articles/view/opera-ua-string-changes/
        # http://my.opera.com/community/openweb/idopera/
        # Opera/9.80 (S60; SymbOS; Opera Mobi/320; U; sv) Presto/2.4.15 Version/10.00
        # Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36 OPR/15.0.1147.100

        if ( $ua =~ m{\AOpera.*\sVersion/(\d*)\.(\d*)\z}i ) {
            $major = $1;
            $minor = $2;
        }
        elsif ( $ua =~ m{\bOPR/(\d+)\.(\d+)}i ) {
            $major = $1;
            $minor = $2;
        }
        elsif ( $ua =~ m{Opera[ /](\d+).(\d+)}i ) {
            $major = $1;
            $minor = $2;
        }
    }
    elsif ( $ua
        =~ m{\b compatible; \s* [\w\-]* [/\s] ( [0-9]+ ) (?: .([0-9]+) (\S*) )? ;}x
        ) {
        # MSIE and some others use a 'compatible' format
        ( $major, $minor, $beta ) = ( $1, $2, $3 );
    }
    elsif ( !$browser ) {

        # Nothing else is going to work if $browser isn't defined; skip the
        # specific approaches and go straight to the generic ones.
    }
    elsif ( $browser_tests->{edge} ) {
        ( $major, $minor, $beta ) = $ua =~ m{Edge/(\d+)(.\d+)(.\d+)?};
    }
    elsif ( $browser_tests->{safari} ) {

        # Safari Version

        if (
            0
            && $ua =~ m{ # Disabled for bug compatibility
                version/
                ( \d+ )       # Major version number is everything before first dot
                \.            # First dot
                ( \d+ )?      # Minor version number follows dot
            }x
            ) {
            # Safari starting with version 3.0 provides its own public version
            ( $major, $minor ) = ( $1, $2, undef );
        }
        elsif ( $ua =~ m{ safari/ ( \d+ (?: \.\d+ )* ) }x ) {
            if ( my ( $safari_build, $safari_minor ) = split /\./, $1 ) {
                $major = int( $safari_build / 100 );
                $minor = int( $safari_build % 100 );
                $beta  = ".$safari_minor" if $safari_minor;
            }
        }
        elsif ( $ua =~ m{applewebkit\/([\d\.]{1,})}xi ) {
            if ( my ( $safari_build, $safari_minor ) = split /\./, $1 ) {
                $major = int( $safari_build / 100 );
                $minor = int( $safari_build % 100 );
                $beta  = ".$safari_minor" if $safari_minor;
            }
        }
    }
    elsif ( $browser_tests->{ie} ) {

        # MSIE

        if ( $ua =~ m{\b msie \s ( [0-9\.]+ ) (?: [a-z]+ [a-z0-9]* )? ;}x ) {

            # Internet Explorer
            ( $major, $minor, $beta ) = split /\./, $1;
        }
        elsif ( $ua =~ m{\b rv: ( [0-9\.]+ ) \b}x ) {

            # MSIE masking as Gecko really well ;)
            ( $major, $minor, $beta ) = split /\./, $1;
        }
    }
    elsif ( $browser eq 'n3ds' ) {
        if ( $ua =~ m{Nintendo 3DS;.*\sVersion/(\d*)\.(\d*)}i ) {
            $major = $1;
            $minor = $2;
        }
    }
    elsif ( $browser eq 'browsex' ) {
        if ( $ua =~ m{BrowseX \((\d+)\.(\d+)([\d.]*)}i ) {
            $major = $1;
            $minor = $2;
            $beta  = $3;
        }
    }
    elsif ( $ua =~ m{netscape6/(\d+)\.(\d+)([\d.]*)} ) {

        # Other cases get handled below, we just need this to skip the '6'
        $major = $1;
        $minor = $2;
        $beta  = $3;
    }
    elsif ( $browser eq 'brave' ) {

        # Note: since 0.7.10, Brave has changed the branding
        # of GitHub's 'Electron' (http://electron.atom.io/) to 'Brave'.
        # This means the browser string has both 'brave/' (the browser)
        # and 'Brave/' (re-branded Electron) in it.
        # The generic section below looks at $self->{browser_string}, which is 'Brave'
        # (Electron) and not $self->{browser} which is 'brave'.
        # Caveat parser.
        if ( $ua =~ m{brave/(\d+)\.(\d+)([\d.]*)} ) {
            $major = $1;
            $minor = $2;
            $beta  = $3;
        }
    }
    elsif ($browser eq 'chrome'
        && $ua =~ m{crios/(\d+)\.(\d+)([\d.]*)} ) {
        $major = $1;
        $minor = $2;
        $beta  = $3;
    }
    elsif ($browser eq 'pubsub'
        && $ua =~ m{apple-pubsub/(\d+)\.?(\d+)?([\d.]*)} ) {
        $major = $1;
        $minor = $2;
        $beta  = $3;
    }
    elsif ($browser eq 'obigo'
        && $self->{user_agent} =~ m{(obigo[\w\-]*|teleca)[\/ ]\w(\d+)(\w*)}i )
    {
        $major = $2;
        $minor = q{};
        $beta  = $3;
    }
    elsif ($browser eq 'polaris'
        && $ua =~ m{polaris[ \/](\d+)\.?(\d+)?([\d\.]*)} ) {
        $major = $1;
        $minor = $2;
        $beta  = $3;
    }
    elsif ($browser eq 'ucbrowser'
        && $ua =~ m{ucbrowser[\/ ]*(\d+)\.?(\d+)?([\d\.]*)} ) {
        $major = $1;
        $minor = $2;
        $beta  = $3;
    }

    # If we didn't match a browser-specific test, we look for
    # '$browser/x.y.z'
    if ( !defined($major) and defined( $self->{browser_string} ) ) {
        my $version_index = index( $ua, lc "$self->{browser_string}/" );
        if ( $version_index != -1 ) {
            my $version_str
                = substr( $ua, $version_index + length($browser) );
            if ( $version_str =~ m{/(\d+)\.(\d+)([\w.]*)} ) {
                $major = $1;
                $minor = $2;
                $beta  = $3;
            }
        }
    }

    # If that didn't work, we try 'Version/x.y.z'
    if ( !defined($major) ) {
        if ( $ua =~ m{version/(\d+)\.(\d+)([\w.]*)} ) {
            $major = $1;
            $minor = $2;
            $beta  = $3;
        }
    }

    # If that didn't work, we start guessing. Just grab
    # anything after a word and a slash.
    if ( !defined($major) ) {

        ( $major, $minor, $beta ) = (
            $ua =~ m{
                \S+        # Greedily catch anything leading up to forward slash.
                \/                # Version starts with a slash
                [A-Za-z]*         # Eat any letters before the major version
                ( [0-9]+ )        # Major version number is everything before the first dot
                 \.               # The first dot
                ([\d]* )          # Minor version number is every digit after the first dot
                                  # Throw away remaining numbers and dots
                ( [^\s]* )        # Beta version string is up to next space
            }x
        );
    }

    # If that didn't work, try even more generic.
    if ( !defined($major) ) {

        if ( $ua =~ /[A-Za-z]+\/(\d+)\;/ ) {
            $major = $1;
            $minor = 0;
        }
    }

    # If that didn't work, give up.
    $major = 0     if !$major;
    $minor = 0     if !$minor;
    $beta  = undef if ( defined($beta) && $beta eq q{} );

    # Now set version tests

    if ( $browser_tests->{netscape} ) {

        # Netscape browsers
        $version_tests->{nav2}   = 1 if $major == 2;
        $version_tests->{nav3}   = 1 if $major == 3;
        $version_tests->{nav4}   = 1 if $major == 4;
        $version_tests->{nav4up} = 1 if $major >= 4;
        $version_tests->{nav45}  = 1 if $major == 4 && $minor == 5;
        $version_tests->{nav45up} = 1
            if ( $major == 4 && ".$minor" >= .5 )
            || $major >= 5;
        $version_tests->{navgold} = 1
            if defined($beta) && ( index( $beta, 'gold' ) != -1 );
        $version_tests->{nav6} = 1
            if ( $major == 5 || $major == 6 );    # go figure
        $version_tests->{nav6up} = 1 if $major >= 5;

        if ( $browser eq 'seamonkey' ) {

            # Ugh, seamonkey versions started back at 1.
            $version_tests->{nav2}    = 0;
            $version_tests->{nav4up}  = 1;
            $version_tests->{nav45up} = 1;
            $version_tests->{nav6}    = 1;
            $version_tests->{nav6up}  = 1;
        }
    }

    if ( $browser_tests->{ie} ) {
        $version_tests->{ie3}    = 1 if ( $major == 3 );
        $version_tests->{ie4}    = 1 if ( $major == 4 );
        $version_tests->{ie4up}  = 1 if ( $major >= 4 );
        $version_tests->{ie5}    = 1 if ( $major == 5 );
        $version_tests->{ie5up}  = 1 if ( $major >= 5 );
        $version_tests->{ie55}   = 1 if ( $major == 5 && $minor == 5 );
        $version_tests->{ie55up} = 1 if ( ".$minor" >= .5 || $major >= 6 );
        $version_tests->{ie6}    = 1 if ( $major == 6 );
        $version_tests->{ie7}    = 1 if ( $major == 7 );
        $version_tests->{ie8}    = 1 if ( $major == 8 );
        $version_tests->{ie9}    = 1 if ( $major == 9 );
        $version_tests->{ie10}   = 1 if ( $major == 10 );
        $version_tests->{ie11}   = 1 if ( $major == 11 );

        $version_tests->{ie_compat_mode}
            = (    $version_tests->{ie7}
                && $tests->{trident}
                && $self->{engine_version} + 0 >= 4 );
    }

    if ( $browser_tests->{aol} ) {
        $version_tests->{aol3} = 1
            if ( index( $ua, 'aol 3.0' ) != -1
            || $version_tests->{ie3} );
        $version_tests->{aol4} = 1
            if ( index( $ua, 'aol 4.0' ) != -1 )
            || $version_tests->{ie4};
        $version_tests->{aol5}  = 1 if index( $ua, 'aol 5.0' ) != -1;
        $version_tests->{aol6}  = 1 if index( $ua, 'aol 6.0' ) != -1;
        $version_tests->{aoltv} = 1 if index( $ua, 'navio' ) != -1;
    }

    if ( $browser_tests->{opera} ) {
        $version_tests->{opera3} = 1
            if index( $ua, 'opera 3' ) != -1 || index( $ua, 'opera/3' ) != -1;
        $version_tests->{opera4} = 1
            if ( index( $ua, 'opera 4' ) != -1 )
            || ( index( $ua, 'opera/4' ) != -1
            && ( index( $ua, 'nintendo dsi' ) == -1 ) );
        $version_tests->{opera5} = 1
            if ( index( $ua, 'opera 5' ) != -1 )
            || ( index( $ua, 'opera/5' ) != -1 );
        $version_tests->{opera6} = 1
            if ( index( $ua, 'opera 6' ) != -1 )
            || ( index( $ua, 'opera/6' ) != -1 );
        $version_tests->{opera7} = 1
            if ( index( $ua, 'opera 7' ) != -1 )
            || ( index( $ua, 'opera/7' ) != -1 );

    }

    $minor = ".$minor";

    $self->{major} = $major;
    $self->{minor} = $minor;
    $self->{beta}  = $beta;
}

### Device tests, only run on demand

sub _init_device {
    my ($self) = @_;

    my $ua            = lc $self->{user_agent};
    my $browser_tests = $self->{browser_tests};
    my $tests         = $self->{tests};

    my ( $device, $device_string );
    my $device_tests = $self->{device_tests} = {};

    if ( index( $ua, 'windows phone' ) != -1 ) {
        $device = 'winphone';

        # Test is set in _init_os()
    }
    elsif (index( $ua, 'android' ) != -1
        || index( $ua, 'silk-accelerated' ) != -1 ) {

        # Silk-accelerated indicates a 1st generation Kindle Fire,
        # which may not have other indications of being an Android
        # device.
        $device = 'android';
        $device_tests->{$device} = 1;
    }
    elsif (index( $ua, 'blackberry' ) != -1
        || index( $ua, 'bb10' ) != -1
        || index( $ua, 'rim tablet os' ) != -1 ) {
        $device = 'blackberry';
        $device_tests->{$device} = 1;
    }
    elsif ( index( $ua, 'ipod' ) != -1 ) {
        $device = 'ipod';
        $device_tests->{$device} = 1;
    }
    elsif ( index( $ua, 'ipad' ) != -1 ) {
        $device = 'ipad';
        $device_tests->{$device} = 1;
    }
    elsif ( index( $ua, 'iphone' ) != -1 ) {
        $device = 'iphone';
        $device_tests->{$device} = 1;
    }
    elsif ( index( $ua, 'webos' ) != -1 ) {
        $device = 'webos';
        $device_tests->{$device} = 1;
    }
    elsif ( index( $ua, 'kindle' ) != -1 ) {
        $device = 'kindle';
        $device_tests->{$device} = 1;
    }
    elsif ( index( $ua, 'audrey' ) != -1 ) {
        $device = 'audrey';
        $device_tests->{$device} = 1;
    }
    elsif ( index( $ua, 'i-opener' ) != -1 ) {
        $device = 'iopener';
        $device_tests->{$device} = 1;
    }
    elsif ( index( $ua, 'avantgo' ) != -1 ) {
        $device                  = 'avantgo';
        $device_tests->{$device} = 1;
        $device_tests->{palm}    = 1;
    }
    elsif ( index( $ua, 'palmos' ) != -1 ) {
        $device = 'palm';
        $device_tests->{$device} = 1;
    }
    elsif ( index( $ua, 'playstation 3' ) != -1 ) {
        $device = 'ps3';
        $device_tests->{$device} = 1;
    }
    elsif ( index( $ua, 'playstation portable' ) != -1 ) {
        $device = 'psp';
        $device_tests->{$device} = 1;
    }
    elsif ( index( $ua, 'nintendo dsi' ) != -1 ) {
        $device = 'dsi';
        $device_tests->{$device} = 1;
    }
    elsif ( index( $ua, 'nintendo 3ds' ) != -1 ) {
        $device = 'n3ds';
        $device_tests->{$device} = 1;
    }
    elsif (
           $browser_tests->{obigo}
        || $browser_tests->{ucbrowser}
        || index( $ua, 'up.browser' ) != -1
        || (   index( $ua, 'nokia' ) != -1
            && index( $ua, 'windows phone' ) == -1 )
        || index( $ua, 'alcatel' ) != -1
        || $ua =~ m{\bbrew\b}
        || $ua =~ m{\bbmp\b}
        || index( $ua, 'ericsson' ) != -1
        || index( $ua, 'sie-' ) == 0
        || index( $ua, 'wmlib' ) != -1
        || index( $ua, ' wap' ) != -1
        || index( $ua, 'wap ' ) != -1
        || index( $ua, 'wap/' ) != -1
        || index( $ua, '-wap' ) != -1
        || index( $ua, 'wap-' ) != -1
        || index( $ua, 'wap' ) == 0
        || index( $ua, 'wapper' ) != -1
        || index( $ua, 'zetor' ) != -1
        ) {
        $device = 'wap';
        $device_tests->{$device} = 1;
    }

    $device_tests->{tablet} = (
        index( $ua, 'ipad' ) != -1
            || ( $browser_tests->{ie}
            && index( $ua, 'windows phone' ) == -1
            && index( $ua, 'arm' ) != -1 )
            || ( index( $ua, 'android' ) != -1
            && index( $ua, 'mobile' ) == -1
            && index( $ua, 'safari' ) != -1 )
            || ( $browser_tests->{firefox} && index( $ua, 'tablet' ) != -1 )
            || index( $ua, 'kindle' ) != -1
            || index( $ua, 'xoom' ) != -1
            || index( $ua, 'flyer' ) != -1
            || index( $ua, 'jetstream' ) != -1
            || index( $ua, 'transformer' ) != -1
            || index( $ua, 'novo7' ) != -1
            || index( $ua, 'an10g2' ) != -1
            || index( $ua, 'an7bg3' ) != -1
            || index( $ua, 'an7fg3' ) != -1
            || index( $ua, 'an8g3' ) != -1
            || index( $ua, 'an8cg3' ) != -1
            || index( $ua, 'an7g3' ) != -1
            || index( $ua, 'an9g3' ) != -1
            || index( $ua, 'an7dg3' ) != -1
            || index( $ua, 'an7dg3st' ) != -1
            || index( $ua, 'an7dg3childpad' ) != -1
            || index( $ua, 'an10bg3' ) != -1
            || index( $ua, 'an10bg3dt' ) != -1
            || index( $ua, 'opera tablet' ) != -1
            || index( $ua, 'rim tablet' ) != -1
            || index( $ua, 'hp-tablet' ) != -1
    );

    if ( !$device_tests->{tablet} ) {
        $device_tests->{mobile} = (
            ( $browser_tests->{firefox} && index( $ua, 'mobile' ) != -1 )
                || ( $browser_tests->{ie}
                && index( $ua, 'windows phone' ) == -1
                && index( $ua, 'arm' ) != -1 )
                || index( $ua, 'windows phone' ) != -1
                || index( $ua, 'up.browser' ) != -1
                || index( $ua, 'nokia' ) != -1
                || index( $ua, 'alcatel' ) != -1
                || index( $ua, 'ericsson' ) != -1
                || index( $ua, 'sie-' ) == 0
                || index( $ua, 'wmlib' ) != -1
                || index( $ua, ' wap' ) != -1
                || index( $ua, 'wap ' ) != -1
                || index( $ua, 'wap/' ) != -1
                || index( $ua, '-wap' ) != -1
                || index( $ua, 'wap-' ) != -1
                || index( $ua, 'wap' ) == 0
                || index( $ua, 'wapper' ) != -1
                || index( $ua, 'blackberry' ) != -1
                || index( $ua, 'mobile' ) != -1
                || index( $ua, 'palm' ) != -1
                || index( $ua, 'smartphone' ) != -1
                || index( $ua, 'windows ce' ) != -1
                || index( $ua, 'palmsource' ) != -1
                || index( $ua, 'iphone' ) != -1
                || index( $ua, 'ipod' ) != -1
                || index( $ua, 'ipad' ) != -1
                || ( index( $ua, 'opera mini' ) != -1
                && index( $ua, 'tablet' ) == -1 )
                || index( $ua, 'htc_' ) != -1
                || index( $ua, 'symbian' ) != -1
                || index( $ua, 'webos' ) != -1
                || index( $ua, 'samsung' ) != -1
                || index( $ua, 'samsung' ) != -1
                || index( $ua, 'zetor' ) != -1
                || index( $ua, 'android' ) != -1
                || index( $ua, 'symbos' ) != -1
                || index( $ua, 'opera mobi' ) != -1
                || index( $ua, 'fennec' ) != -1
                || $ua =~ m{\bbrew\b}
                || index( $ua, 'obigo' ) != -1
                || index( $ua, 'teleca' ) != -1
                || index( $ua, 'polaris' ) != -1
                || index( $ua, 'opera tablet' ) != -1
                || index( $ua, 'rim tablet' ) != -1
                || ( index( $ua, 'bb10' ) != -1
                && index( $ua, 'mobile' ) != -1 )
                || $device_tests->{psp}
                || $device_tests->{dsi}
                || $device_tests->{'n3ds'}
        );
    }

    if (
        $browser_tests->{ucbrowser}
        && ( $self->{user_agent}
            =~ m{ucweb/2.0\s*\(([^\;\)]*\;){4}\s*([^\;\)]*?)\s*\)}i
            || $self->{user_agent}
            =~ m{ucweb/2.0\s*\(([^\;\)]*\;){3}\s*([^\;\)]*?)\s*\)}i )
        ) {
        $device_string = $2;
    }
    elsif ( $ua =~ /^(\bmot-[^ \/]+)/ ) {
        $device_string = substr $self->{user_agent}, 0, length $1;
        $device_string =~ s/^MOT-/Motorola /i;
    }
    elsif ( ( $browser_tests->{obigo} || index( $ua, 'brew' ) != -1 )
        && $self->{user_agent} =~ m{\d+x\d+ ([\d\w\- ]+?)( \S+\/\S+)*$}i ) {
        $device_string = $1;
    }
    elsif (
        $ua =~ /windows phone os [^\)]+ iemobile\/[^;]+; ([^;]+; [^;\)]+)/g )
    {
        # windows phone 7.x
        $device_string = substr $self->{user_agent},
            pos($ua) - length $1, length $1;
        $device_string =~ s/; / /;
    }
    elsif ( $ua
        =~ /windows phone [^\)]+ iemobile\/[^;]+; arm; touch; ([^;]+; [^;\)]+)/g
        ) {
        # windows phone 8.0
        $device_string = substr $self->{user_agent},
            pos($ua) - length $1, length $1;
        $device_string =~ s/; / /;
    }
    elsif (
        $ua =~ /windows phone 8[^\)]+ iemobile\/[^;]+; ([^;]+; [^;\)]+)/g ) {

        # windows phone 8.1
        $device_string = substr $self->{user_agent},
            pos($ua) - length $1, length $1;
        $device_string =~ s/; / /;
    }
    elsif ( $ua =~ /bb10; ([^;\)]+)/g ) {
        $device_string = 'BlackBerry ' . substr $self->{user_agent},
            pos($ua) - length $1, length $1;
        $device_string =~ s/Kbd/Q10/;
    }
    elsif ( $ua =~ /blackberry ([\w.]+)/ ) {
        $device_string = "BlackBerry $1";
    }
    elsif ( $ua =~ /blackberry(\d+)\// ) {
        $device_string = "BlackBerry $1";
    }
    elsif ( $ua =~ /silk-accelerated/ ) {

        # Only first generation Kindle Fires have that string
        $device_string = 'Kindle Fire';
        $device_tests->{kindlefire} = 1;
    }
    elsif ( $self->{user_agent} =~ /android .*\; ([^;]*) build/i ) {
        my $model = $1;
        if ( $model =~ m{^KF} || $model =~ m{kindle fire}i ) {

            # We might hit this even if tablet() is false, if we have
            # a Kindle Fire masquerading as a mobile device.
            $device_string = 'Kindle Fire';
            $device_tests->{kindlefire} = 1;
        }
        elsif ( $device_tests->{tablet} ) {
            $device_string = "Android tablet ($model)";
        }
        else {
            $device_string = "Android ($model)";
        }
    }
    elsif ( $self->{user_agent}
        =~ /\b((alcatel|huawei|lg|nokia|samsung|sonyericsson)[\w\-]*)\//i ) {
        $device_string = $1;
    }
    elsif ($device) {
        $device_string = $DEVICE_NAMES{$device};
    }
    else {
        $device_string = undef;
    }

    if ($device) {
        $self->{device} = $device;
    }
    else {
        $self->{device}
            = undef;    # Means we cache the fact that we found nothing
    }

    if ($device_string) {
        $self->{device_string} = $device_string;
    }
}

### Now a big block of public accessors for tests and information

sub browser {
    my ($self) = @_;
    return undef unless defined $self->{user_agent};
    return $self->{browser};
}

sub browser_string {
    my ($self) = @_;
    return undef unless defined $self->{user_agent};
    return $self->{browser_string};
}

sub robot_string {
    my $self = shift;

    $self->_init_robots unless exists( $self->{robot_string} );
    return $self->{robot_string};
}

sub robot_name {
    my ($self) = @_;
    return $self->robot_string;
}

sub _robot_version {
    my ($self) = @_;
    $self->_init_robots unless exists( $self->{robot_string} );
    if ( $self->{robot_version} ) {
        return @{ $self->{robot_version} };
    }
    else {
        return ( undef, undef, undef );
    }
}

sub robot_version {
    my ($self) = @_;
    my ( $major, $minor, $beta ) = $self->_robot_version;
    if ( defined($major) ) {
        if ( defined($minor) ) {
            return "$major$minor";
        }
        else {
            return $major;
        }
    }
    else {
        return undef;
    }
}

sub robot_major {
    my ($self) = @_;
    my ( $major, $minor, $beta ) = $self->_robot_version;
    return $major;
}

sub robot_minor {
    my ($self) = @_;
    my ( $major, $minor, $beta ) = $self->_robot_version;
    return $minor;
}

sub robot_beta {
    my ($self) = @_;
    my ( $major, $minor, $beta ) = $self->_robot_version;
    return $beta;
}

sub os {
    my ($self) = @_;

    return undef unless defined $self->{user_agent};
    $self->_init_os unless $self->{os_tests};
    return $self->{os};
}

sub os_string {
    my ($self) = @_;

    return undef unless defined $self->{user_agent};
    $self->_init_os unless $self->{os_tests};
    return $self->{os_string};
}

sub _os_version {
    my ($self) = @_;
    $self->_init_os_version if !exists( $self->{os_version} );
    if ( $self->{os_version} ) {
        return @{ $self->{os_version} };
    }
    else {
        return ( undef, undef, undef );
    }
}

sub os_version {
    my ($self) = @_;
    my ( $major, $minor, $beta ) = $self->_os_version;
    if ( defined($major) ) {
        return "$major$minor";
    }
    else {
        return undef;
    }
}

sub os_major {
    my ($self) = @_;
    my ( $major, $minor, $beta ) = $self->_os_version;
    return $major;
}

sub os_minor {
    my ($self) = @_;
    my ( $major, $minor, $beta ) = $self->_os_version;
    return $minor;
}

sub os_beta {
    my ($self) = @_;
    my ( $major, $minor, $beta ) = $self->_os_version;
    return $beta;
}

sub _realplayer_version {
    my ($self) = @_;

    $self->_init_version unless $self->{version_tests};
    return $self->{realplayer_version} || 0;
}

sub realplayer_browser {
    my ($self) = @_;
    return defined( $self->{browser} ) && $self->{browser} eq 'realplayer';
}

sub gecko_version {
    my ($self) = @_;

    if ( $self->gecko ) {
        return $self->{engine_version};
    }
    else {
        return undef;
    }
}

sub version {
    my ($self) = @_;
    $self->_init_version() unless $self->{version_tests};

    my $version = "$self->{major}$self->{minor}";
    return $version;
}

sub major {
    my ($self) = @_;
    $self->_init_version() unless $self->{version_tests};

    my ($version) = $self->{major};
    return $version;
}

sub minor {
    my ($self) = @_;
    $self->_init_version() unless $self->{version_tests};

    my ($version) = $self->{minor};
    return $version;
}

sub public_version {
    my ($self) = @_;
    my ( $major, $minor ) = $self->_public;

    return "$major$minor";
}

sub public_major {
    my ($self) = @_;
    my ( $major, $minor ) = $self->_public;

    return $major;
}

sub public_minor {
    my ($self) = @_;
    my ( $major, $minor ) = $self->_public;

    return $minor;
}

sub public_beta {
    my ($self) = @_;
    my ( $major, $minor, $beta ) = $self->_public;

    return $beta;
}

sub browser_version {
    my ($self) = @_;
    my ( $major, $minor ) = $self->_public;

    return "$major$minor";
}

sub browser_major {
    my ($self) = @_;
    my ( $major, $minor ) = $self->_public;

    return $major;
}

sub browser_minor {
    my ($self) = @_;
    my ( $major, $minor ) = $self->_public;

    return $minor;
}

sub browser_beta {
    my ($self) = @_;
    my ( $major, $minor, $beta ) = $self->_public;

    return $beta;
}

sub _public {
    my ($self) = @_;

    # Return Public version of Safari. See RT #48727.
    if ( $self->safari ) {
        my $ua = lc $self->{user_agent};

        # Safari starting with version 3.0 provides its own public version
        if (
            $ua =~ m{
                version/
                ( \d+ )       # Major version number is everything before first dot
                ( \. \d+ )?   # Minor version number is first dot and following digits
            }x
            ) {
            return ( $1, $2, undef );
        }

        # Safari before version 3.0 had only build numbers; use a lookup table
        # provided by Apple to convert to version numbers

        if ( $ua =~ m{ safari/ ( \d+ (?: \.\d+ )* ) }x ) {
            my $build   = $1;
            my $version = $safari_build_to_version{$build};
            unless ($version) {

                # if exact build -> version mapping doesn't exist, find next
                # lower build

                for my $maybe_build (
                    sort { $self->_cmp_versions( $b, $a ) }
                    keys %safari_build_to_version
                    ) {
                    $version = $safari_build_to_version{$maybe_build}, last
                        if $self->_cmp_versions( $build, $maybe_build ) >= 0;
                }

                # Special case for specific worm that uses a malformed user agent
                return ( '1', '.2', undef ) if $ua =~ m{safari/12x};
            }
            my ( $major, $minor ) = split /\./, $version;
            my $beta;
            $minor =~ s/(\D.*)// and $beta = $1;
            $minor = ( '.' . $minor );
            return ( $major, $minor, ( $beta ? 1 : undef ) );
        }
    }

    $self->_init_version() unless $self->{version_tests};
    return ( $self->{major}, $self->{minor}, $self->{beta} );
}

sub _cmp_versions {
    my ( $self, $a, $b ) = @_;

    my @a = split /\./, $a;
    my @b = split /\./, $b;

    while (@b) {
        return -1 if @a == 0 || $a[0] < $b[0];
        return 1  if @b == 0 || $b[0] < $a[0];
        shift @a;
        shift @b;
    }

    return @a <=> @b;
}

sub engine {
    my ($self) = @_;

    # *shrug*
    if ( my $engine_string = $self->engine_string ) {
        if ( $engine_string eq 'MSIE' ) {
            return 'ie';
        }
        else {
            return lc $engine_string;
        }
    }
    else {
        return undef;
    }
}

sub engine_string {
    my ($self) = @_;

    if ( $self->gecko ) {
        return 'Gecko';
    }

    if ( $self->trident ) {
        return 'Trident';
    }

    if ( $self->ie ) {
        return 'MSIE';
    }

    if ( $self->edge ) {
        return 'EdgeHTML';
    }

    if ( $self->webkit ) {
        return 'WebKit';
    }

    if ( $self->presto ) {
        return 'Presto';
    }

    if ( $self->netfront ) {
        return 'NetFront';
    }

    if ( $self->khtml ) {
        return 'KHTML';
    }

    return undef;
}

sub engine_version {
    my ($self) = @_;

    if ( $self->{engine_version} ) {
        if ( $self->{engine_version} =~ m{^(\d+(\.\d+)?)} ) {
            return $1;
        }
    }

    return $self->{engine_version};
}

sub engine_major {
    my ($self) = @_;

    if ( $self->{engine_version} ) {
        if ( $self->{engine_version} =~ m{^(\d+)} ) {
            return $1;
        }
    }

    return undef;
}

sub engine_minor {
    my ($self) = @_;

    if ( $self->{engine_version} ) {
        if ( $self->{engine_version} =~ m{^\d+(\.\d+)} ) {
            return $1;
        }
    }

    return undef;
}

sub engine_beta {
    my ($self) = @_;

    if ( $self->{engine_version} ) {
        if ( $self->{engine_version} =~ m{^\d+\.\d+([\.\d\+]*)} ) {
            return $1;
        }
    }

    return undef;
}

sub beta {
    my ($self) = @_;

    $self->_init_version unless $self->{version_tests};

    my ($version) = $self->{beta};
    return $version;
}

sub language {
    my ($self) = @_;

    my $parsed = $self->_language_country();
    return $parsed->{'language'};
}

sub country {
    my ($self) = @_;

    my $parsed = $self->_language_country();
    return $parsed->{'country'};
}

sub device {
    my ($self) = @_;

    $self->_init_device if !exists( $self->{device} );
    return $self->{device};
}

sub device_string {
    my ($self) = @_;

    $self->_init_device if !exists( $self->{device_string} );
    return $self->{device_string};
}

sub device_name {
    my ($self) = @_;
    return $self->device_string;
}

sub _language_country {
    my ($self) = @_;

    if ( $self->safari ) {
        if (   $self->major == 1
            && $self->{user_agent} =~ m/\s ( [a-z]{2} ) \)/xms ) {
            return { language => uc $1 };
        }
        if ( $self->{user_agent} =~ m/\s ([a-z]{2})-([A-Za-z]{2})/xms ) {
            return { language => uc $1, country => uc $2 };
        }
    }

    if (   $self->aol
        && $self->{user_agent} =~ m/;([A-Z]{2})_([A-Z]{2})\)/ ) {
        return { language => $1, country => $2 };
    }

    if ( $self->{user_agent} =~ m/\b([a-z]{2})-([A-Za-z]{2})\b/xms ) {
        return { language => uc $1, country => uc $2 };
    }

    if ( $self->{user_agent} =~ m/\[([a-z]{2})\]/xms ) {
        return { language => uc $1 };
    }

    if ( $self->{user_agent} =~ m/\(([^)]+)\)/xms ) {
        my @parts = split( /;/, $1 );
        foreach my $part (@parts) {
            if ( $part =~ /^\s*([a-z]{2})\s*$/ ) {
                return { language => uc $1 };
            }
        }
    }

    return { language => undef, country => undef };
}

sub browser_properties {
    my ($self) = @_;

    my @browser_properties;

    my ( $test, $value );

    while ( ( $test, $value ) = each %{ $self->{tests} } ) {
        push @browser_properties, $test if $value;
    }
    while ( ( $test, $value ) = each %{ $self->{browser_tests} } ) {
        push @browser_properties, $test if $value;
    }

    $self->_init_device  unless $self->{device_tests};
    $self->_init_os      unless $self->{os_tests};
    $self->_init_robots  unless $self->{robot_tests};
    $self->_init_version unless $self->{version_tests};

    while ( ( $test, $value ) = each %{ $self->{device_tests} } ) {
        push @browser_properties, $test if $value;
    }
    while ( ( $test, $value ) = each %{ $self->{os_tests} } ) {
        push @browser_properties, $test if $value;
    }
    while ( ( $test, $value ) = each %{ $self->{robot_tests} } ) {
        push @browser_properties, $test if $value;
    }
    while ( ( $test, $value ) = each %{ $self->{version_tests} } ) {
        push @browser_properties, $test if $value;
    }

    # devices are a property too but it's not stored in %tests
    # so I explicitly test for it and add it
    push @browser_properties, 'device' if ( $self->device() );

    return sort @browser_properties;
}

1;

# ABSTRACT: Determine Web browser, version, and platform from an HTTP user agent string

__END__

=pod

=encoding UTF-8

=head1 NAME

HTTP::BrowserDetect - Determine Web browser, version, and platform from an HTTP user agent string

=head1 VERSION

version 3.14

=head1 SYNOPSIS

    use HTTP::BrowserDetect;

    my $ua = HTTP::BrowserDetect->new($user_agent_string);

    # Print general information
    print "Browser: $ua->browser_string\n"
        if $ua->browser_string;
    print "Version: $ua->browser_version$ua->browser_beta\n"
        if $ua->browser_version;
    print "OS: $ua->os_string\n"
        if $ua->os_string;

    # Detect operating system
    if ($ua->windows) {
      if ($ua->winnt) ...
      if ($ua->win95) ...
    }
    print "Mac\n" if $ua->macosx;

    # Detect browser vendor and version
    print "Safari\n" if $ua->safari;
    print "MSIE\n" if $ua->ie;
    print "Mobile\n" if $ua->mobile;
    if ($ua->browser_major(4)) {
    if ($ua->browser_minor() > .5) {
        ...
    }
    }
    if ($ua->browser_version() > 4.5) {
      ...;
    }

=head1 DESCRIPTION

The HTTP::BrowserDetect object does a number of tests on an HTTP user agent
string. The results of these tests are available via methods of the object.

This module was originally based upon the JavaScript browser detection
code available at
L<http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html>.

=head1 CONSTRUCTOR AND STARTUP

=head2 new()

    HTTP::BrowserDetect->new( $user_agent_string )

The constructor may be called with a user agent string specified. Otherwise, it
will use the value specified by $ENV{'HTTP_USER_AGENT'}, which is set by the
web server when calling a CGI script.

=head1 SUBROUTINES/METHODS

=head1 Browser Information

=head2 browser()

Returns the browser, as one of the following values:

chrome, firefox, ie, opera, safari, adm, applecoremedia, blackberry,
brave, browsex, dalvik, elinks, links, lynx, emacs, epiphany, galeon,
konqueror, icab, lotusnotes, mosaic, mozilla, netfront, netscape,
n3ds, dsi, obigo, polaris, pubsub, realplayer, seamonkey, silk,
staroffice, ucbrowser, webtv

If the browser could not be identified (either because unrecognized
or because it is a robot), returns C<undef>.

=head2 browser_string()

Returns a human formatted version of the browser name. These names are
subject to change and are meant for display purposes. This may include
information additional to what's in browser() (e.g. distinguishing
Firefox from Iceweasel).

If the user agent could not be identified, or if it was identified as
a robot instead, returns C<undef>.

=head1 Browser Version

Please note that that the version(), major() and minor() methods have been
deprecated as of release 1.78 of this module. They should be replaced
with browser_version(), browser_major(), browser_minor(), and browser_beta().

The reasoning behind this is that version() method will, in the case of Safari,
return the Safari/XXX numbers even when Version/XXX numbers are present in the
UserAgent string (i.e. it will return incorrect versions for Safari in
some cases).

=head2 browser_version()

Returns the browser version (major and minor) as a string. For
example, for Chrome 36.0.1985.67, this returns "36.0".

=head2 browser_major()

Returns the major part of the version as a string. For example, for
Chrome 36.0.1985.67, this returns "36".

Returns undef if no version information can be detected.

=head2 browser_minor()

Returns the minor part of the version as a string. This includes the
decimal point; for example, for Chrome 36.0.1985.67, this returns
".0".

Returns undef if no version information can be detected.

=head2 browser_beta()

Returns any part of the version after the major and minor version, as
a string. For example, for Chrome 36.0.1985.67, this returns
".1985.67". The beta part of the string can contain any type of
alphanumeric characters.

Returns undef if no version information can be detected. Returns an
empty string if version information is detected but it contains only
a major and minor version with nothing following.

=head1 Operating System

=head2 os()

Returns one of the following strings, or C<undef>:

  windows, winphone, mac, macosx, linux, android, ios, os2, unix, vms,
  chromeos, firefoxos, ps3, psp, rimtabletos, blackberry, amiga, brew

=head2 os_string()

Returns a human formatted version of the OS name.  These names are
subject to change and are really meant for display purposes. This may
include information additional to what's in os() (e.g. distinguishing
various editions of Windows from one another) (although for a way to
do that that's more suitable for use in program logic, see below under
"OS related properties").

Returns C<undef> if no OS information could be detected.

=head2 os_version(), os_major(), os_minor(), os_beta()

Returns version information for the OS, if any could be detected. The
format is the same as for the browser_version() functions.

=head1 Mobile Devices

=head2 mobile()

Returns true if the browser appears to belong to a mobile phone or
similar device (i.e. one small enough that the mobile version of a
page is probably preferable over the desktop version).

In previous versions, tablet devices sometimes had mobile() return
true. They are now mutually exclusive.

=head2 tablet()

Returns true if the browser appears to belong to a tablet device.

=head2 device()

Returns the type of mobile / tablet hardware, if it can be detected.

Currently returns one of: android, audrey, avantgo, blackberry, dsi, iopener, ipad,
iphone, ipod, kindle, n3ds, palm, ps3, psp, wap, webos, winphone.

Returns C<undef> if this is not a tablet/mobile device or no hardware
information can be detected.

=head2 device_string()

Returns a human formatted version of the hardware device name.  These names are
subject to change and are really meant for display purposes.  You should use
the device() method in your logic. This may include additional
information (such as the model of phone if it is detectable).

Returns C<undef> if this is not a portable device or if no device name
can be detected.

=head1 Robots

=head2 robot()

If the user agent appears to be a robot, spider, crawler, or other
automated Web client, this returns one of the following values:

lwp, slurp, yahoo, bingbot, msnmobile, msn, msoffice, ahrefs,
altavista, apache, askjeeves, baidu, curl, facebook, getright,
googleadsbot, googleadsense, googlebotimage, googlebotnews,
googlebotvideo, googlefavicon, googlemobile, google, golib, indy,
infoseek, ipsagent, linkchecker, linkexchange, lycos, malware,
mj12bot, nutch, phplib, puf, rubylib, scooter, specialarchiver,
wget, yandexbot, yandeximages, java, unknown

Returns "unknown" when the user agent is believed to be a robot but
is not identified as one of the above specific robots.

Returns C<undef> if the user agent is not a robot or cannot be
identified.

Note that if a robot crafts a user agent designed to impersonate a
particular browser, we generally set properties appropriate to both
the actual robot, and the browser it is impersonating. For example,
googlebot-mobile pretends to be mobile safari so that it will get
mobile versions of pages. In this case, browser() will return
'safari', the properties will generally be set as if for Mobile
Safari, the 'robot' property will be set, and robot() will return
'googlemobile'.

=head3 lib()

Returns true if the user agent appears to be an HTTP library or tool
(e.g. LWP, curl, wget, java). Generally libraries are also classified
as robots, although it is impossible to tell whether they are being
operated by an automated system or a human.

=head3 robot_string()

Returns a human formatted version of the robot name. These names are
subject to change and are meant for display purposes. This may include
additional information (e.g. robots which return "unknown" from
robot() generally can be identified in a human-readable fashion by
reading robot_string() ).

=head2 robot_version(), robot_major(), robot_minor(), robot_beta()

Returns version information for the robot, if any could be
detected. The format is the same as for the browser_version()
functions.

Note that if a robot crafts a user agent designed to impersonate a
particular browser, we generally return results appropriate to both
the actual robot, and the browser it is impersonating. For example,
googlebot-mobile pretends to be mobile safari so that it will get
mobile versions of pages. In this case, robot_version() will return
the version of googlebot-mobile, and browser_version() will return the
version of Safari that googlebot-mobile is impersonating.

=head1 Browser Properties

Operating systems, devices, browser names, rendering engines, and
true-or-false methods (e.g. "mobile" and "lib") are all browser
properties. For example, calling browser_properties() for Mobile
Safari running on an Android will return this list:

('android', 'device', 'mobile', 'mobile_safari', 'safari', 'webkit')

=head2 browser_properties()

Returns all properties for this user agent, as a list. Note that
because a large number of cases must be considered, this will take
significantly more time than simply querying the particular methods
you care about.

A mostly complete list of properties follows (i.e. each of these
methods is both a method you can call, and also a property that may
be in the list returned by browser_properties() ). In addition to this
list, robot(), lib(), device(), mobile(), and tablet() are all
browser properties.

=head2 OS related properties

The following methods are available, each returning a true or false value.
Some methods also test for the operating system version. The indentations
below show the hierarchy of tests (for example, win2k is considered a type of
winnt, which is a type of win32)

=head3 windows()

    win16 win3x win31
    win32
        winme win95 win98
        winnt
            win2k winxp win2k3 winvista win7
            win8
                win8_0 win8_1
            win10
                win10_0
    wince
    winphone
        winphone7 winphone7_5 winphone8 winphone10

=head3 dotnet()

=head3 chromeos()

=head3 firefoxos()

=head3 mac()

mac68k macppc macosx ios

=head3 os2()

=head3 bb10()

=head3 rimtabletos()

=head3 unix()

  sun sun4 sun5 suni86 irix irix5 irix6 hpux hpux9 hpux10
  aix aix1 aix2 aix3 aix4 linux sco unixware mpras reliant
  dec sinix freebsd bsd

=head3 vms()

=head3 amiga()

=head3 ps3gameos()

=head3 pspgameos()

It may not be possibile to detect Win98 in Netscape 4.x and earlier. On Opera
3.0, the userAgent string includes "Windows 95/NT4" on all Win32, so you can't
distinguish between Win95 and WinNT.

=head2 Browser related properties

The following methods are available, each returning a true or false value.
Some methods also test for the browser version, saving you from checking the
version separately.

=head3 adm

=head3 aol aol3 aol4 aol5 aol6

=head3 applecoremedia

=head3 avantgo

=head3 browsex

=head3 chrome

=head3 dalvik

=head3 emacs

=head3 epiphany

=head3 firefox

=head3 galeon

=head3 icab

=head3 ie ie3 ie4 ie4up ie5 ie5up ie55 ie55up ie6 ie7 ie8 ie9 ie10 ie11

=head3 ie_compat_mode

The ie_compat_mode is used to determine if the IE user agent is for
the compatibility mode view, in which case the real version of IE is
higher than that detected. The true version of IE can be inferred from
the version of Trident in the engine_version method.

=head3 konqueror

=head3 lotusnotes

=head3 lynx links elinks

=head3 mobile_safari

=head3 mosaic

=head3 mozilla

=head3 neoplanet neoplanet2

=head3 netfront

=head3 netscape nav2 nav3 nav4 nav4up nav45 nav45up navgold nav6 nav6up

=head3 obigo

=head3 opera opera3 opera4 opera5 opera6 opera7

=head3 polaris

=head3 pubsub

=head3 realplayer

The realplayer method above tests for the presence of either the RealPlayer
plug-in "(r1 " or the browser "RealPlayer".

=head3 realplayer_browser

The realplayer_browser method tests for the presence of the RealPlayer
browser (but returns 0 for the plugin).

=head3 safari

=head3 seamonkey

=head3 silk

=head3 staroffice

=head3 ucbrowser

=head3 webtv

Netscape 6, even though it's called six, in the User-Agent string has version
number 5. The nav6 and nav6up methods correctly handle this quirk. The Firefox
test correctly detects the older-named versions of the browser (Phoenix,
Firebird).

=head2 Device related properties

The following methods are available, each returning a true or false value.

=head3 android

=head3 audrey

=head3 avantgo

=head3 blackberry

=head3 dsi

=head3 iopener

=head3 iphone

=head3 ipod

=head3 ipad

=head3 kindle

=head3 kindlefire

=head3 n3ds

=head3 palm

=head3 webos

=head3 wap

Note that 'wap' indicates that the device is capable of WAP, not
necessarily that the device is limited to WAP only. Most modern WAP
devices are also capable of rendering standard HTML.

=head3 psp

=head3 ps3

=head2 Robot properties

The following additional methods are available, each returning a true or false
value. This is by no means a complete list of robots that exist on the Web.

=head3 ahrefs

=head3 altavista

=head3 apache

=head3 askjeeves

=head3 baidu

=head3 bingbot

=head3 curl

=head3 facebook

=head3 getright

=head3 golib

=head3 google

=head3 googleadsbot

=head3 googleadsense

=head3 googlemobile

=head3 indy

=head3 infoseek

=head3 ipsagent

=head3 java

=head3 linkexchange

=head3 lwp

=head3 lycos

=head3 malware

=head3 mj12bot

=head3 msn

=head3 msoffice

=head3 puf

=head3 rubylib

=head3 slurp

=head3 wget

=head3 yahoo

=head3 yandex

=head3 yandeximages

=head2 Engine properties

The following properties indicate if a particular rendering engine is
being used.

=head3 webkit

=head3 gecko

=head3 trident

=head3 presto

=head3 khtml

=head1 Other methods

=head2 user_agent()

Returns the value of the user agent string.

Calling this method with a parameter to set the user agent has now
been removed; please use HTTP::BrowserDetect->new() to pass the user
agent string.

=head2 country()

Returns the country string as it may be found in the user agent string. This
will be in the form of an upper case 2 character code. ie: US, DE, etc

=head2 language()

Returns the language string as it is found in the user agent string. This will
be in the form of an upper case 2 character code. ie: EN, DE, etc

=head2 engine()

Returns the rendering engine, one of the following:

gecko, webkit, khtml, trident, ie, presto, netfront

Note that this returns "webkit" for webkit based browsers (including
Chrome/Blink). This is a change from previous versions of this
library, which returned "KHTML" for webkit.

Returns C<undef> if none of the above rendering engines can be
detected.

=head2 engine_string()

Returns a human formatted version of the rendering engine.

Note that this returns "WebKit" for webkit based browsers (including
Chrome/Blink). This is a change from previous versions of this
library, which returned "KHTML" for webkit.

Returns C<undef> if none of the known rendering engines can be
detected.

=head2 engine_version(), engine_major(), engine_minor(), engine_beta()

Returns version information for the rendering engine, if any could be
detected. The format is the same as for the browser_version()
functions.

=head1 Deprecated methods

=head2 device_name()

Deprecated alternate name for device_string()

=head2 version()

This is probably not what you want.  Please use either browser_version() or
engine_version() instead.

Returns the version (major and minor) as a string.

This function returns wrong values for some Safari versions, for
compatibility with earlier code. browser_version() returns correct
version numbers for Safari.

=head2 major()

This is probably not what you want. Please use either browser_major()
or engine_major() instead.

Returns the integer portion of the browser version as a string.

This function returns wrong values for some Safari versions, for
compatibility with earlier code. browser_version() returns correct
version numbers for Safari.

=head2 minor()

This is probably not what you want. Please use either browser_minor()
or engine_minor() instead.

Returns the decimal portion of the browser version as a string.

This function returns wrong values for some Safari versions, for
compatibility with earlier code. browser_version() returns correct
version numbers for Safari.

=head2 beta()

This is probably not what you want. Please use browser_beta() instead.

Returns the beta version, consisting of any characters after the major
and minor version number, as a string.

This function returns wrong values for some Safari versions, for
compatibility with earlier code. browser_version() returns correct
version numbers for Safari.

=head2 public_version(), public_major(), public_minor(), public_beta()

Deprecated.  Please use browser_version() and related functions
instead.

=head2 gecko_version()

If a Gecko rendering engine is used (as in Mozilla or Firefox), returns the
engine version. If no Gecko browser is being used, or the version
number can't be detected, returns undef.

This is an old function, preserved for compatibility; please use
engine_version() in new code.

=head1 CREDITS

Lee Semel, lee@semel.net (Original Author)

Peter Walsham (co-maintainer)

Olaf Alders, C<olaf at wundercounter.com> (co-maintainer)

=head1 ACKNOWLEDGEMENTS

Thanks to the following for their contributions:

cho45

Leonardo Herrera

Denis F. Latypoff

merlynkline

Simon Waters

Toni Cebrin

Florian Merges

david.hilton.p

Steve Purkis

Andrew McGregor

Robin Smidsrod

Richard Noble

Josh Ritter

Mike Clarke

Marc Sebastian Pelzer

Alexey Surikov

Maros Kollar

Jay Rifkin

Luke Saunders

Jacob Rask

Heiko Weber

Jon Jensen

Jesse Thompson

Graham Barr

Enrico Sorcinelli

Olivier Bilodeau

Yoshiki Kurihara

Paul Findlay

Uwe Voelker

Douglas Christopher Wilson

John Oatis

Atsushi Kato

Ronald J. Kimball

Bill Rhodes

Thom Blake

Aran Deltac

yeahoffline

David Ihnen

Hao Wu

Perlover

Daniel Stadie

ben hengst

Andrew Moise

Atsushi Kato

Marco Fontani

Nicolas Doye

=head1 TO DO

POD coverage is not 100%.

=head1 SEE ALSO

"Browser ID (User-Agent) Strings", L<http://www.zytrax.com/tech/web/browser_ids.htm>

L<HTML::ParseBrowser>.

=head1

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc HTTP::BrowserDetect

You can also look for information at:

=over 4

=item * GitHub Source Repository

L<http://github.com/oalders/http-browserdetect>

=item * Reporting Issues

L<https://github.com/oalders/http-browserdetect/issues>

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/HTTP-BrowserDetect>

=item * CPAN Ratings

L<http://cpanratings.perl.org/d/HTTP-BrowserDetect>

=item * Search CPAN

L<https://metacpan.org/module/HTTP::BrowserDetect>

=back

=head1 BUGS AND LIMITATIONS

The biggest limitation at this point is the test suite, which really needs to
have many more UserAgent strings to test against.

=head1 CONTRIBUTING

Patches are certainly welcome, with many thanks for the excellent contributions
which have already been received. The preferred method of patching would be to
fork the GitHub repo and then send me a pull request, but plain old patch files
are also welcome.

If you're able to add test cases, this will speed up the time to release your
changes. Just edit t/useragents.json so that the test coverage includes any
changes you have made. Please contact me if you have any questions.

This distribution uses L<Dist::Zilla>. If you're not familiar with this module,
please see L<https://github.com/oalders/http-browserdetect/issues/5> for some
helpful tips to get you started.

=head1 AUTHORS

=over 4

=item *

Lee Semel <lee@semel.net>

=item *

Peter Walsham

=item *

Olaf Alders <olaf@wundercounter.com> (current maintainer)

=back

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by Lee Semel.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut