Codebase list libhttp-browserdetect-perl / d4c6d84
Imported Upstream version 1.31 Angel Abad 12 years ago
9 changed file(s) with 73 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
2626 "Olaf Alders <olaf\@wundercounter.com> (current maintainer)"
2727 ],
2828 "dist_name" => "HTTP-BrowserDetect",
29 "dist_version" => "1.30",
29 "dist_version" => "1.31",
3030 "license" => "perl",
3131 "module_name" => "HTTP::BrowserDetect",
3232 "recommends" => {},
00 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)
14
25 1.30 2011-09-15
36 - Tweaks language regexes to reduce false positives
5757 "web" : "http://github.com/oalders/http-browserdetect"
5858 }
5959 },
60 "version" : "1.30"
60 "version" : "1.31"
6161 }
6262
3333 "strict" => 0,
3434 "vars" => 0
3535 },
36 "VERSION" => "1.30",
36 "VERSION" => "1.31",
3737 "test" => {
3838 "TESTS" => "t/*.t"
3939 }
22 an HTTP user agent string
33
44 VERSION
5 version 1.30
5 version 1.31
66
77 SYNOPSIS
88 use HTTP::BrowserDetect;
9191 Returns a human formatted version of the hardware device name. These
9292 names are subject to change and are really meant for display purposes.
9393 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.
9696
9797 browser_properties()
9898 Returns a list of the browser properties, that is, all of the tests that
192192 winnt
193193 win2k winxp win2k3 winvista win7
194194 wince
195 winphone
195196
196197 dotnet()
197198 mac()
215216 Returns one of the following strings, or undef. This method exists
216217 solely for compatibility with the HTTP::Headers::UserAgent module.
217218
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
220222
221223 Detecting Browser Vendor
222224 The following methods are available, each returning a true or false
44 license = Perl_5
55 copyright_holder = Lee Semel
66 copyright_year = 2011
7 version = 1.30
7 version = 1.31
88 main_module = lib/HTTP/BrowserDetect.pm
99
1010 [GatherDir]
00 use strict;
11 package HTTP::BrowserDetect;
22 {
3 $HTTP::BrowserDetect::VERSION = '1.30';
3 $HTTP::BrowserDetect::VERSION = '1.31';
44 }
55
66 use vars qw(@ISA @EXPORT @EXPORT_OK @ALL_TESTS);
2929 freebsd bsd vms
3030 x11 amiga android
3131 win7 ps3gameos pspgameos
32 wince ios
32 wince ios winphone
3333 );
3434
3535 push @ALL_TESTS, @os;
565565 $tests->{WIN7} = ( index( $ua, "nt 6.1" ) != -1 );
566566 $tests->{DOTNET} = ( index( $ua, ".net clr" ) != -1 );
567567
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 );
569570
570571 $tests->{WINME} = ( index( $ua, "win 9x 4.90" ) != -1 ); # whatever
571572 $tests->{WIN32} = (
595596 || $tests->{WIN7}
596597 || $tests->{WINME}
597598 || $tests->{WINCE}
599 || $tests->{WINPHONE}
598600 )
599601 || index( $ua, "win" ) != -1
600602 );
707709 $major = shift @version;
708710 $minor = shift @version;
709711 }
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/; / /;
710721 }
711722
712723 $self->{major} = $major;
754765 $os_string = 'Win2k3' if $self->win2k3;
755766 $os_string = 'WinVista' if $self->winvista;
756767 $os_string = 'Win7' if $self->win7;
768 $os_string = 'Windows Phone' if $self->winphone;
757769 $os_string = 'Mac' if $self->mac;
758770 $os_string = 'Mac OS X' if $self->macosx;
759771 $os_string = 'Win3x' if $self->win3x;
10271039
10281040 my ( $self, $check ) = _self_or_default( @_ );
10291041
1042 return $self->{device_name} if defined $self->{device_name};
1043
10301044 my %device_name = (
10311045 blackberry => 'BlackBerry',
10321046 iphone => 'iPhone',
11151129
11161130 =head1 VERSION
11171131
1118 version 1.30
1132 version 1.31
11191133
11201134 =head1 SYNOPSIS
11211135
12091223 Returns a human formatted version of the hardware device name. These names
12101224 are subject to change and are really meant for display purposes. You should
12111225 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.
12131228
12141229 =head2 browser_properties()
12151230
13211336 winnt
13221337 win2k winxp win2k3 winvista win7
13231338 wince
1339 winphone
13241340
13251341 =head2 dotnet()
13261342
13531369 Returns one of the following strings, or undef. This method exists solely for
13541370 compatibility with the L<HTTP::Headers::UserAgent> module.
13551371
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
13581375
13591376 =head1 Detecting Browser Vendor
13601377
3030 my $detected = HTTP::BrowserDetect->new( $ua );
3131 diag( $detected->user_agent );
3232
33 foreach my $method ( 'browser_string', 'engine_string', ) {
33 foreach my $method ( 'browser_string', 'engine_string', 'os_string' ) {
3434 if ( $test->{$method} ) {
3535 cmp_ok( $detected->$method, 'eq', $test->{$method},
3636 "$method: $test->{$method}" );
26962696 "winnt",
26972697 "winxp"
26982698 ]
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"
26992733 }
27002734 }
27012735