| 1 | package HTTP::UserAgentString::Browser; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | HTTP::UserAgentString::Browser - Web browser | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | $browser = $p->parse($string) | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | print "This is a ", ($browser->isRobot()) ? "robot" : "browser", "\n"; | ||||||||||||||||||||||||||||
| 12 | print "Name: ", $browser->name(), "\n"; | ||||||||||||||||||||||||||||
| 13 | print "Version: ", $browser->version(), "\n"; | ||||||||||||||||||||||||||||
| 14 | print "URL: ", $browser->url(), "\n"; | ||||||||||||||||||||||||||||
| 15 | print "Company: ", $browser->company(), "\n"; | ||||||||||||||||||||||||||||
| 16 | print "Company URL: ", $browser->company_url(), "\n"; | ||||||||||||||||||||||||||||
| 17 | print "Info URL: ", $browser->info_url(), "\n"; | ||||||||||||||||||||||||||||
| 18 | print "Type: ", $browser->type(), "\n"; | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | $os = $browser->os(); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | Used to represent web browsers returned by L<HTTP::UserAgentString::Parser>. Object is read | ||||||||||||||||||||||||||||
| 25 | only. Accesors are provided for all capabilities defined by | ||||||||||||||||||||||||||||
| 26 | user-agent-string.info | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =head1 METHODS | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =over 4 | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =item $browser->name() | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | Browser name. Example: "Firefox" | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =item $browser->version() | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | String version. Example: "3.5" | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =item $browser->url() | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | Web page for the browser | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =item $browser->company() | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | Name of the company that develops the browser | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =item $browser->company_url() | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | URL of the company that develops the browser | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =item $browser->ico() | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | PNG icon for the browser that can be obtained from http://user-agent-string.info/pub/img/ua/ | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =item $browser->info_url() | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | Web page in http://user-agent-string.info/ that provides information on the browser | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =item $browser->type() | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Numeric type (see browser_type_id[] in the .ini file) | ||||||||||||||||||||||||||||
| 63 | More accessors are provided to check for type: | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =over 4 | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =item $browser->typeDesc() | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | String description for the browser's type. | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =item $browser->isBrowser() | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | Check for standard web browser | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =item $browser->isOffline() | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | Check for offline web browsers | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =item $browser->isMobile() | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | Check for mobile web browsers | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =item $browser->isEmail() | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | Check for e-mail clients | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =item $browser->isWAP() | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | Check for WAP browsers | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =item $browser->isLibrary() | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | Check for HTTP libraries | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =back | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =item $browser->os | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | If defined, L<HTTP::UserAgentString::OS> object representing the operating system | ||||||||||||||||||||||||||||
| 100 | where the browser is running. | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =back | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | L<HTTP::UserAgentString::OS> for the class representing operating systems, and | ||||||||||||||||||||||||||||
| 107 | L<HTTP::UserAgentString::Robot> for robots. | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | Copyright (c) 2011 Nicolas Moldavsky (http://www.e-planning.net/) | ||||||||||||||||||||||||||||
| 112 | This library is released under LGPL V3 | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =cut | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 117 | 4 | ▶ | use base qw(HTTP::UserAgentString::Sys); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 4 | my @KEYS = qw(type name url company company_url ico info_url); | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 4 | my $BROWSER = 0; | |||||||||||||||||||||||||||
| 122 | 4 | my $OFFLINE = 1; | |||||||||||||||||||||||||||
| 123 | 4 | my $MOBILE = 3; | |||||||||||||||||||||||||||
| 124 | 4 | my $EMAIL = 4; | |||||||||||||||||||||||||||
| 125 | 4 | my $LIBRARY = 5; | |||||||||||||||||||||||||||
| 126 | 4 | my $WAP = 6; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub new($$$;$$) { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 129 | 0 | my ($pkg, $data, $typeDesc, $version, $os) = @_; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | my $h = {}; | |||||||||||||||||||||||||||
| 132 | 0 | ▶ | for (my $i = 0; $i < scalar(@KEYS); $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 0 | my $val = $data->[$i]; | |||||||||||||||||||||||||||
| 134 | 0 | ▶ | if (defined($val) and (length($val) > 0)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $val and length $val > 0
MC/DC0%0/2
defined $val and length $val > 0
defined $val
length $val > 0
Truth table0%0/3
A and B
A= defined $valB= length $val > 0
| |||||||||||||||||||||||||||||
| 135 | 0 | $h->{$KEYS[$i]} = $val; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | 0 | $h->{os} = $os; | |||||||||||||||||||||||||||
| 139 | 0 | $h->{version} = $version; | |||||||||||||||||||||||||||
| 140 | 0 | ▶ | if (defined($version)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | my @v = split(/\./, $version); | |||||||||||||||||||||||||||
| 142 | 0 | ▶ | if (@v) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | $h->{major_version} = shift(@v); | |||||||||||||||||||||||||||
| 144 | 0 | ▶ | if (@v) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 0 | $h->{minor_version} = shift(@v); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | $h->{typeDesc} = $typeDesc; | |||||||||||||||||||||||||||
| 151 | 0 | return bless($h, $pkg); | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | ▶ | sub type($) { $_[0]->{type} } | ||||||||||||||||||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub info_url($) { $_[0]->{info_url} } | ||||||||||||||||||||||||||
|
Subroutine
info_url: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub os($) { $_[0]->{os} } | ||||||||||||||||||||||||||
|
Subroutine
os: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub version($) { $_[0]->{version} } | ||||||||||||||||||||||||||
|
Subroutine
version: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | sub major_version($) { $_[0]->{major_version} } | ||||||||||||||||||||||||||
|
Subroutine
major_version: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 159 | 0 | ▶ | sub minor_version($) { $_[0]->{minor_version} } | ||||||||||||||||||||||||||
|
Subroutine
minor_version: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub typeDesc($) { $_[0]->{typeDesc} } | ||||||||||||||||||||||||||
|
Subroutine
typeDesc: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | sub isRobot($) { 0 } | ||||||||||||||||||||||||||
|
Subroutine
isRobot: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub isBrowser($) { $BROWSER == $_[0]->type } | ||||||||||||||||||||||||||
|
Subroutine
isBrowser: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub isOffline($) { $OFFLINE == $_[0]->type } | ||||||||||||||||||||||||||
|
Subroutine
isOffline: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | sub isMobile($) { $MOBILE == $_[0]->type } | ||||||||||||||||||||||||||
|
Subroutine
isMobile: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 167 | 0 | ▶ | sub isEmail($) { $EMAIL == $_[0]->type } | ||||||||||||||||||||||||||
|
Subroutine
isEmail: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | sub isLibrary($) { $LIBRARY == $_[0]->type } | ||||||||||||||||||||||||||
|
Subroutine
isLibrary: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub isWAP($) { $WAP == $_[0]->type } | ||||||||||||||||||||||||||
|
Subroutine
isWAP: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 4 | 1; | |||||||||||||||||||||||||||