Changeset 19128 for lang/perl

Show
Ignore:
Timestamp:
09/10/08 19:17:33 (5 years ago)
Author:
daisuke
Message:

work with utf8 encoded strings, and properly decode them when we find one

Location:
lang/perl/Google-Chart/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Google-Chart/trunk/lib/Google/Chart/Type/QRcode.pm

    r18923 r19128  
    44use Moose; 
    55use Moose::Util::TypeConstraints; 
     6use Encode (); 
    67 
    78enum 'Google::Chart::Type::QRcode::Encoding' => qw(shift_jis utf-8 iso-8859-1); 
     
    5152    my $self = shift; 
    5253    my %data = ( 
    53         cht => 'qr', 
    54         chl => $self->text, 
     54        cht  => 'qr', 
     55        chl  => Encode::is_utf8($self->text) ? 
     56            Encode::decode_utf8($self->text) : $self->text, 
    5557        choe => $self->encoding, 
    5658        chld => $self->eclevel || $self->margin ?  
  • lang/perl/Google-Chart/trunk/t/53_qrcode.t

    r16838 r19128  
    11use strict; 
    2 use Test::More (tests => 5); 
     2use utf8; 
     3use Test::More (tests => 9); 
    34use Test::Exception; 
    45 
     
    2728    my %h = $uri->query_form; 
    2829    is( $h{cht}, "qr" ); 
     30} 
    2931 
     32{ 
     33    my $chart = Google::Chart->new( 
     34        type => { 
     35            module => "QRcode", 
     36            args   => { 
     37                text => Encode::encode_utf8("諸行無常") 
     38            } 
     39        } 
     40    ); 
     41 
     42    ok( $chart ); 
     43    isa_ok( $chart, "Google::Chart" ); 
     44 
     45    isa_ok( $chart->type, "Google::Chart::Type::QRcode" ); 
     46 
     47    my $uri = $chart->as_uri; 
     48    diag $uri; 
     49    my %h = $uri->query_form; 
     50    is( $h{cht}, "qr" ); 
    3051} 
     52