1 package HTTP::Headers::UserAgent;
5 use HTTP::BrowserDetect;
7 use vars qw( $VERSION @EXPORT_OK $fh %old );
11 @EXPORT_OK = qw( GetPlatform );
32 HTTP::Headers::UserAgent - Class encapsulating the HTTP User-Agent header
36 use HTTP::Headers::UserAgent;
38 HTTP::Headers::UserAgent->DumpFile( $fh );
40 $user_agent = new HTTP::Headers::UserAgent $ENV{HTTP_USER_AGENT};
42 $user-agent->string( $ENV{HTTP_USER_AGENT} );
44 $string = $user_agent->string;
46 $platform = $user_agent->platform;
48 $os = $user_agent->os;
50 ( $browser, $version ) = $user_agent->browser;
52 #backwards-compatibility with HTTP::Headers::UserAgent 1.00
53 $old_platform = HTTP::Headers::UserAgent::GetPlatform $ENV{HTTP_USER_AGENT};
57 The HTTP::Headers::UserAgent class represents User-Agent HTTP headers.
59 This is version 3.00 of the HTTP::Headers::UserAgent class. It is now
60 B<depriciated>, and the code is a wrapper around the more well-maintained
61 HTTP::BrowserDetect module. You are advised to switch to HTTP::BrowswerDetect.
62 While the interface provides backward-compatibility with version 1.00, it is
63 not based on the 1.00 code.
71 No-op compatibility method.
79 =item new HTTP_USER_AGENT
81 Creates a new HTTP::Headers::UserAgent object. Takes the HTTP_USER_AGENT
82 string as a parameter.
88 my $class = ref($proto) || $proto;
89 my $self = { 'bd' => new HTTP::BrowserDetect(shift) };
90 bless( $self, $class);
94 =item string [ HTTP_USER_AGENT ]
96 If a parameter is given, sets the user-agent string.
98 Returns the user-agent as an unprocessed string.
104 $self->{'bd'}->user_agent(@_);
109 Tries to guess the platform. Returns ia32, ppc, alpha, hppa, mips, sparc, or
112 ia32 Intel archetecure, 32-bit (x86)
114 alpha DEC (now Compaq) Alpha
119 This is the only function which is not yet implemented as a wrapper around
120 an equivalent function in HTTP::BrowserDetect.
126 for ( $self->{'bd'}{'user_agent'} ) {
127 /Win/ && return "ia32";
128 /Mac/ && return "ppc";
129 /Linux.*86/ && return "ia32";
130 /Linux.*alpha/ && return "alpha";
131 /OSF/ && return "alpha";
132 /HP-UX/ && return "hppa";
133 /IRIX/ && return "mips";
134 /(SunOS|Solaris)/ && return "sparc";
136 print $fh $self->string if $fh;
142 Tries to guess the operating system. Returns irix, win16, win95, win98,
143 winnt, win32 (Windows 95/98/NT/?), macos, osf1, linux, solaris, sunos, bsdi,
146 This is now a wrapper around HTTP::BrowserDetect methods. Using
147 HTTP::BrowserDetect natively offers a better interface to OS detection and is
155 foreach my $possible ( qw(
156 win31 win95 win98 winnt win2k winme win32 win3x win16 windows
159 sun4 sun5 suni86 sun irix
163 $os ||= $possible if $self->{'bd'}->$possible();
165 $os = 'macos' if $os =~ /^mac/;
166 $os = 'osf1' if $os =~ /^dec/;
167 $os = 'solaris' if $os =~ /^sun(5$|i86$|$)/;
168 $os = 'sunos' if $os eq 'sun4';
169 $os = 'bsdi' if $os eq 'bsd';
175 Returns a list consisting of the browser name and version. Possible browser
178 Netscape, IE, Opera, Lynx, WebTV, AOL Browser, or Unknown
180 This is now a wrapper around HTTP::BrowserDetect::browser_string
186 my $browser = $self->{'bd'}->browser_string();
187 $browser = 'Unknown' unless defined $browser;
188 $browser = 'IE' if $browser eq 'MSIE';
194 =head1 BACKWARDS COMPATIBILITY
196 For backwards compatibility with HTTP::Headers::UserAgent 1.00, a GetPlatform
197 subroutine is provided.
201 =item GetPlatform HTTP_USER_AGENT
203 Returns Win95, Win98, WinNT, UNIX, MAC, Win3x, OS2, Linux, or undef.
205 In some cases ( `Win32', `Windows CE' ) where HTTP::Headers::UserAgent 1.00
206 would have returned `Win95', will return undef instead.
208 Will return `UNIX' for some cases where HTTP::Headers::UserAgent would have
215 my $object = new HTTP::Headers::UserAgent $string;
223 Ivan Kohler <ivan-useragent@420.am>
225 Portions of this software were originally taken from the Bugzilla Bug
226 Tracking system <http://www.mozilla.org/bugs/>, and are reused here with
227 permission of the original author, Terry Weissman <terry@mozilla.org>.
231 Copyright (c) 2001 Ivan Kohler. All rights reserved.
232 This program is free software; you can redistribute it and/or modify it
233 under the same terms as Perl itself.
237 Really you should just switch over to the more well-maintained
238 HTTP::BrowserDetect, which this module is now just a wrapper around.
242 perl(1), L<HTTP::Headers>, L<HTTP::BrowserDetect>