| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Egg::Plugin::Filter::Plugin::Japanese; | 
| 2 |  |  |  |  |  |  | # | 
| 3 |  |  |  |  |  |  | # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> | 
| 4 |  |  |  |  |  |  | # | 
| 5 |  |  |  |  |  |  | # $Id: Japanese.pm 337 2008-05-14 12:30:09Z lushe $ | 
| 6 |  |  |  |  |  |  | # | 
| 7 | 1 |  |  | 1 |  | 600 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 39 |  | 
| 8 | 1 |  |  | 1 |  | 6 | use warnings; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 31 |  | 
| 9 | 1 |  |  | 1 |  | 6 | use Egg::Plugin::Filter; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 16 |  | 
| 10 | 1 |  |  | 1 |  | 25 | use Jcode; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 1067 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | our $VERSION = '3.00'; | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | our($Zspace, $RZspace); | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | my $EGG= 0; | 
| 17 |  |  |  |  |  |  | my $VAL= 1; | 
| 18 |  |  |  |  |  |  | my $ARG= 2; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | sub _setup_filters { | 
| 21 | 0 |  |  | 0 |  |  | my($class, $e)= @_; | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 0 | 0 |  |  |  |  | $Zspace  || die q{ I want setup '$Zspace'.  }; | 
| 24 | 0 | 0 |  |  |  |  | $RZspace || die q{ I want setup '$RZspace'. }; | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 0 |  |  |  |  |  | my $filters= \%Egg::Plugin::Filter::Filters; | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | $filters->{h2z}= sub { | 
| 29 | 0 | 0 |  | 0 |  |  | return 0 unless defined(${$_[$VAL]}); | 
|  | 0 |  |  |  |  |  |  | 
| 30 | 0 |  |  |  |  |  | ${$_[$VAL]}= Jcode->new($_[$VAL])->h2z; | 
|  | 0 |  |  |  |  |  |  | 
| 31 | 0 |  |  |  |  |  | }; | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | $filters->{a2z}= sub { | 
| 34 | 0 | 0 |  | 0 |  |  | return 0 unless defined(${$_[$VAL]}); | 
|  | 0 |  |  |  |  |  |  | 
| 35 | 0 |  |  |  |  |  | my $w= Jcode->new($_[$VAL])->h2z; | 
| 36 | 0 |  |  |  |  |  | $w->tr('A-Z', '£Á-£Ú'); | 
| 37 | 0 |  |  |  |  |  | $w->tr('a-z', '£Á-£Ú'); | 
| 38 | 0 |  |  |  |  |  | $w->tr('0-9', '£°-£¹'); | 
| 39 | 0 |  |  |  |  |  | ${$_[$VAL]}= $w; | 
|  | 0 |  |  |  |  |  |  | 
| 40 | 0 |  |  |  |  |  | }; | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | $filters->{j_trim}= sub { | 
| 43 | 0 | 0 |  | 0 |  |  | return 0 unless defined(${$_[$VAL]}); | 
|  | 0 |  |  |  |  |  |  | 
| 44 | 0 |  |  |  |  |  | 1 while ${$_[$VAL]}=~s{^(?:\s|$Zspace)+} []sg; | 
|  | 0 |  |  |  |  |  |  | 
| 45 | 0 |  |  |  |  |  | 1 while ${$_[$VAL]}=~s{(?:\s|$Zspace)$} []sg; | 
|  | 0 |  |  |  |  |  |  | 
| 46 | 0 |  |  |  |  |  | }; | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | $filters->{j_hold}= sub { | 
| 49 | 0 | 0 |  | 0 |  |  | defined(${$_[$VAL]}) and ${$_[$VAL]}=~s{(?:\s|$Zspace)+} []sg; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 50 | 0 |  |  |  |  |  | }; | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | $filters->{j_strip}= sub { | 
| 53 | 0 | 0 |  | 0 |  |  | return 0 unless defined(${$_[$VAL]}); | 
|  | 0 |  |  |  |  |  |  | 
| 54 | 0 |  |  |  |  |  | ${$_[$VAL]}=~s{(?:\s|$Zspace)+} [ ]sg; | 
|  | 0 |  |  |  |  |  |  | 
| 55 | 0 |  |  |  |  |  | }; | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | $filters->{j_strip_j}= sub { | 
| 58 | 0 | 0 |  | 0 |  |  | return 0 unless defined(${$_[$VAL]}); | 
|  | 0 |  |  |  |  |  |  | 
| 59 | 0 |  |  |  |  |  | ${$_[$VAL]}=~s{(?:\s|$Zspace)+} [$RZspace]sge; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 60 | 0 |  |  |  |  |  | }; | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | $filters->{j_strip_blank}= sub { | 
| 63 | 0 | 0 |  | 0 |  |  | return 0 unless defined(${$_[$VAL]}); | 
|  | 0 |  |  |  |  |  |  | 
| 64 | 0 |  |  |  |  |  | ${$_[$VAL]}=~s{(?: |$Zspace)+} [ ]sg; | 
|  | 0 |  |  |  |  |  |  | 
| 65 | 0 |  |  |  |  |  | }; | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | $filters->{j_strip_blank_j}= sub { | 
| 68 | 0 | 0 |  | 0 |  |  | return 0 unless defined(${$_[$VAL]}); | 
|  | 0 |  |  |  |  |  |  | 
| 69 | 0 |  |  |  |  |  | ${$_[$VAL]}=~s{(?: |$Zspace)+} [$RZspace]sge; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 70 | 0 |  |  |  |  |  | }; | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | $filters->{j_text}= sub { | 
| 73 | 0 |  |  | 0 |  |  | my($e, $v, $a)= @_; | 
| 74 | 0 |  |  |  |  |  | $filters->{h2z}->($e, $v); | 
| 75 | 0 |  |  |  |  |  | $filters->{strip_tab}->($e, $v); | 
| 76 | 0 |  |  |  |  |  | $filters->{j_trim}->($e, $v); | 
| 77 | 0 |  |  |  |  |  | $filters->{j_strip_blank}->($e, $v); | 
| 78 | 0 |  | 0 |  |  |  | $filters->{crlf}->($e, $v, [$a->[0] || 3]); | 
| 79 | 0 |  |  |  |  |  | }; | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | $filters->{j_fold}= sub { | 
| 82 | 0 |  |  | 0 |  |  | my($e, $v, $a)= @_; | 
| 83 | 0 |  | 0 |  |  |  | my $len= $a->[0] || 72; | 
| 84 | 0 |  |  |  |  |  | my $text; | 
| 85 | 0 |  |  |  |  |  | for (split /\n/, ${$_[$VAL]}) { | 
|  | 0 |  |  |  |  |  |  | 
| 86 | 0 | 0 |  |  |  |  | $text.= $_ ? join("\n", Jcode->new(\$_)->jfold($len)). "\n": "\n"; | 
| 87 |  |  |  |  |  |  | } | 
| 88 | 0 |  |  |  |  |  | chomp $text; | 
| 89 | 0 |  |  |  |  |  | ${$_[$VAL]}= $text; | 
|  | 0 |  |  |  |  |  |  | 
| 90 | 0 |  |  |  |  |  | }; | 
| 91 |  |  |  |  |  |  |  | 
| 92 | 0 |  |  |  |  |  | @_; | 
| 93 |  |  |  |  |  |  | } | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | 1; | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | __END__ | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | =head1 NAME | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | Egg::Plugin::Filter::Plugin::Japanese - Filter processing for Japanese. | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | package MyApp; | 
| 106 |  |  |  |  |  |  | use Egg qw/ Filter /; | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | __PACKAGE__->egg_startup( | 
| 109 |  |  |  |  |  |  | .......... | 
| 110 |  |  |  |  |  |  | .... | 
| 111 |  |  |  |  |  |  | plugin_filter => { | 
| 112 |  |  |  |  |  |  | plugins=> [qw/ Japanese::EUC /], | 
| 113 |  |  |  |  |  |  | }, | 
| 114 |  |  |  |  |  |  | ); | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | $e->filter( | 
| 117 |  |  |  |  |  |  | name    => [qw/ hold_html h2z a2z j_strip j_trim /], | 
| 118 |  |  |  |  |  |  | message => [qw/ escape_html j_text:3 j_fold:72 /], | 
| 119 |  |  |  |  |  |  | ); | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | It is a plugin for L<Egg::Plugin::Filter> that does the filter processing for Japanese. | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | It is made to use by setting plugin of the configuration of L<Egg::Plugin::Filter>. | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | plugin_filter => { | 
| 128 |  |  |  |  |  |  | plugins=> [qw/ Japanese::UTF8 /], | 
| 129 |  |  |  |  |  |  | }, | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | [[Egg::Plugin::Filter::Japanese::UTF8]]¡¢ | 
| 132 |  |  |  |  |  |  | [[Egg::Plugin::Filter::Japanese::EUC]]¡¢ | 
| 133 |  |  |  |  |  |  | [[Egg::Plugin::Filter::Japanese::Shift_JIS]] | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | =head1 FILTERS | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | =head3 h2z | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | The normal-width katakana is made multi byte character. | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | see [[Jcode]] | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | =head3 a2z | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | The alphanumeric character is made multi byte character. | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | The tr method of [[Jcode]] is used. | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | =head3 j_trim | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | 'trim' corresponding to the multi byte space is done. | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | =head3 j_hold | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | 'hold' corresponding to the multi byte space is done. | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | =head3 j_strip | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | 'strip' corresponding to the multi byte space is done. | 
| 160 |  |  |  |  |  |  | It is replaced with half angle space. | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | =head3 j_strip_j | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | 'strip' corresponding to the multi byte space is done. | 
| 165 |  |  |  |  |  |  | It is replaced with the multi byte space. | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | =head3 j_strip_blank | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | 'strip' is done for only half angle space and the em-size space. | 
| 170 |  |  |  |  |  |  | It is replaced with half angle space. | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | =head3 j_strip_blank_j | 
| 173 |  |  |  |  |  |  |  | 
| 174 |  |  |  |  |  |  | 'strip' is done for only half angle space and the em-size space. | 
| 175 |  |  |  |  |  |  | It is replaced with the multi byte space. | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | =head3 j_text [:NUMBER] | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | 'h2z' , 'strip_tab' , 'j_trim', 'j_strip_blank', 'crlf' are done at a time. | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | In NUMBER, the default when unspecifying it by the figure passed to crlf is three. | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | $e->filter( | 
| 184 |  |  |  |  |  |  | hoge => [qw/ j_text:2 /], | 
| 185 |  |  |  |  |  |  | ); | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | Using it by inputting textarea is convenient. | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | =head3 j_fold [:NUMBER] | 
| 190 |  |  |  |  |  |  |  | 
| 191 |  |  |  |  |  |  | The length of the character a line is arranged. | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | NUMBER is a figure passed to the jfold method of Jcode, and default is 72. | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | L<Egg::Release>, | 
| 198 |  |  |  |  |  |  | L<Egg::Plugin::Filter>, | 
| 199 |  |  |  |  |  |  | L<Egg::Plugin::Filter::Plugin::UTF8>, | 
| 200 |  |  |  |  |  |  | L<Egg::Plugin::Filter::Plugin::Shift_JIS>, | 
| 201 |  |  |  |  |  |  | L<Jcode>, | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | =head1 AUTHOR | 
| 204 |  |  |  |  |  |  |  | 
| 205 |  |  |  |  |  |  | Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> | 
| 206 |  |  |  |  |  |  |  | 
| 207 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 208 |  |  |  |  |  |  |  | 
| 209 |  |  |  |  |  |  | Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>. | 
| 210 |  |  |  |  |  |  |  | 
| 211 |  |  |  |  |  |  | This library is free software; you can redistribute it and/or modify | 
| 212 |  |  |  |  |  |  | it under the same terms as Perl itself, either Perl version 5.8.6 or, | 
| 213 |  |  |  |  |  |  | at your option, any later version of Perl 5 you may have available. | 
| 214 |  |  |  |  |  |  |  | 
| 215 |  |  |  |  |  |  | =cut | 
| 216 |  |  |  |  |  |  |  |