File Coverage

blib/lib/Lingua/Sinica/PerlYuYan.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package Lingua::Sinica::PerlYuYan;
2              
3 3     3   3661 use 5.008;
  3         10  
  3         121  
4 3     3   2053 use utf8;
  3         21  
  3         14  
5 3     3   99 use strict;
  3         8  
  3         91  
6 3     3   4942 use Filter::Simple::Compile;
  0            
  0            
7             use Encode ();
8              
9             our $VERSION = 1257439830.94865; # 2009年11月 6日 周五 00時50分39秒 CST
10              
11             =encoding utf8
12              
13             =head1 NAME
14              
15             Lingua::Sinica::PerlYuYan - 中書珨 - Perl in Classical Chinese in Perl
16              
17             =head1 VERSION
18              
19             our $VERSION = 1257439830.94865; # 2009年11月 6日 周五 00時50分39秒 CST
20              
21             =head1 SYNOPSIS
22              
23             # The Sieve of Eratosthenes - 埃拉托斯芬篩法
24             use Lingua::Sinica::PerlYuYan;
25              
26             用籌兮用嚴。井涸兮無礙
27             。印曰最高矣 又道數然哉。
28             。截起吾純風 賦小入大合。
29             。習予吾陣地 並二至純風。
30             。當起段賦取 加陣地合始。
31             。陣地賦篩始 繫繫此雜段。
32             。終陣地兮印 正道次標哉。
33             。輸空接段點 列終註泰來。
34              
35             =head1 DESCRIPTION
36              
37             This module makes it possible to write Perl programs in Classical Chinese poetry in Perl.
38              
39             說此經者,能以珨文言文珨。
40              
41             (If one I to ask "Why?", please refer to L for
42             related information.)
43              
44             (闕譯,以待來者。)
45              
46             This module uses the single-character property of Chinese to disambiguate
47             between keywords, so one may elide whitespaces much like in real Chinese writings.
48              
49             The vocabulary is in the 文言 (literary text) mode, not the common 白話
50             (spoken text) mode with multisyllabic words.
51              
52             C (or simply as C<譯()>) translates a
53             string containing English programs into Chinese.
54              
55             =cut
56              
57             our %Tab;
58             while () {
59             $_ = Encode::is_utf8($_) ? $_ : Encode::decode_utf8($_);
60              
61             next if /^\s*$/;
62             my @eng = split ' ';
63             my @chi = map {/\A [!-~]+ \z/msx ? $_ : split //, $_}
64             # clusters of ASCII are untranslated keywords; keep them
65             split ' ', ;
66             for (my $i = 0; $i <= $#eng; $i++) {
67             next if $chi[$i] eq $eng[$i]; # filter untranslated
68             $Tab{$chi[$i]} = # append space if keyword, but not single letter
69             $eng[$i] =~ /\A [a-z]{2,} \z/msx ? $eng[$i] . ' ' : $eng[$i];
70             }
71             }
72              
73             @Tab{qw{ 資曰 亂曰 檔曰 列曰 套曰 }}
74             = qw{ __DATA__ __END__ __FILE__ __LINE__ __PACKAGE__ };
75              
76             FILTER {
77             $_ = Encode::is_utf8($_) ? $_ : Encode::decode_utf8($_);
78              
79             foreach my $key ( sort { length $b <=> length $a } keys %Tab ) {
80             s/$key/$Tab{$key}/g;
81             }
82              
83             return($_ = Encode::encode_utf8($_));
84             };
85              
86             no warnings 'redefine';
87             sub translate {
88             my $code = shift;
89              
90             for my $key (sort {length $Tab{$b} cmp length $Tab{$a}} keys %Tab) {
91             $code =~ s/\Q$Tab{$key}\E/$key/g;
92             }
93              
94             return $code;
95             }
96              
97             1;
98              
99             =head1 SEE ALSO
100              
101             L, L
102              
103             =head1 CC0 1.0 Universal
104              
105             To the extent possible under law, 唐鳳 has waived all copyright and related
106             or neighboring rights to Lingua-Sinica-PerlYuYan.
107              
108             This work is published from Taiwan.
109              
110             L
111              
112             =begin html
113              
114            

115            
116             CC0
117            
118            
119             To the extent possible under law, 唐鳳
120             has waived all copyright and related or neighboring rights to
121             Lingua-Sinica-PerlYuYan.
122             This work is published from
123             Taiwan.
124            

125              
126             =end html
127              
128             =cut
129              
130             __DATA__