package HTTP::MobileAgent::DoCoMo; use strict; use vars qw($VERSION); $VERSION = 0.18; use base qw(HTTP::MobileAgent); __PACKAGE__->make_accessors( qw(version model status bandwidth serial_number is_foma card_id comment) ); use HTTP::MobileAgent::DoCoMoDisplayMap qw($DisplayMap); # various preferences use vars qw($DefaultCacheSize $HTMLVerMap $GPSModels); $DefaultCacheSize = 5; # http://www.nttdocomo.co.jp/p_s/imode/spec/useragent.html $HTMLVerMap = [ # regex => version qr/[DFNP]501i/ => '1.0', qr/502i|821i|209i|691i|(F|N|P|KO)210i|^F671i$/ => '2.0', qr/(D210i|SO210i)|503i|211i|SH251i|692i|200[12]|2101V/ => '3.0', qr/504i|251i|^F671iS$|^F661i$|212i|2051|2102V|2701/ => '4.0', qr/eggy|P751v/ => '3.2', qr/505i|252i/ => '5.0', ]; $GPSModels = { map { $_ => 1 } qw(F661i) }; sub is_docomo { 1 } sub parse { my $self = shift; my($main, $foma_or_comment) = split / /, $self->user_agent, 2; if ($foma_or_comment && $foma_or_comment =~ s/^\((.*)\)$/$1/) { # DoCoMo/1.0/P209is (Google CHTML Proxy/1.0) $self->{comment} = $1; $self->_parse_main($main); } elsif ($foma_or_comment) { # DoCoMo/2.0 N2001(c10;ser0123456789abcde;icc01234567890123456789) $self->{is_foma} = 1; @{$self}{qw(name version)} = split m!/!, $main; $self->_parse_foma($foma_or_comment); } else { # DoCoMo/1.0/R692i/c10 $self->_parse_main($main); } } sub _parse_main { my($self, $main) = @_; my($name, $version, $model, $cache, @rest) = split m!/!, $main; $self->{name} = $name; $self->{version} = $version; $self->{model} = $model; $self->{model} = 'SH505i' if $self->{model} eq 'SH505i2'; if ($cache) { $cache =~ s/^c// or return $self->no_match; $self->{cache_size} = $cache; } for (@rest) { /^ser(\w{11})$/ and do { $self->{serial_number} = $1; next }; /^(T[CDBJ])$/ and do { $self->{status} = $1; next }; /^s(\d+)$/ and do { $self->{bandwidth} = $1; next }; /^W(\d+)H(\d+)$/ and do { $self->{display_bytes} = "$1*$2"; next; }; } } sub _parse_foma { my($self, $foma) = @_; $foma =~ s/^([^\(]+)// or return $self->no_match; $self->{model} = $1; $self->{model} = 'SH2101V' if $1 eq 'MST_v_SH2101V'; # Huh? if ($foma =~ s/^\((.*?)\)$//) { my @options = split /;/, $1; for (@options) { /^c(\d+)$/ and $self->{cache_size} = $1, next; /^ser(\w{15})$/ and $self->{serial_number} = $1, next; /^icc(\w{20})$/ and $self->{card_id} = $1, next; /^(T[CDBJ])$/ and $self->{status} = $1, next; $self->no_match; } } } sub html_version { my $self = shift; my @map = @$HTMLVerMap; while (my($re, $version) = splice(@map, 0, 2)) { return $version if $self->model =~ /$re/; } return undef; } sub cache_size { my $self = shift; return $self->{cache_size} || $DefaultCacheSize; } sub series { my $self = shift; return 'FOMA' if $self->is_foma; my $model = $self->model; $model =~ /(\d{3}i)/; return $1; } sub vendor { my $self = shift; my $model = $self->model; $model =~ /^([A-Z]+)\d/; return $1; } sub _make_display { my $self = shift; my $display = $DisplayMap->{uc($self->model)}; if ($self->{display_bytes}) { my($w, $h) = split /\*/, $self->{display_bytes}; $display->{width_bytes} = $w; $display->{height_bytes} = $h; } return HTTP::MobileAgent::Display->new(%$display); } sub is_gps { my $self = shift; return exists $GPSModels->{$self->model}; } 1; __END__ =head1 NAME HTTP::MobileAgent::DoCoMo - NTT DoCoMo implementation =head1 SYNOPSIS use HTTP::MobileAgent; local $ENV{HTTP_USER_AGENT} = "DoCoMo/1.0/P502i/c10"; my $agent = HTTP::MobileAgent->new; printf "Name: %s\n", $agent->name; # "DoCoMo" printf "Ver: %s\n", $agent->version; # 1.0 printf "HTML ver: %s\n", $agent->html_version; # 2.0 printf "Model: %s\n", $agent->model; # "P502i" printf "Cache: %dk\n", $agent->cache_size; # 10 print "FOMA\n" if $agent->is_foma; # false printf "Vendor: %s\n", $agent->vendor; # 'P' printf "Series: %s\n", $agent->series; # "502i" # only available with