HTTP::MobileAgent - HTTP mobile user agent string parser
use HTTP::MobileAgent; my $agent = HTTP::MobileAgent->new(Apache->request); # or $agent = HTTP::MobileAgent->new; to get from %ENV # or $agent = HTTP::MobileAgent->new($agent_string); if ($agent->is_docomo) { # or if ($agent->name eq 'DoCoMo') # or if ($agent->isa('HTTP::MobileAgent::DoCoMo')) # it's NTT DoCoMo i-mode. # see what's available in H::MA::DoCoMo } elsif ($agent->is_j_phone) { # it's J-Phone. # see what's available in H::MA::JPhone } elsif ($agent->is_ezweb) { # it's KDDI/EZWeb. # see what's available in H::MA::EZweb } else { # may be PC # $agent is H::MA::NonMobile } my $display = $agent->display; # HTTP::MobileAgent::Display if ($display->color) { ... }
HTTP::MobileAgent parses HTTP_USER_AGENT strings of (mainly Japanese) mobile HTTP user agents. It'll be useful in page dispatching by user agents.
Here are common methods of HTTP::MobileAgent subclasses. More agent specific methods are described in each subclasses. Note that some of common methods are also overrided in some subclasses.
$agent = HTTP::MobileAgent->new; $agent = HTTP::MobileAgent->new($r); # Apache or HTTP::Request $agent = HTTP::MobileAgent->new($ua_string);
parses HTTP headers and constructs HTTP::MobileAgent subclass instance. If no argument is supplied, $ENV{HTTP_*} is used.
Note that you nees to pass Aapche or HTTP::Requet object to new(), as some mobile agents put useful information on HTTP headers other than only User-Agent: (like x-jphone-msname in J-Phone).
User-Agent:
x-jphone-msname
print "User-Agent: ", $agent->user_agent;
returns User-Agent string.
print "name: ", $agent->name;
returns User-Agent name like 'DoCoMo'.
if ($agent->is_docomo) { }
returns if the agent is DoCoMo, J-Phone or EZweb.
my $display = $agent->display;
returns HTTP::MobileAgent::Display object. See HTTP::MobileAgent::Display for details.
Following warnings might be raised when $^W is on.
$^W
User-Agent: string does not match patterns provided in subclasses. It may be faked user-agent or a new variant. Feel free to mail me to inform this.
Yep, I tried to do. But the module's code seems hard enough for me to extend and don't want to bother the author for this mobile-specific features. So I made this module as a separated one.
If you have any idea / request for this module to add new subclass, I'm open to the discussion or (more preferable) patches. Feel free to mail me.
This module is now ported to PHP as Net::UserAgent::Mobile by Atsuhiro KUBO. See http://pear.php.net/package-info.php?pacid=180 for details.
Tatsuhiko Miyagawa <miyagawa@bulknews.net>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
HTTP::MobileAgent::DoCoMo, HTTP::MobileAgent::JPhone, HTTP::MobileAgent::EZweb, HTTP::MobileAgent::NonMobile, HTTP::MobileAgent::Display, HTTP::BrowserDetect
Reference URL for specification is listed in Pods for each subclass.
To install HTTP::MobileAgent, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::MobileAgent
CPAN shell
perl -MCPAN -e shell install HTTP::MobileAgent
For more information on module installation, please visit the detailed CPAN module installation guide.