Show
Ignore:
Timestamp:
01/02/08 13:40:55 (6 years ago)
Author:
tokuhirom
Message:

spec changes

Location:
lang/perl/Template-Plugin-MobileJPPictogram/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Template-Plugin-MobileJPPictogram/trunk/lib/Template/Plugin/MobileJPPictogram.pm

    r3952 r3965  
    1111use Encode::JP::Mobile::Charnames; 
    1212 
    13 our $FILTER_NAME = 'escape_pictograms'; 
    14  
    1513sub new { 
    1614    my ( $self, $context, @args ) = @_; 
    17     my $format = $args[0] || '[%s]'; 
    18     my $name = $args[1] || $FILTER_NAME; 
    19     $context->define_filter( $name, sub { commify($format, $_[0]) }, 0 ); 
     15    $context->define_filter( 'pictogram_charname', \&_charname, 1 ); 
     16    $context->define_filter( 'pictogram_unicode',  \&_unicode,  1 ); 
    2017    return $self; 
    2118} 
    2219 
    23 sub commify { 
    24     my $format = shift; 
    25     local $_ = shift; 
     20sub _charname { 
     21    my ( $ctx, $unicode ) = @_; 
     22    die "unicode string missing for pictogram_charname" unless $unicode; 
    2623 
    27     s{(\p{InMobileJPPictograms})}{ 
    28         my $name = Encode::JP::Mobile::Charnames::unicode2name(unpack 'U*', $1); 
    29         sprintf $format, $name; 
    30     }ge; 
     24    sub { 
     25        local $_ = shift; 
    3126 
    32     return $_; 
     27        s{(\p{InMobileJPPictograms})}{ 
     28            my $name = Encode::JP::Mobile::Charnames::unicode2name(unpack 'U*', $1); 
     29            sprintf $unicode, $name; 
     30        }ge; 
     31 
     32        $_; 
     33    }; 
     34} 
     35 
     36sub _unicode { 
     37    my ( $ctx, $unicode ) = @_; 
     38    die "unicode string missing for pictogram_unicode" unless $unicode; 
     39 
     40    sub { 
     41        local $_ = shift; 
     42 
     43        s{(\p{InMobileJPPictograms})}{ 
     44            sprintf $unicode, unpack 'U*', $1; 
     45        }ge; 
     46 
     47        $_; 
     48    }; 
    3349} 
    3450 
     
    3652__END__ 
    3753 
    38 =for stopwords aaaatttt dotottto gmail 
     54=for stopwords aaaatttt dotottto gmail pictogram pictograms Unicode charnames 
    3955 
    4056=head1 NAME 
    4157 
    42 Template::Plugin::MobileJPPictogram - 
     58Template::Plugin::MobileJPPictogram - Japanese mobile phone's pictogram operator 
    4359 
    4460=head1 SYNOPSIS 
    4561 
    46   use Template::Plugin::MobileJPPictogram; 
     62  # controller 
     63  my $tt = Template->new; 
     64  $tt->process('foo.tt', {body => "\x{E001}"}); 
     65 
     66  # foo.tt 
     67  [% USE MobileJPPictogram %] 
     68  [% body | pictogram_charname('***%s***') %] 
     69  [% body | pictogram_unicode('<img src="/img/pictogram/%X.gif" />') %] 
     70 
     71  # output 
     72  ***$BCK$N;R(B*** 
     73  <img src="/img/pictogram/E001.gif" /> 
    4774 
    4875=head1 DESCRIPTION 
    4976 
    50 Template::Plugin::MobileJPPictogram is 
     77Template::Plugin::MobileJPPictogram is Japanese mobile phone's pictogram operator. 
     78 
     79=head1 FILTERS 
     80 
     81=head2 pictogram_charname 
     82 
     83format with charnames. 
     84 
     85    [% body | pictogram_charname('***%s***') %] 
     86 
     87=head2 pictogram_unicode 
     88 
     89format with Unicode. 
     90 
     91    [% body | pictogram_unicode('<img src="/img/pictogram/%X.gif" />') %] 
    5192 
    5293=head1 AUTHOR 
     
    61102it under the same terms as Perl itself. 
    62103 
    63 =cut 
  • lang/perl/Template-Plugin-MobileJPPictogram/trunk/t/01_simple.t

    r3952 r3965  
    55use Template; 
    66use Encode; 
     7 
     8# 鬱膣愛味噌 
    79 
    810filters { 
     
    2931=== 
    3032--- input 
    31 template: "[% USE MobileJPPictogram %][% x | escape_pictograms %]" 
    32 x: PICT:\x{E001} 
    33 --- expected: PICT:[男の子] 
     33template: "[% USE MobileJPPictogram %][% x | pictogram_charname('***%s***') %]" 
     34x: PICT:\x{E754} 
     35--- expected: PICT:***ウマ*** 
    3436 
     37=== 
     38--- input 
     39template: |+ 
     40    [% USE MobileJPPictogram %][% x | pictogram_unicode('<img src="/img/pictogram/%04X.gif" />') %] 
     41x: PICT:\x{E754} 
     42--- expected 
     43PICT:<img src="/img/pictogram/E754.gif" /> 
     44 
     45=== 
     46--- input 
     47template: |+ 
     48    [% USE MobileJPPictogram %][% x | pictogram_unicode('<img src="/img/pictogram/%d.gif" />') %] 
     49x: PICT:\x{E754} 
     50--- expected 
     51PICT:<img src="/img/pictogram/59220.gif" /> 
     52