Tree @upstream/1.24 (Download .tar.gz)
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 | NAME HTTP::BrowserDetect - Determine Web browser, version, and platform from an HTTP user agent string VERSION version 1.24 SYNOPSIS use HTTP::BrowserDetect; my $browser = HTTP::BrowserDetect->new($user_agent_string); # Detect operating system if ($browser->windows) { if ($browser->winnt) ... if ($browser->win95) ... } print $browser->mac; # Detect browser vendor and version print $browser->netscape; print $browser->ie; if (browser->major(4)) { if ($browser->minor() > .5) { ... } } if ($browser->version() > 4) { ...; } # Process a different user agent string $browser->user_agent($another_user_agent_string); 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 is based upon the JavaScript browser detection code available at http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html. INSTALLATION In most cases, you can just issue the following commands: perl Build.PL ./Build ./Build test ./Build install Please see the documentation for Module::Build if you have questions about installing to custom locations etc. CONSTRUCTOR AND STARTUP 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. You may also use a non-object-oriented interface. For each method, you may call HTTP::BrowserDetect::method_name(). You will then be working with a default HTTP::BrowserDetect object that is created behind the scenes. SUBROUTINES/METHODS user_agent($user_agent_string) Returns the value of the user agent string. When called with a parameter, it resets the user agent and reperforms all tests on the string. This way you can process a series of user agent strings (from a log file, perhaps) without creating a new HTTP::BrowserDetect object each time. 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 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 device() Returns the method name of the actual hardware, if it can be detected. Currently returns one of: blackberry, webos, iphone, ipod or ipad Returns UNDEF if no hardware can be detected device_name() 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. Returns one of: BlackBerry, iPhone, iPod or iPad. Returns UNDEF if no hardware can be detected. browser_properties() Returns a list of the browser properties, that is, all of the tests that passed for the provided user_agent string. Operating systems, devices, browser names, mobile and robots are all browser properties. Detecting Browser Version Please note that that the version(), major() and minor() methods have been superceded as of release 1.07 of this module. They are not yet deprecated, but should be replaced with public_version(), public_major() and public_minor() in new development. 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. Because this behaviour has been in place for so long, some clients may have come to rely upon it. So, it has been retained in the interest of "bugwards compatibility", but in almost all cases, the numbers returned by public_version(), public_major() and public_minor() will be what you are looking for. public_version() Returns the browser version as a floating-point number. public_major() Returns the integer portion of the browser version. public_minor() Returns the decimal portion of the browser version as a floating-point number less than 1. For example, if the version is 4.05, this method returns .05; if the version is 4.5, this method returns .5. On occasion a version may have more than one decimal point, such as 'Wget/1.4.5'. The minor version does not include the second decimal point, or any further digits or decimals. version($version) Returns the version as a floating-point number. If passed a parameter, returns true if it is equal to the version specified by the user agent string. major($major) Returns the integer portion of the browser version. If passed a parameter, returns true if it equals the browser major version. minor($minor) Returns the decimal portion of the browser version as a floating-point number less than 1. For example, if the version is 4.05, this method returns .05; if the version is 4.5, this method returns .5. This is a change in behavior from previous versions of this module, which returned a string. If passed a parameter, returns true if equals the minor version. On occasion a version may have more than one decimal point, such as 'Wget/1.4.5'. The minor version does not include the second decimal point, or any further digits or decimals. beta($beta) Returns any the beta version, consisting of any non-numeric characters after the version number. For instance, if the user agent string is 'Mozilla/4.0 (compatible; MSIE 5.0b2; Windows NT)', returns 'b2'. If passed a parameter, returns true if equal to the beta version. If the beta starts with a dot, it is thrown away. Detecting Rendering Engine engine_string() Returns one of the following: Gecko, KHTML, MSIE, NetFront Returns undef if no string can be found. engine_version() Returns the version number of the rendering engine. Currently this only returns a version number for Gecko. Returns undef for all other engines. engine_major() Returns the major version number of the rendering engine. Currently this only returns a version number for Gecko. Returns undef for all other engines. engine_minor() Returns the minor version number of the rendering engine. Currently this only returns a version number for Gecko. Returns undef for all other engines. Detecting OS Platform and Version 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) windows() win16 win3x win31 win32 winme win95 win98 winnt win2k winxp win2k3 winvista win7 wince dotnet() mac() mac68k macppc macosx os2() 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 vms() amiga() ps3gameos() 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. os_string() Returns one of the following strings, or undef. This method exists solely for compatibility with the HTTP::Headers::UserAgent module. Win95, Win98, WinNT, Win2K, WinXP, Win2k3, WinVista, Win7, Mac, Mac OS X, Win3x, OS2, Unix, Linux, Playstation 3 GameOS, Playstation Portable GameOS Detecting Browser Vendor 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. aol aol3 aol4 aol5 aol6 chrome curl emacs firefox gecko icab ie ie3 ie4 ie4up ie5 ie55 ie6 ie7 ie8 java konqueror lotusnotes lynx links elinks mobile_safari mosaic mozilla neoplanet neoplanet2 netfront netscape nav2 nav3 nav4 nav4up nav45 nav45up navgold nav6 nav6up opera opera3 opera4 opera5 opera6 opera7 realplayer safari staroffice webtv Netscape 6, even though its 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). browser_string() Returns undef on failure. Otherwise returns one of the following: Netscape, Firefox, Safari, Chrome, MSIE, WebTV, AOL Browser, Opera, Mosaic, Lynx, Links, ELinks, RealPlayer, IceWeasel, curl, puf, NetFront, Mobile Safari gecko_version() If a Gecko rendering engine is used (as in Mozilla or Firefox), returns the version of the renderer (e.g. 1.3a, 1.7, 1.8) This might be more useful than the particular browser name or version when correcting for quirks in different versions of this rendering engine. If no Gecko browser is being used, or the version number can't be detected, returns undef. Detecting Other Devices The following methods are available, each returning a true or false value. android audrey avantgo blackberry iopener iphone ipod ipad kindle palm webos wap psp ps3 mobile() Returns true if the browser appears to belong to a handheld device. robot() Returns true if the user agent appears to be a robot, spider, crawler, or other automated Web client. 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. altavista facebook getright google googlemobile infoseek linkexchange lwp lycos msn (same as bing) puf slurp webcrawler wget yahoo CREDITS Lee Semel, lee@semel.net (Original Author) Peter Walsham (co-maintainer) Olaf Alders, "olaf at wundercounter.com" (co-maintainer) ACKNOWLEDGEMENTS Thanks to the following for their contributions: 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 TO DO The _engine() method currently only handles Gecko. It needs to be expanded to handle other rendering engines. POD coverage is also not 100%. SEE ALSO "The Ultimate JavaScript Client Sniffer, Version 3.0", http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html "Browser ID (User-Agent) Strings", http://www.zytrax.com/tech/web/browser_ids.htm Safari "Historical User Agent strings", http://developer.apple.com/internet/safari/uamatrix.html (now gone, retrieved 2007-06-20) "Safari Agent Strings", http://homepage.mac.com/jprince/designSandbox/web/safari-agents/ perl(1), HTTP::Headers, HTTP::Headers::UserAgent. SUPPORT You can find documentation for this module with the perldoc command. perldoc HTTP::BrowserDetect You can also look for information at: * GitHub Source Repository <http://github.com/oalders/http-browserdetect> * RT: CPAN's request tracker <http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTTP-BrowserDetect> * AnnoCPAN: Annotated CPAN documentation <http://annocpan.org/dist/HTTP-BrowserDetect> * CPAN Ratings <http://cpanratings.perl.org/d/HTTP-BrowserDetect> * Search CPAN <http://search.cpan.org/dist/HTTP-BrowserDetect/> 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. 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 requests, 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. AUTHORS * Lee Semel <lee@semel.net> * Peter Walsham * Olaf Alders <olaf@wundercounter.com> (current maintainer) COPYRIGHT AND LICENSE This software is copyright (c) 2011 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. |
Commit History @upstream/1.24
0
»»
- [svn-upgrade] new version libhttp-browserdetect-perl (1.12) Ansgar Burchardt 13 years ago
- [svn-upgrade] Integrating new upstream version, libhttp-browserdetect-perl (1.11) Ansgar Burchardt 13 years ago
- [svn-upgrade] Integrating new upstream version, libhttp-browserdetect-perl (1.10) Jonathan Yu 13 years ago
- [svn-upgrade] Integrating new upstream version, libhttp-browserdetect-perl (1.09) Jonathan Yu 14 years ago
- [svn-upgrade] Integrating new upstream version, libhttp-browserdetect-perl (1.08) Gregor Herrmann 14 years ago
- [svn-inject] Installing original source of libhttp-browserdetect-perl Gregor Herrmann 14 years ago
0
»»