.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Parse::HTTP::UserAgent 3pm" .TH Parse::HTTP::UserAgent 3pm "2022-06-16" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Parse::HTTP::UserAgent \- Parser for the User Agent string .SH "VERSION" .IX Header "VERSION" version 0.42 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 8 \& use Parse::HTTP::UserAgent; \& my $ua = Parse::HTTP::UserAgent\->new( $str ); \& die "Unable to parse!" if $ua\->unknown; \& print $ua\->name; \& print $ua\->version; \& print $ua\->os; \& # or just dump for debugging: \& print $ua\->dumper; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Quoting : .PP .Vb 7 \& " ... and then Google built Chrome, and Chrome used Webkit, and it was like \& Safari, and wanted pages built for Safari, and so pretended to be Safari. \& And thus Chrome used WebKit, and pretended to be Safari, and WebKit pretended \& to be KHTML, and KHTML pretended to be Gecko, and all browsers pretended to \& be Mozilla, (...) , and the user agent string was a complete mess, and near \& useless, and everyone pretended to be everyone else, and confusion \& abounded." .Ve .PP User agent strings are a complete mess since there is no standard format for them. They can be in various formats and can include more or less information depending on the vendor's (or the user's) choice. Also, it is not dependable since it is some arbitrary identification string. Any user agent can fake another. So, why deal with such a useless mess? You may want to see the choice of your visitors and can get some reliable data (even if some are fake) and generate some nice charts out of them or just want to send an \f(CW\*(C`HttpOnly\*(C'\fR cookie if the user agent seems to support it (and send a normal one if this is not the case). However, browser sniffing for client-side coding is considered a bad habit. .PP This module implements a rules-based parser and tries to identify \&\s-1MSIE,\s0 FireFox, Opera, Safari & Chrome first. It then tries to identify Mozilla, Netscape, Robots and the rest will be tried with a generic parser. There is also a structure dumper, useful for debugging. .SH "METHODS" .IX Header "METHODS" .SS "new \s-1STRING\s0 [, \s-1OPTIONS\s0 ]" .IX Subsection "new STRING [, OPTIONS ]" Constructor. Takes the user agent string as the first parameter and returns an object based on the parsed structure. .PP The optional \f(CW\*(C`OPTIONS\*(C'\fR parameter (must be a hashref) can be used to pass several parameters: .IP "\(bu" 4 \&\f(CW\*(C`extended\*(C'\fR: controls if the extended probe will be used or not. Default is true. Set this to false to disable: .Sp .Vb 1 \& $ua = Parse::HTTP::UserAgent\->new( $str, { extended => 0 } ); .Ve .Sp Can be used to speed up the parser by disabling detection of non-major browsers, robots and most mobile agents. .SS "trim \s-1STRING\s0" .IX Subsection "trim STRING" Trims the string. .SS "as_hash" .IX Subsection "as_hash" Returns a hash representation of the parsed structure. .SS "dumper" .IX Subsection "dumper" See Parse::HTTP::UserAgent::Base::Dumper. .SS "accessors" .IX Subsection "accessors" See Parse::HTTP::UserAgent::Base::Accessors for the available accessors you can use on the parsed object. .SH "OVERLOADED INTERFACE" .IX Header "OVERLOADED INTERFACE" The object returned, overloads stringification (\f(CW\*(C`name\*(C'\fR) and numification (\f(CW\*(C`version\*(C'\fR) operators. So that you can write this: .PP .Vb 1 \& print 42 if $ua eq \*(AqOpera\*(Aq && $ua >= 9; .Ve .PP instead of this .PP .Vb 1 \& print 42 if $ua\->name eq \*(AqOpera\*(Aq && $ua\->version >= 9; .Ve .SH "ERROR HANDLING" .IX Header "ERROR HANDLING" .IP "\(bu" 4 If you pass a false value to the constructor, it'll croak. .IP "\(bu" 4 If you pass a non-hashref option to the constructor, it'll croak. .IP "\(bu" 4 If you pass a wrong parameter to the dumper, it'll croak. .SH "SEE ALSO" .IX Header "SEE ALSO" .SS "Similar Functionality" .IX Subsection "Similar Functionality" .IP "\(bu" 4 HTML::ParseBrowser .IP "\(bu" 4 HTTP::BrowserDetect .IP "\(bu" 4 HTTP::DetectUserAgent .IP "\(bu" 4 HTTP::MobileAgent .IP "\(bu" 4 Mobile::UserAgent .SS "Resources" .IX Subsection "Resources" .IP "\(bu" 4 .IP "\(bu" 4 .IP "\(bu" 4 .IP "\(bu" 4 .IP "\(bu" 4 .IP "\(bu" 4 .SS "Module Reviews" .IX Subsection "Module Reviews" .IP "\(bu" 4 \&\s-1CPAN\s0 modules for parsing User-Agent strings by \fBNeil Bowers\fR: (23 October 2011). .IP "\(bu" 4 Parse::HTTP::UserAgent: yet another user agent string parser by \fBBurak Gursoy\fR: (4 September 2009). .SH "AUTHOR" .IX Header "AUTHOR" Burak Gursoy .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2009 by Burak Gursoy. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.