Show
Ignore:
Timestamp:
04/20/08 23:21:48 (5 years ago)
Author:
tokuhirom
Message:

- HTML::TreeBuidler? は unicode string じゃないと文字化けるので対応。
- Moxy::Util->detect_charset を HTTP::Response::charset に改名。

Location:
lang/perl/Moxy/trunk/lib
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Moxy/trunk/lib/Moxy.pm

    r10012 r10020  
    2727use YAML; 
    2828use HTML::TreeBuilder; 
     29use Moxy::Util; 
    2930use HTML::TreeBuilder::XPath; 
    3031use HTTP::MobileAttribute plugins => [ 
     
    235236            $self->log("Content-Type: $content_type"); 
    236237            if ($content_type =~ /html/i) { 
    237                 $res->content( rewrite($base_url, $res->content, $url) ); 
     238                $res->content( encode($res->charset, rewrite($base_url, decode($res->charset, $res->content), $url)) ); 
    238239            } 
    239240            use bytes; 
  • lang/perl/Moxy/trunk/lib/Moxy/Plugin/ControlPanel.pm

    r10004 r10020  
    2020 
    2121    # convert html charset to response charset. 
    22     my $charset = Moxy::Util->detect_charset($args->{response}); 
     22    my $charset = $args->{response}->charset; 
    2323    my $enc = Encode::find_encoding($charset); 
    2424    Encode::from_to($output, 'utf-8', $enc ? $enc->name : 'utf-8'); 
  • lang/perl/Moxy/trunk/lib/Moxy/Plugin/LocationBar.pm

    r10016 r10020  
    1818    return sprintf(<<"...", encode_entities($current_url)); 
    1919    <script> 
    20         var moxy_base = location.protocol + '://' + location.host; 
     20        var moxy_base = location.protocol.replace(':', '') + '://' + location.host; 
    2121    </script> 
    2222    <form method="get" onsubmit="location.href=moxy_base +'/'+encodeURIComponent(document.getElementById('moxy_url').value);return false;"> 
  • lang/perl/Moxy/trunk/lib/Moxy/Plugin/Pictogram.pm

    r10004 r10020  
    1515    my $carrier = $args->{mobile_attribute}->carrier; 
    1616 
    17     my $charset = 
    18         Moxy::Util->detect_charset( $args->{response} ); 
     17    my $charset = $args->{response}->charset; 
    1918    $charset = ( $charset =~ /utf-?8/i ) ? 'utf8' : 'sjis'; 
    2019 
  • lang/perl/Moxy/trunk/lib/Moxy/Util.pm

    r9968 r10020  
    2222} 
    2323 
    24 sub detect_charset { 
    25     my ($class, $response) = @_; 
     24sub HTTP::Response::charset { 
     25    my ($self, ) = @_; 
    2626 
    27     my $charset; 
    28     if ($response->header('Content-Type') =~ /charset=([\w\-]+)/io) { 
    29         $charset = $1; 
    30     } 
    31     $charset ||= ( $response->content() =~ /<\?xml version="1.0" encoding="([\w\-]+)"\?>/ )[0];  
    32     $charset ||= ( $response->content() =~ m!<meta http-equiv="Content-Type" content=".*charset=([\w\-]+)"!i )[0];  
    33     $charset ||= $Detector->($response->content());  
    34     $charset ||= 'utf-8';  
    35  
    36     return $charset; 
     27    return $self->{__charset} ||= do { 
     28        my $charset; 
     29        if ( $self->header('Content-Type') =~ /charset=([\w\-]+)/io ) { 
     30            $charset = $1; 
     31        } 
     32        $charset ||= ( $self->content() =~ /<\?xml version="1.0" encoding="([\w\-]+)"\?>/ )[0]; 
     33        $charset ||= ( $self->content() =~ m!<meta http-equiv="Content-Type" content=".*charset=([\w\-]+)"!i)[0]; 
     34        $charset ||= $Detector->( $self->content() ); 
     35        $charset ||= 'cp932'; 
     36        $charset; 
     37    }; 
    3738} 
    3839