Changeset 1346

Show
Ignore:
Timestamp:
11/12/07 23:58:50 (6 years ago)
Author:
tokuhirom
Message:

HTTP::MobileAgent?: use utf8, and perl critic clean, and portable.

Location:
lang/perl/HTTP-MobileAgent/trunk/bin
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/HTTP-MobileAgent/trunk/bin/makedocomomap

    r1328 r1346  
    11#!/usr/bin/perl -w 
    22use strict; 
     3use utf8; 
    34use FindBin; 
    4 use Jcode; 
    55use LWP::Simple; 
    66use Data::Dumper; 
    77use HTTP::MobileAgent; 
     8use Encode; 
     9use File::Spec; 
    810 
    9 my $URL = 'http://www.nttdocomo.co.jp/service/imode/make/content/spec/screen_area/index.html'; 
     11my $URL = 
     12'http://www.nttdocomo.co.jp/service/imode/make/content/spec/screen_area/index.html'; 
    1013 
    1114do_task(@ARGV); 
    1215 
    1316sub do_task { 
    14     my $html = Jcode->new(get($URL))->tr('��-��', '0-9')->euc; 
     17    my $html = decode( 'cp932', get($URL) ); 
    1518    $html =~ s/(?:\r?\n)+/\n/g; 
    1619    my $re = regexp(); 
    1720    my %map; 
    18     while ($html =~ /$re/igs) { 
    19         my($model, $width, $height, $color, $depth) = ($1, $2, $3, $4, $5); 
    20         $map{uc($model)} = { 
    21             width => $width, 
    22             height => $height, 
    23             color => $color eq '���顼', 
    24             depth => $depth, 
    25         }; 
     21    while ( $html =~ /$re/igs ) { 
     22        my ( $model, $width, $height, $color, $depth ) = ( $1, $2, $3, $4, $5 ); 
     23        $map{ uc($model) } = { 
     24            width => $width, 
     25            height => $height, 
     26            color  => $color eq 'カラー', 
     27            depth => $depth, 
     28        }; 
    2629    } 
    2730    my $overwrite = $ARGV[0] && $ARGV[0] eq '-o'; 
    28     output_code(\%map, $overwrite); 
     31    output_code( \%map, $overwrite ); 
    2932} 
    3033 
    3134sub output_code { 
    32     my($map, $overwrite) = @_; 
     35    my ( $map, $overwrite ) = @_; 
     36    my $fh; 
    3337    if ($overwrite) { 
    34         open MAP, "> $FindBin::Bin/../lib/HTTP/MobileAgent/DoCoMoDisplayMap.pm" or die $!; 
    35         select MAP; 
     38        open $fh, '>', File::Spec->catfile($FindBin::Bin, qw/ .. lib HTTP MobileAgent DoCoMoDisplayMap.pm/) 
     39          or die $!; 
     40        select $fh; 
    3641    } 
    3742    $Data::Dumper::Indent = 1; 
    3843    $Data::Dumper::Terse  = 1; 
    39     printf <<'TEMPLATE', Data::Dumper->Dump([ $map ]); 
     44    printf <<'TEMPLATE', Data::Dumper->Dump( [$map] ); 
    4045package HTTP::MobileAgent::DoCoMoDisplayMap; 
    4146# This file is autogenerated by makedocomomap 
     
    75801; 
    7681TEMPLATE 
    77     ; 
    7882    if ($overwrite) { 
    79         close MAP; 
     83        close $fh; 
    8084    } 
    8185} 
     
    8690<td><span class="txt">.*?(?:</span></td>)? 
    8791<td><span class="txt">.*?(?:</span></td>)? 
    88 <td><span class="txt">.*?(\d+)��\d+).*?</span></td> 
     92<td><span class="txt">.*?(\d+)×(\d+).*?</span></td> 
    8993<td>.*?</td> 
    90 <td><span class="txt">(����顼)(?:.*?)(\d+)(?:��|��Ĵ)</span></td> 
     94<td><span class="txt">(白黒|カラー)(?:.*?)(\d+)(?:色|階調)</span></td> 
    9195RE 
    92     ; 
    9396} 
  • lang/perl/HTTP-MobileAgent/trunk/bin/makexmldocomomap

    r1328 r1346  
    11#!/usr/bin/perl -w 
    22use strict; 
    3 use Jcode; 
     3use warnings; 
     4use utf8; 
    45use LWP::Simple; 
    5 use Data::Dumper; 
    6 use HTTP::MobileAgent; 
    7 require XML::Simple; 
     6use XML::Simple (); 
     7use Encode; 
    88 
    9 my $URL = 'http://www.nttdocomo.co.jp/service/imode/make/content/spec/screen_area/index.html'; 
     9my $URL = 
     10'http://www.nttdocomo.co.jp/service/imode/make/content/spec/screen_area/index.html'; 
    1011 
    1112do_task(@ARGV); 
    1213 
    1314sub do_task { 
    14     my $html = Jcode->new(get($URL))->tr('��-��', '0-9')->euc; 
     15    my $html = decode( 'cp932',  get($URL) ); 
    1516    $html =~ s/(?:\r?\n)+/\n/g; 
    1617    my $re = regexp(); 
    1718    my %map; 
    18     while ($html =~ /$re/igs) { 
    19         my($model, $width, $height, $color, $depth) = ($1, $2, $3, $4, $5); 
    20         push @{$map{terminal}}, { 
    21             model => uc($model), 
    22             width => $width, 
    23             height => $height, 
    24             color => $color eq '���顼', 
    25             depth => $depth, 
    26         }; 
     19    while ( $html =~ /$re/igs ) { 
     20        my ( $model, $width, $height, $color, $depth ) = ( $1, $2, $3, $4, $5 ); 
     21        push @{ $map{terminal} }, 
     22          { 
     23            model  => uc($model), 
     24            width  => $width, 
     25            height => $height, 
     26            color  => $color eq 'カラー', 
     27            depth  => $depth, 
     28          }; 
    2729    } 
    28     output_code(\%map); 
     30    output_code( \%map ); 
    2931} 
    3032 
    3133sub output_code { 
    32     my($map) = @_; 
     34    my ($map) = @_; 
    3335    my $xml = XML::Simple->new; 
    3436    printf <<'TEMPLATE', $xml->XMLout($map); 
     
    3638%s 
    3739TEMPLATE 
    38     ; 
    3940} 
    4041 
     
    4445<td><span class="txt">.*?(?:</span></td>)? 
    4546<td><span class="txt">.*?(?:</span></td>)? 
    46 <td><span class="txt">.*?(\d+)��\d+).*?</span></td> 
     47<td><span class="txt">.*?(\d+)×(\d+).*?</span></td> 
    4748<td>.*?</td> 
    48 <td><span class="txt">(����顼)(?:.*?)(\d+)(?:��|��Ĵ)</span></td> 
     49<td><span class="txt">(白黒|カラー)(?:.*?)(\d+)(?:色|階調)</span></td> 
    4950RE 
    50     ; 
    5151}