NAME
HTTP::UserAgentStringParser - User-Agent string parser
SYNOPSIS
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";
}
DESCRIPTION
HTTP::UserAgentString::Parser
is a Perl API for user-agent-string.info. 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 user-agent-string.info 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.
CONSTRUCTOR
$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
METHODS
- $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.
- $p->updateDB($force)
-
Updates the cache file from user-agent-string.info. 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.
- $p->getCurrentVersion()
-
Retrieves the current database version from user-agent-string.info. Returns the version number or undef() if an error occurs.
- $p->getCachedVersion()
-
Returns the version of the cached .ini file, or undef() if there is no cached file.
- $p->cache_file()
-
Local path to the cached .ini file.
- $p->version_file()
-
Local path to file that contains the version of the cached .ini file.
SEE ALSO
See HTTP::UserAgentString::Browser and HTTP::UserAgentString::Robot for description of the objects returned by parse().
COPYRIGHT
Copyright (c) 2011 Nicolas Moldavsky (http://www.e-planning.net/)
This is free software. You can redistribute it or modify it under the terms of the
Perl license