HTTP::UserAgentStringParser - User-Agent string parser


 my $p = HTTP::UserAgentString::Parser->new();
 my $ua = $p->parse("Opera/9.80 (X11; Linux x86_64; U; en) Presto/2.9.168 Version/11.50");

 if ($ua->isRobot) {
        print "It's a robot: ", $ua->name, "\n";
 } else {
        print "It's a browser: ", $ua->name, " - version: ", $ua->version, "\n";


HTTP::UserAgentString::Parser is a Perl API for It can be used to parse user agent strings and determine whether the agent is a robot, a normal browser, mobile browser, e-mail client. It can also tell browser version, company that makes it, home page URL. In most of the cases it can also tell in which OS the browser is running.

HTTP::UserAgentString::Parser will download the .ini file provided by which contains all the information to do the parsing. The file will be cached by default for 7 days. After that time, it will check whether a new version was released. The default cache time can be modified, as well as the cache path (default is /tmp). A cache reload can also be forced.

In order to parse a string, a parse() method is provided which returns an object of classes HTTP::UserAgentString::Browser or HTTP::UserAgentString::Robot. Both classes have accesors to determine agent capabilities. In case the string does not match any known browser or robot, undef() is returned.


$p = HTTP::UserAgentString::Parser->new(%opts)

Valid options are:

 cache_max_age: in seconds (default is 7 days)
 cache_dir: path must be writeable - default is /tmp
 parse_cache_size: size of parsing cache in number of elements.  Default is 100_000


$agent = $p->parse($string)

Parses a User-Agent string and returns a HTTP::UserAgentString::Browser or HTTP::UserAgentString::Robot object, or undef() if no matches where found.


Updates the cache file from If force is false or undef(), the check is only executed if the cache file has expired. If force is true, the method checks whether there is a new file and downloads it accordingly.


Retrieves the current database version from Returns the version number or undef() if an error occurs.


Returns the version of the cached .ini file, or undef() if there is no cached file.


Local path to the cached .ini file.


Local path to file that contains the version of the cached .ini file.


See HTTP::UserAgentString::Browser and HTTP::UserAgentString::Robot for description of the objects returned by parse().


 Copyright (c) 2011 Nicolas Moldavsky (
 This is free software. You can redistribute it or modify it under the terms of the
 Perl license