File Coverage

blib/lib/Encode/Korean/MRR.pm
Criterion Covered Total %
statement 20 34 58.8
branch 0 4 0.0
condition n/a
subroutine 7 11 63.6
pod 2 4 50.0
total 29 53 54.7


line stmt bran cond sub pod time code
1             # Encoding of Korean: McCune-Reischauer Romanization
2              
3             # $Id: MRR.pm,v 1.5 2007/11/29 14:25:31 you Exp $
4              
5             package Encode::Korean::MRR;
6              
7             our $VERSION = do { q$Revision: 1.5 $ =~ /\d+\.(\d+)/; sprintf "%.2f", $1 / 100 };
8              
9 1     1   25133 use 5.008008;
  1         3  
  1         29  
10              
11 1     1   4 use strict;
  1         5  
  1         39  
12 1     1   4 use warnings;
  1         1  
  1         22  
13              
14 1     1   914 use Encode::Encoding;
  1         10862  
  1         32  
15 1     1   8 use base qw(Encode::Encoding);
  1         2  
  1         128  
16              
17             __PACKAGE__->Define(qw/McCune-Reischauer mrr/);
18              
19             sub import {
20 1     1   16 require Encode;
21 1         36 Encode->export_to_level(1,@_);
22             }
23              
24 1     1   620 use Encode::Korean::TransliteratorGenerator;
  1         4  
  1         427  
25              
26             # == RULES ==
27              
28             my $mrr = Encode::Korean::TransliteratorGenerator->new();
29              
30             $mrr->consonants(qw(k kk n t tt r m p pp s ss ng ch tch ch' k' t' p' h));
31             $mrr->vowels(
32             "a",
33             "ae",
34             "ya",
35             "yae",
36             "\x{014F}", # \x{014F} latin small letter with breve (ŏ)
37             "e",
38             "y\x{014F}",
39             "ye",
40             "o",
41             "wa",
42             "wae",
43             "oe",
44             "yo",
45             "u",
46             "w\x{014F}",
47             "we",
48             "wi",
49             "yu",
50             "\x{016D}", # \x{016D} latin small letter u with breve (ŭ)
51             "\x{016D}y",
52             "i"
53             );
54             $mrr->el('l');
55             $mrr->ell('ll');
56             $mrr->naught('.');
57             $mrr->sep('.');
58             $mrr->make();
59              
60             # == MODES ==
61             $mrr->enmode('greedy');
62             $mrr->demode('greedy');
63              
64             sub enmode {
65 0     0 0   my $class = shift;
66 0           my($mode) = @_;
67 0           $mrr->enmode($mode);
68             }
69              
70             sub demode {
71 0     0 0   my $class = shift;
72 0           my($mode) = @_;
73 0           $mrr->demode($mode);
74             }
75              
76              
77              
78             # == METHODS ==
79             # === encode ===
80             # * encode($string [,$check])
81             # * Encodes unicode hangul syllables (Perl internal string)
82             # into transliterated (romanized) string
83             sub encode ($$;$) {
84 0     0 1   my ($obj, $str, $chk) = @_;
85 0           my $tr = Encode::encode 'utf8', $mrr->encode($str, $chk);
86 0 0         $_[1] = '' if $chk;
87 0           return $tr;
88             }
89              
90             # === decode ===
91             # * decode($octets [,$check])
92             # * Decodes transliteration into unicode hangul syllables (Perl internal string)
93             sub decode ($$;$) {
94 0     0 1   my ($obj, $str, $chk) = @_;
95 0           my $han = $mrr->decode(Encode::decode('utf8', $str), $chk);
96 0 0         $_[1] = '' if $chk;
97 0           return $han;
98             }
99              
100             # === cat_decode ===
101             # * Needs to work with encoding pragma
102             # * cat_decode($destination, $octets, $offset, $terminator [,$check])
103              
104              
105             1;
106             __END__