Duadua - Detect User-Agent, do up again!
use Duadua; my $ua = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'; my $d = Duadua->new($ua); $d->is_bot and say $d->name; # Googlebot
Or call as a function to parse immediately
my $d = Duadua->parse($ua); $d->is_bot and say $d->name; # Googlebot
And it's able to accept an object like HTTP::Headers instead of user-agent string.
use HTTP::Headers; use Duadua; my $headers = HTTP::Headers->new( 'User_Agent' => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)' ); my $d = Duadua->new($headers); $d->is_bot and say $d->name; # Googlebot
NOTE that an object class should be HTTP::Headers[::*], and it should have a method `header` to get specific HTTP-Header.
If you would like to parse many times, then you can use reparse method. It's fast.
reparse
my $d = Duadua->new; for my $ua (@ua_list) { my $result = $d->reparse($ua); $result->is_bot and say $result->name; }
If you need to get version info, then you should set true value to version option like below.
use Duadua; my $ua = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'; my $d = Duadua->new($ua, { version => 1 }); say $d->version; # 2.1
Duadua is a User-Agent detector.
constructor
If you set the true value to version, then you can get version string. (By default, don't get version)
version
If you set the array to skip, then you can skip detect logic by specific classes.
skip
NOTE that ParserClass is case sensitive, and it might be going to change results.
Parses User-Agent string
Parses User-Agent string by same instance without new
Returns raw User-Agent string
Gets User-Agent name
Returns true value if the User-Agent is bot.
Returns true value if the User-Agent is iOS.
Returns true value if the User-Agent is Android.
Returns true value if the User-Agent is Linux.
Returns true value if the User-Agent is Windows.
Returns true value if the User-Agent is ChromeOS.
Returns version option value. If it's true value, then parse to get User Agent version also.
Returns version from user agent string
The list of User Agent Parser
Duadua is hosted on github: http://github.com/bayashi/Duadua
I appreciate any feedback :D
Dai Okabayashi <bayashi@cpan.org>
Duadua is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. (Note that, unlike the Artistic License 1.0, version 2.0 is GPL compatible by itself, hence there is no benefit to having an Artistic 2.0 / GPL disjunction.) See the file LICENSE for details.
Duadua
To install Duadua, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Duadua
CPAN shell
perl -MCPAN -e shell install Duadua
For more information on module installation, please visit the detailed CPAN module installation guide.