Show
Ignore:
Timestamp:
01/07/08 23:35:18 (6 years ago)
Author:
tokuhirom
Message:

H::MA::Plugin-Charset: implemented.

Location:
lang/perl/HTTP-MobileAgent-Plugin-Charset/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/HTTP-MobileAgent-Plugin-Charset/trunk/lib/HTTP/MobileAgent/Plugin/Charset.pm

    r4175 r4189  
    44our $VERSION = '0.01'; 
    55 
    6 # ------------------------------------------------------------------------- 
    7 # docomo 
    8 sub HTTP::MobileAgent::DoCoMo::encoding { 
    9     my $self = shift; 
    10     $self->can_display_utf8 ? 'x-utf8-docomo' : 'x-sjis-docomo'; 
    11 } 
    12 # http://www.nttdocomo.co.jp/service/imode/make/content/xhtml/about/ 
    13 sub HTTP::MobileAgent::DoCoMo::can_display_utf8 { 
     6sub HTTP::MobileAgent::can_display_utf8 { 
    147    my $self = shift; 
    158    $self->xhtml_compliant; 
    169} 
     10sub HTTP::MobileAgent::AirHPhone::can_display_utf8 { 
     11    my $self = shift; 
     12    $self->get_header('Accept-Charset') =~ /utf-?8/i ? 1 : 0; 
     13} 
    1714 
    18 # ------------------------------------------------------------------------- 
    19 # non-mobile 
    20 sub HTTP::MobileAgent::NonMobile::encoding { 'utf8' } 
    21 sub HTTP::MobileAgent::NonMobile::can_display_utf8 { 1 } 
     15sub HTTP::MobileAgent::encoding { 
     16    my $self = shift; 
     17    if ($self->is_non_mobile) { 
     18        return 'utf-8'; 
     19    } else { 
     20        my $charset = $self->can_display_utf8 ? 'utf8' : 'sjis'; 
     21        return join '-', 'x', $charset, lc($self->carrier_longname); 
     22    } 
     23} 
    2224 
    23251; 
    2426__END__ 
     27 
     28=encoding utf8 
    2529 
    2630=for stopwords aaaatttt dotottto gmail 
     
    3741  my $agent = HTTP::MobileAgent->new; 
    3842  $agent->can_display_utf8; # => 1 or 0 
    39   decode($agent->encoding, $r->param('body')); 
     43  encode($agent->encoding, "\x{223e}"); 
    4044 
    4145=head1 DESCRIPTION 
     
    5357L<HTTP::MobileAgent>, L<Encode::JP::Mobile> 
    5458 
     59L<http://www.au.kddi.com/ezfactory/tec/spec/wap_rule.html> 
     60L<http://www.nttdocomo.co.jp/service/imode/make/content/xhtml/about/> 
     61 
    5562=head1 LICENSE 
    5663 
  • lang/perl/HTTP-MobileAgent-Plugin-Charset/trunk/t/01_can_display_utf8.t

    r4175 r4189  
    1717 
    1818    local $ENV{HTTP_USER_AGENT} = $ua; 
     19    local $ENV{HTTP_ACCEPT_CHARSET}; 
     20    if ($ua =~ /DDIPOCKET/) { 
     21        $ENV{HTTP_ACCEPT_CHARSET} = 
     22          ( $ua =~ /K3001V/ ) 
     23          ? 'shift_jis, utf-8, utf-16, iso-8859-1;q=0.6, *;q=0.1' 
     24          : 'shift_jis; q=0.6, *;q=0.1'; 
     25    } 
    1926    my $agent = HTTP::MobileAgent->new; 
    2027    $agent->can_display_utf8 ? 'utf8' : 'no utf8'; 
     
    3542--- expected: no utf8 
    3643 
     44===  
     45--- input: Vodafone/1.0/V802SE/SEJ001/SNXXXXXXXXX Browser/SEMC-Browser/4.1 Profile/MIDP-2.0 Configuration/CLDC-1.10 
     46--- expected: utf8 
     47 
     48=== 
     49--- input: J-PHONE/2.0/J-DN02 
     50--- expected: no utf8 
     51 
     52=== willcom 
     53--- input: Mozilla/3.0(DDIPOCKET;JRC/AH-J3001V,AH-J3002V/1.0/0100/c50)CNF/2.0 
     54--- expected: no utf8 
     55 
     56=== willcom 
     57--- input: Mozilla/3.0(DDIPOCKET;KYOCERA/AH-K3001V/1.4.1.67.000000/0.1/C100) Opera 7.0 
     58--- expected: utf8 
     59 
     60=== ez 
     61--- input: UP.Browser/3.01-HI01 UP.Link/3.4.5.2 
     62--- expected: no utf8 
     63 
     64=== ez 
     65--- input: KDDI-TS21 UP.Browser/6.0.2.276 (GUI) MMP/1.1 
     66--- expected: utf8 
     67 
  • lang/perl/HTTP-MobileAgent-Plugin-Charset/trunk/t/02_encoding.t

    r4175 r4189  
    1717 
    1818    local $ENV{HTTP_USER_AGENT} = $ua; 
     19    local $ENV{HTTP_ACCEPT_CHARSET}; 
     20    if ($ua =~ /DDIPOCKET/) { 
     21        $ENV{HTTP_ACCEPT_CHARSET} = 
     22          ( $ua =~ /K3001V/ ) 
     23          ? 'shift_jis, utf-8, utf-16, iso-8859-1;q=0.6, *;q=0.1' 
     24          : 'shift_jis; q=0.6, *;q=0.1'; 
     25    } 
    1926    my $agent = HTTP::MobileAgent->new; 
    2027    $agent->encoding; 
     
    2532=== 
    2633--- input: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.8) Gecko/20071019 Firefox/2.0.0.8 
    27 --- expected: utf8 
     34--- expected: utf-8 
    2835 
    2936=== docomo foma 
     
    3542--- expected: x-sjis-docomo 
    3643 
     44===  
     45--- input: Vodafone/1.0/V802SE/SEJ001/SNXXXXXXXXX Browser/SEMC-Browser/4.1 Profile/MIDP-2.0 Configuration/CLDC-1.10 
     46--- expected: x-utf8-vodafone 
     47 
     48=== 
     49--- input: J-PHONE/2.0/J-DN02 
     50--- expected: x-sjis-vodafone 
     51 
     52=== willcom 
     53--- input: Mozilla/3.0(DDIPOCKET;JRC/AH-J3001V,AH-J3002V/1.0/0100/c50)CNF/2.0 
     54--- expected: x-sjis-airh 
     55 
     56=== willcom 
     57--- input: Mozilla/3.0(DDIPOCKET;KYOCERA/AH-K3001V/1.4.1.67.000000/0.1/C100) Opera 7.0 
     58--- expected: x-utf8-airh 
     59 
     60=== ez 
     61--- input: UP.Browser/3.01-HI01 UP.Link/3.4.5.2 
     62--- expected: x-sjis-ezweb 
     63 
     64=== ez 
     65--- input: KDDI-TS21 UP.Browser/6.0.2.276 (GUI) MMP/1.1 
     66--- expected: x-utf8-ezweb 
     67