File Coverage

blib/lib/Lingua/ZH/Numbers/Currency.pm
Criterion Covered Total %
statement 19 21 90.4
branch 1 2 50.0
condition n/a
subroutine 6 7 85.7
pod 0 2 0.0
total 26 32 81.2


line stmt bran cond sub pod time code
1             # $File: //member/autrijus/Lingua-ZH-Numbers/Numbers/Currency.pm $ $Author: autrijus $
2             # $Revision: #2 $ $Change: 4128 $ $DateTime: 2003/02/08 06:01:51 $
3              
4             package Lingua::ZH::Numbers::Currency;
5             $Lingua::ZH::Numbers::Currency::VERSION = '0.01';
6              
7 1     1   1167 use 5.001;
  1         3  
  1         244  
8 1     1   7 use strict;
  1         1  
  1         36  
9 1     1   5 use Lingua::ZH::Numbers ();
  1         1  
  1         27  
10 1     1   5 use base 'Lingua::ZH::Numbers';
  1         1  
  1         108  
11 1     1   5 use vars qw($Charset %MAP $VERSION @EXPORT @ISA);
  1         2  
  1         746  
12             @EXPORT = 'currency_to_zh';
13              
14             =head1 NAME
15              
16             Lingua::ZH::Numbers::Currency - Converts currency values into their Chinese string equivalents
17              
18             =head1 VERSION
19              
20             This document describes version 0.01 of Lingua::ZH::Numbers::Currency, released
21             November 23, 2002.
22              
23             =head1 SYNOPSIS
24              
25             # OO Style
26             use Lingua::ZH::Numbers::Currency 'big5';
27             my $shuzi = Lingua::ZH::Numbers::Currency->new( 123 );
28             print $shuzi->get_string;
29              
30             my $lingyige_shuzi = Lingua::ZH::Numbers::Currency->new;
31             $lingyige_shuzi->parse( 7340 );
32             $chinese_string = $lingyige_shuzi->get_string;
33              
34             # Function style
35             print currency_to_zh( 345 ); # automatically exported
36              
37             # Change output format
38             Lingua::ZH::Numbers::Currency->charset('gb');
39              
40             =head1 DESCRIPTION
41              
42             This module is a subclass of L; it provides a
43             different set of characters used in currency numbers as used in
44             financial transactions. All five representation systems
45             (I): C, C, C, C and
46             C are still supported, although the C variant is
47             identical to the one used in L.
48              
49             You can also use this module in a functionnal manner by invoking
50             the C function.
51              
52             =head1 CAVEATS
53              
54             Fraction currency numbers are unsupported; you have to round the
55             number before passing it for conversion, via C or C.
56              
57             =cut
58              
59             %MAP = (
60             ($] >= 5.006) ? eval q(
61             'traditional' => {
62             mag => [ '', split(' ', "\x{842c} \x{5104} \x{5146} \x{4eac} \x{5793} \x{79ed} \x{7a70} \x{6e9d} \x{6f97} \x{6b63} \x{8f09} \x{6975} \x{6046}\x{6cb3}\x{6c99} \x{963f}\x{50e7}\x{7947} \x{90a3}\x{7531}\x{4ed6} \x{4e0d}\x{53ef}\x{601d}\x{8b70} \x{7121}\x{91cf}\x{5927}\x{6578}") ],
63             ord => [ '', split(' ', "\x{62fe} \x{4f70} \x{4edf}") ],
64             dig => [ split(' ', "\x{96f6} \x{58f9} \x{8cb3} \x{53c3} \x{8086} \x{4f0d} \x{9678} \x{67d2} \x{634c} \x{7396}") ],
65             dot => "\x{9ede}",
66             neg => "\x{8ca0}",
67             post => "\x{5713}\x{6574}",
68             },
69             'simplified' => {
70             mag => [ '', split(' ', "\x{4e07} \x{4ebf} \x{5146} \x{4eac} \x{5793} \x{79ed} \x{7a70} \x{6c9f} \x{6da7} \x{6b63} \x{8f7d} \x{6781} \x{6052}\x{6cb3}\x{6c99} \x{963f}\x{50e7}\x{7957} \x{90a3}\x{7531}\x{4ed6} \x{4e0d}\x{53ef}\x{601d}\x{8bae} \x{65e0}\x{91cf}\x{5927}\x{6570}") ],
71             ord => [ '', split(' ', "\x{62fe} \x{4f70} \x{4edf}") ],
72             dig => [ split(' ', "\x{96f6} \x{58f9} \x{8d30} \x{53c2} \x{8086} \x{4f0d} \x{9646}\x{67d2} \x{634c} \x{7396}") ],
73             dot => "\x{70b9}",
74             neg => "\x{8d1f}",
75             post => "\x{5706}\x{6574}",
76             },
77             ) : (),
78             'big5' => {
79             mag => [ '', split(' ', "\xB8U \xBB\xF5 \xA5\xFC \xA8\xCA \xAB\xB2 \xD2\xF1 \xF6\xF8 \xB7\xBE \xBC\xEE \xA5\xBF \xB8\xFC \xB7\xA5 \xAB\xED\xAAe\xA8F \xAA\xFC\xB9\xAC\xAC\xE9 \xA8\xBA\xA5\xD1\xA5L \xA4\xA3\xA5i\xAB\xE4\xC4\xB3 \xB5L\xB6q\xA4j\xBC\xC6") ],
80             ord => [ '', split(' ', "\xACB \xA8\xD5 \xA5a") ],
81             dig => [ split(' ', "\xB9s \xB3\xFC \xB6L \xB0\xD1 \xB8v \xA5\xEE \xB3\xB0 \xACm \xAE\xC3 \xA8h") ],
82             dot => "\xC2I",
83             neg => "\xADt",
84             post => "\xB6\xEA\xBE\xE3",
85             },
86             'gb' => {
87             mag => [ '', split(' ', "\xCD\xF2 \xD2\xDA \xD5\xD7 \xBE\xA9 \xDB\xF2 \xEF\xF6 \xF0\xA6 \xB9\xB5 \xBD\xA7 \xD5\xFD \xD4\xD8 \xBC\xAB \xBA\xE3\xBA\xD3\xC9\xB3 \xB0\xA2\xC9\xAE\xEC\xF3 \xC4\xC7\xD3\xC9\xCB\xFB \xB2\xBB\xBF\xC9\xCB\xBC\xD2\xE9 \xCE\xDE\xC1\xBF\xB4\xF3\xCA\xFD") ],
88             ord => [ '', split(' ', "\xCA\xB0 \xB0\xDB \xC7\xAA") ],
89             dig => [ split(' ', "\xC1\xE3 \xD2\xBC \xB7\xA1 \xB2\xCE \xCB\xC1 \xCE\xE9 \xC2\xBD \xC6\xE2 \xB0\xC6 \xBE\xC1") ],
90             dot => "\xB5\xE3",
91             neg => "\xB8\xBA",
92             post => "\xD4\xB2\xD5\xFB",
93             },
94             'pinyin' => $ISA[0]->map->{pinyin},
95             );
96             # }}}
97              
98             $MAP{pinyin}{post} = "Yuan Zheng";
99             $Charset = 'pinyin';
100              
101             sub get_string {
102 0     0 0 0 my ($self) = @_;
103 0         0 return currency_to_zh($$self);
104             }
105              
106             sub currency_to_zh {
107 1     1 0 4 my $input = shift;
108 1 50       4 die "Fraction currency numbers not yet supported" if $input =~ s/\.(.*)//;
109 1         8 my $num = __PACKAGE__->_convert($MAP{$Charset}, $input);
110 1         7 $num .= $MAP{$Charset}{post};
111             }
112              
113             1;
114              
115             =head1 SEE ALSO
116              
117             L
118              
119             =head1 ACKNOWLEDGMENTS
120              
121             Dieter Simader for suggesting me to write this module.
122              
123             =head1 AUTHORS
124              
125             Autrijus Tang Eautrijus@autrijus.orgE
126              
127             =head1 COPYRIGHT
128              
129             Copyright 2002 by Autrijus Tang Eautrijus@autrijus.orgE.
130              
131             This program is free software; you can redistribute it and/or modify it
132             under the same terms as Perl itself.
133              
134             See L
135              
136             =cut