Parse:...rAgent(3pm)
π Parse::HTTP::UserAgent β the parser for the User Agent string π
okay bestie, welcome to Parse:...rAgent(3pm), aka the Parse::HTTP::UserAgent page from the User Contributed Perl Documentation. it's giving vintage, it's giving deprecated-but-iconic, and yes we're gonna read the whole thing together. π«Ά
β¨ VERSION β¨
version 0.43 β that's the one, that's the number, no cap. π
β¨ SYNOPSIS β¨
here's the vibe in code form, bestie:
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;
that's it. that's the whole flex. π
β¨ DESCRIPTION β¨
so first things first, the module quotes <http://www.webaim.org/blog/user-agent-string-history/>, and honestly? this quote is the moment. it's the whole entire lore:
" ... 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."
not everyone pretending to be everyone else π the DRAMA.
so here's the tea: user agent strings are a complete mess because there is no standard format for them. literally none. 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's not dependable, because it's just some arbitrary identification string. any user agent can fake another. so why even deal with such a useless mess?? valid question, bestie, and here's the answer: 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 you just want to send an "HttpOnly" cookie if the user agent seems to support it (and send a normal one if this is not the case). iconic reasons, honestly. HOWEVER β browser sniffing for client-side coding is considered a bad habit. so don't do that one. π«
this module implements a rules-based parser and tries to identify MSIE, FireFox, Opera, Safari & Chrome first. it then tries to identify Mozilla, Netscape, Robots and the rest will be tried with a generic parser. there's also a structure dumper, useful for debugging. cute, functional, multitasking β main character energy fr fr. π
β¨ DEPRECATION NOTICE β¨
this module is DEPRECATED. please use HTTP::BrowserDetect instead. that's not a drill, bestie, that's a straight-up "we've moved on" text. π
β¨ METHODS β¨
π new STRING [, OPTIONS ]
constructor! takes the user agent string as the first parameter and returns an object based on the parsed structure.
the optional OPTIONS parameter (must be a hashref) can be used to pass several parameters:
"extended"β controls if the extended probe will be used or not. default is true. set this to false to disable:
$ua = Parse::HTTP::UserAgent->new( $str, { extended => 0 } );
can be used to speed up the parser by disabling detection of non-major browsers, robots and most mobile agents. so like, speedrun mode. β‘
π trim STRING
trims the string. short king behavior. βοΈ
π as_hash
returns a hash representation of the parsed structure.
π dumper
see Parse::HTTP::UserAgent::Base::Dumper.
π accessors
see Parse::HTTP::UserAgent::Base::Accessors for the available accessors you can use on the parsed object.
β¨ OVERLOADED INTERFACE β¨
the object returned overloads stringification ("name") and numification ("version") operators. so you can write this:
print 42 if $ua eq 'Opera' && $ua >= 9;
instead of this:
print 42 if $ua->name eq 'Opera' && $ua->version >= 9;
shorter code, same facts, absolutely slay. β¨
β¨ ERROR HANDLING β¨
- if you pass a false value to the constructor, it'll croak. π
- if you pass a non-hashref option to the constructor, it'll croak. π
- if you pass a wrong parameter to the
dumper, it'll croak. π
three croaks, zero mercy. the module does not play. πΈ
β¨ SEE ALSO β¨
this module is DEPRECATED. please use HTTP::BrowserDetect instead. (yes, again. it's serious, bestie.)
πΈ Similar Functionality
HTML::ParseBrowserHTTP::BrowserDetectHTTP::DetectUserAgentHTTP::MobileAgentMobile::UserAgent
πΈ Resources
- <http://en.wikipedia.org/wiki/User_agent>
- <http://www.zytrax.com/tech/web/browser_ids.htm>
- <http://www.zytrax.com/tech/web/mobile_ids.html>
- <http://www.webaim.org/blog/user-agent-string-history/>
- <https://developer.mozilla.org/en/Gecko_user_agent_string_reference>
- <http://www.useragentstring.com>
πΈ Module Reviews
- CPAN modules for parsing User-Agent strings by Neil Bowers: <http://blogs.perl.org/users/neilb/2011/10/cpan-modules-for-parsing-user-agent-strings.html> (23 October 2011).
- Parse::HTTP::UserAgent: yet another user agent string parser by Burak Gursoy: <http://use.perl.org/~Burak/journal/39577> (4 September 2009).
β¨ AUTHOR β¨
Burak Gursoy π
β¨ COPYRIGHT AND LICENSE β¨
this software is copyright (c) 2009 by Burak Gursoy.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. π«Ά
okay that's the whole page, bestie!! thanks for reading, you ate that. π β¨
and for the cute sign-off: this was Parse:...rAgent(3pm) as shipped with perl v5.40.1, dated 2025-05-16. bye babes, go parse something responsibly π¦π
π¦ where this page comes from
- debian trixie: libparse-http-useragent-perl 0.43-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libparse-http-useragent-perl 0.43-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libparse-http-useragent-perl 0.43-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms