Changeset 3965 for lang/perl/Template-Plugin-MobileJPPictogram
- Timestamp:
- 01/02/08 13:40:55 (5 years ago)
- Location:
- lang/perl/Template-Plugin-MobileJPPictogram/trunk
- Files:
-
- 2 modified
-
lib/Template/Plugin/MobileJPPictogram.pm (modified) (3 diffs)
-
t/01_simple.t (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Template-Plugin-MobileJPPictogram/trunk/lib/Template/Plugin/MobileJPPictogram.pm
r3952 r3965 11 11 use Encode::JP::Mobile::Charnames; 12 12 13 our $FILTER_NAME = 'escape_pictograms';14 15 13 sub new { 16 14 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 ); 20 17 return $self; 21 18 } 22 19 23 sub commify{24 my $format = shift;25 local $_ = shift;20 sub _charname { 21 my ( $ctx, $unicode ) = @_; 22 die "unicode string missing for pictogram_charname" unless $unicode; 26 23 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; 31 26 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 36 sub _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 }; 33 49 } 34 50 … … 36 52 __END__ 37 53 38 =for stopwords aaaatttt dotottto gmail 54 =for stopwords aaaatttt dotottto gmail pictogram pictograms Unicode charnames 39 55 40 56 =head1 NAME 41 57 42 Template::Plugin::MobileJPPictogram - 58 Template::Plugin::MobileJPPictogram - Japanese mobile phone's pictogram operator 43 59 44 60 =head1 SYNOPSIS 45 61 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" /> 47 74 48 75 =head1 DESCRIPTION 49 76 50 Template::Plugin::MobileJPPictogram is 77 Template::Plugin::MobileJPPictogram is Japanese mobile phone's pictogram operator. 78 79 =head1 FILTERS 80 81 =head2 pictogram_charname 82 83 format with charnames. 84 85 [% body | pictogram_charname('***%s***') %] 86 87 =head2 pictogram_unicode 88 89 format with Unicode. 90 91 [% body | pictogram_unicode('<img src="/img/pictogram/%X.gif" />') %] 51 92 52 93 =head1 AUTHOR … … 61 102 it under the same terms as Perl itself. 62 103 63 =cut -
lang/perl/Template-Plugin-MobileJPPictogram/trunk/t/01_simple.t
r3952 r3965 5 5 use Template; 6 6 use Encode; 7 8 # 鬱膣愛味噌 7 9 8 10 filters { … … 29 31 === 30 32 --- input 31 template: "[% USE MobileJPPictogram %][% x | escape_pictograms%]"32 x: PICT:\x{E 001}33 --- expected: PICT: [男の子]33 template: "[% USE MobileJPPictogram %][% x | pictogram_charname('***%s***') %]" 34 x: PICT:\x{E754} 35 --- expected: PICT:***ウマ*** 34 36 37 === 38 --- input 39 template: |+ 40 [% USE MobileJPPictogram %][% x | pictogram_unicode('<img src="/img/pictogram/%04X.gif" />') %] 41 x: PICT:\x{E754} 42 --- expected 43 PICT:<img src="/img/pictogram/E754.gif" /> 44 45 === 46 --- input 47 template: |+ 48 [% USE MobileJPPictogram %][% x | pictogram_unicode('<img src="/img/pictogram/%d.gif" />') %] 49 x: PICT:\x{E754} 50 --- expected 51 PICT:<img src="/img/pictogram/59220.gif" /> 52
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)