Imported Upstream version 1.31
Angel Abad
12 years ago
26 | 26 | "Olaf Alders <olaf\@wundercounter.com> (current maintainer)" |
27 | 27 | ], |
28 | 28 | "dist_name" => "HTTP-BrowserDetect", |
29 | "dist_version" => "1.30", | |
29 | "dist_version" => "1.31", | |
30 | 30 | "license" => "perl", |
31 | 31 | "module_name" => "HTTP::BrowserDetect", |
32 | 32 | "recommends" => {}, |
0 | 0 | Revision history for Perl extension HTTP::BrowserDetect. |
1 | ||
2 | 1.31 2011-10-12 | |
3 | - Adds detection and device name for Windows Phone (Douglas Christopher Wilson) | |
1 | 4 | |
2 | 5 | 1.30 2011-09-15 |
3 | 6 | - Tweaks language regexes to reduce false positives |
57 | 57 | "web" : "http://github.com/oalders/http-browserdetect" |
58 | 58 | } |
59 | 59 | }, |
60 | "version" : "1.30" | |
60 | "version" : "1.31" | |
61 | 61 | } |
62 | 62 |
33 | 33 | "strict" => 0, |
34 | 34 | "vars" => 0 |
35 | 35 | }, |
36 | "VERSION" => "1.30", | |
36 | "VERSION" => "1.31", | |
37 | 37 | "test" => { |
38 | 38 | "TESTS" => "t/*.t" |
39 | 39 | } |
2 | 2 | an HTTP user agent string |
3 | 3 | |
4 | 4 | VERSION |
5 | version 1.30 | |
5 | version 1.31 | |
6 | 6 | |
7 | 7 | SYNOPSIS |
8 | 8 | use HTTP::BrowserDetect; |
91 | 91 | Returns a human formatted version of the hardware device name. These |
92 | 92 | names are subject to change and are really meant for display purposes. |
93 | 93 | You should use the device() method in your logic. Returns one of: |
94 | BlackBerry, iPhone, iPod or iPad. Returns UNDEF if no hardware can be | |
95 | detected. | |
94 | BlackBerry, iPhone, iPod or iPad or device name found in user agent | |
95 | string. Returns "undef" if no hardware can be detected. | |
96 | 96 | |
97 | 97 | browser_properties() |
98 | 98 | Returns a list of the browser properties, that is, all of the tests that |
192 | 192 | winnt |
193 | 193 | win2k winxp win2k3 winvista win7 |
194 | 194 | wince |
195 | winphone | |
195 | 196 | |
196 | 197 | dotnet() |
197 | 198 | mac() |
215 | 216 | Returns one of the following strings, or undef. This method exists |
216 | 217 | solely for compatibility with the HTTP::Headers::UserAgent module. |
217 | 218 | |
218 | Win95, Win98, WinNT, Win2K, WinXP, Win2k3, WinVista, Win7, Mac, Mac OS X, iOS, | |
219 | Win3x, OS2, Unix, Linux, Playstation 3 GameOS, Playstation Portable GameOS | |
219 | Win95, Win98, WinNT, Win2K, WinXP, Win2k3, WinVista, Win7, Windows Phone, | |
220 | Mac, Mac OS X, iOS, Win3x, OS2, Unix, Linux, Playstation 3 GameOS, | |
221 | Playstation Portable GameOS | |
220 | 222 | |
221 | 223 | Detecting Browser Vendor |
222 | 224 | The following methods are available, each returning a true or false |
4 | 4 | license = Perl_5 |
5 | 5 | copyright_holder = Lee Semel |
6 | 6 | copyright_year = 2011 |
7 | version = 1.30 | |
7 | version = 1.31 | |
8 | 8 | main_module = lib/HTTP/BrowserDetect.pm |
9 | 9 | |
10 | 10 | [GatherDir] |
0 | 0 | use strict; |
1 | 1 | package HTTP::BrowserDetect; |
2 | 2 | { |
3 | $HTTP::BrowserDetect::VERSION = '1.30'; | |
3 | $HTTP::BrowserDetect::VERSION = '1.31'; | |
4 | 4 | } |
5 | 5 | |
6 | 6 | use vars qw(@ISA @EXPORT @EXPORT_OK @ALL_TESTS); |
29 | 29 | freebsd bsd vms |
30 | 30 | x11 amiga android |
31 | 31 | win7 ps3gameos pspgameos |
32 | wince ios | |
32 | wince ios winphone | |
33 | 33 | ); |
34 | 34 | |
35 | 35 | push @ALL_TESTS, @os; |
565 | 565 | $tests->{WIN7} = ( index( $ua, "nt 6.1" ) != -1 ); |
566 | 566 | $tests->{DOTNET} = ( index( $ua, ".net clr" ) != -1 ); |
567 | 567 | |
568 | $tests->{WINCE} = ( index( $ua, "windows ce" ) != -1 ); | |
568 | $tests->{WINCE} = ( index( $ua, "windows ce" ) != -1 ); | |
569 | $tests->{WINPHONE} = ( index( $ua, "windows phone os" ) != -1 ); | |
569 | 570 | |
570 | 571 | $tests->{WINME} = ( index( $ua, "win 9x 4.90" ) != -1 ); # whatever |
571 | 572 | $tests->{WIN32} = ( |
595 | 596 | || $tests->{WIN7} |
596 | 597 | || $tests->{WINME} |
597 | 598 | || $tests->{WINCE} |
599 | || $tests->{WINPHONE} | |
598 | 600 | ) |
599 | 601 | || index( $ua, "win" ) != -1 |
600 | 602 | ); |
707 | 709 | $major = shift @version; |
708 | 710 | $minor = shift @version; |
709 | 711 | } |
712 | } | |
713 | ||
714 | # Device from UA | |
715 | ||
716 | $self->{device_name} = undef; | |
717 | ||
718 | if ( $ua =~ /windows phone os [^\)]+ iemobile\/[^;]+; ([^;]+; [^;\)]+)/g ) { | |
719 | $self->{device_name} = substr $self->{user_agent}, pos($ua) - length $1, length $1; | |
720 | $self->{device_name} =~ s/; / /; | |
710 | 721 | } |
711 | 722 | |
712 | 723 | $self->{major} = $major; |
754 | 765 | $os_string = 'Win2k3' if $self->win2k3; |
755 | 766 | $os_string = 'WinVista' if $self->winvista; |
756 | 767 | $os_string = 'Win7' if $self->win7; |
768 | $os_string = 'Windows Phone' if $self->winphone; | |
757 | 769 | $os_string = 'Mac' if $self->mac; |
758 | 770 | $os_string = 'Mac OS X' if $self->macosx; |
759 | 771 | $os_string = 'Win3x' if $self->win3x; |
1027 | 1039 | |
1028 | 1040 | my ( $self, $check ) = _self_or_default( @_ ); |
1029 | 1041 | |
1042 | return $self->{device_name} if defined $self->{device_name}; | |
1043 | ||
1030 | 1044 | my %device_name = ( |
1031 | 1045 | blackberry => 'BlackBerry', |
1032 | 1046 | iphone => 'iPhone', |
1115 | 1129 | |
1116 | 1130 | =head1 VERSION |
1117 | 1131 | |
1118 | version 1.30 | |
1132 | version 1.31 | |
1119 | 1133 | |
1120 | 1134 | =head1 SYNOPSIS |
1121 | 1135 | |
1209 | 1223 | Returns a human formatted version of the hardware device name. These names |
1210 | 1224 | are subject to change and are really meant for display purposes. You should |
1211 | 1225 | use the device() method in your logic. Returns one of: BlackBerry, iPhone, |
1212 | iPod or iPad. Returns UNDEF if no hardware can be detected. | |
1226 | iPod or iPad or device name found in user agent string. Returns C<undef> if | |
1227 | no hardware can be detected. | |
1213 | 1228 | |
1214 | 1229 | =head2 browser_properties() |
1215 | 1230 | |
1321 | 1336 | winnt |
1322 | 1337 | win2k winxp win2k3 winvista win7 |
1323 | 1338 | wince |
1339 | winphone | |
1324 | 1340 | |
1325 | 1341 | =head2 dotnet() |
1326 | 1342 | |
1353 | 1369 | Returns one of the following strings, or undef. This method exists solely for |
1354 | 1370 | compatibility with the L<HTTP::Headers::UserAgent> module. |
1355 | 1371 | |
1356 | Win95, Win98, WinNT, Win2K, WinXP, Win2k3, WinVista, Win7, Mac, Mac OS X, iOS, | |
1357 | Win3x, OS2, Unix, Linux, Playstation 3 GameOS, Playstation Portable GameOS | |
1372 | Win95, Win98, WinNT, Win2K, WinXP, Win2k3, WinVista, Win7, Windows Phone, | |
1373 | Mac, Mac OS X, iOS, Win3x, OS2, Unix, Linux, Playstation 3 GameOS, | |
1374 | Playstation Portable GameOS | |
1358 | 1375 | |
1359 | 1376 | =head1 Detecting Browser Vendor |
1360 | 1377 |
30 | 30 | my $detected = HTTP::BrowserDetect->new( $ua ); |
31 | 31 | diag( $detected->user_agent ); |
32 | 32 | |
33 | foreach my $method ( 'browser_string', 'engine_string', ) { | |
33 | foreach my $method ( 'browser_string', 'engine_string', 'os_string' ) { | |
34 | 34 | if ( $test->{$method} ) { |
35 | 35 | cmp_ok( $detected->$method, 'eq', $test->{$method}, |
36 | 36 | "$method: $test->{$method}" ); |
2696 | 2696 | "winnt", |
2697 | 2697 | "winxp" |
2698 | 2698 | ] |
2699 | }, | |
2700 | "Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; HTC; T7575)" : { | |
2701 | "browser_string" : "MSIE", | |
2702 | "language" : null, | |
2703 | "match" : [ | |
2704 | "windows", | |
2705 | "winphone", | |
2706 | "mobile", | |
2707 | "ie", | |
2708 | "ie4up", | |
2709 | "ie55up", | |
2710 | "ie5up", | |
2711 | "ie7" | |
2712 | ], | |
2713 | "os" : "WinPhone", | |
2714 | "os_string" : "Windows Phone", | |
2715 | "device_name" : "HTC T7575" | |
2716 | }, | |
2717 | "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; T7575)" : { | |
2718 | "browser_string": "MSIE", | |
2719 | "language": null, | |
2720 | "match" : [ | |
2721 | "windows", | |
2722 | "winphone", | |
2723 | "mobile", | |
2724 | "ie", | |
2725 | "ie4up", | |
2726 | "ie55up", | |
2727 | "ie5up", | |
2728 | "ie9" | |
2729 | ], | |
2730 | "os" : "WinPhone", | |
2731 | "os_string" : "Windows Phone", | |
2732 | "device_name" : "HTC T7575" | |
2699 | 2733 | } |
2700 | 2734 | } |
2701 | 2735 |