Remove Locale-Codes internals from core
[p5sagit/p5-mst-13.2.git] / cpan / Locale-Codes / lib / Locale / Currency.pm
CommitLineData
47a334e9 1package Locale::Currency;
f768f60b 2# Copyright (C) 2001 Canon Research Centre Europe (CRE).
3# Copyright (C) 2002-2009 Neil Bowers
4# Copyright (c) 2010-2010 Sullivan Beck
5# This program is free software; you can redistribute it and/or modify it
6# under the same terms as Perl itself.
7
47a334e9 8use strict;
f768f60b 9use warnings;
47a334e9 10require 5.002;
11
47a334e9 12require Exporter;
f768f60b 13use Carp;
14use Locale::Codes;
15use Locale::Constants;
16use Locale::Codes::Currency;
47a334e9 17
f768f60b 18#=======================================================================
19# Public Global Variables
20#=======================================================================
47a334e9 21
f768f60b 22use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
23
24$VERSION='3.12';
25@ISA = qw(Exporter);
26@EXPORT = qw(code2currency
27 currency2code
28 all_currency_codes
29 all_currency_names
30 currency_code2code
31 LOCALE_CURR_ALPHA
32 LOCALE_CURR_NUMERIC
33 );
34
35sub _code {
36 my($code,$codeset) = @_;
37 $code = "" if (! $code);
38
39 $codeset = LOCALE_CURR_DEFAULT if (! defined($codeset) || $codeset eq "");
40
41 if ($codeset =~ /^\d+$/) {
42 if ($codeset == LOCALE_CURR_ALPHA) {
43 $codeset = "alpha";
44 } elsif ($codeset == LOCALE_CURR_NUMERIC) {
45 $codeset = "num";
46 } else {
47 return (1);
48 }
49 }
50
51 if ($codeset eq "alpha") {
52 $code = uc($code);
53 } elsif ($codeset eq "num") {
54 if (defined($code) && $code ne "") {
55 return (1) unless ($code =~ /^\d+$/);
56 $code = sprintf("%.3d", $code);
57 }
58 } else {
59 return (1);
60 }
61
62 return (0,$code,$codeset);
63}
47a334e9 64
f768f60b 65#=======================================================================
66#
67# code2currency ( CODE [,CODESET] )
68#
69#=======================================================================
70
71sub code2currency {
72 my($err,$code,$codeset) = _code(@_);
73 return undef if ($err ||
74 ! defined $code);
75
76 return Locale::Codes::_code2name("currency",$code,$codeset);
77}
47a334e9 78
79#=======================================================================
6b14ceb7 80#
f768f60b 81# currency2code ( CURRENCY [,CODESET] )
6b14ceb7 82#
47a334e9 83#=======================================================================
f768f60b 84
85sub currency2code {
86 my($currency,$codeset) = @_;
87 my($err,$tmp);
88 ($err,$tmp,$codeset) = _code("",$codeset);
89 return undef if ($err ||
90 ! defined $currency);
91
92 return Locale::Codes::_name2code("currency",$currency,$codeset);
47a334e9 93}
94
f768f60b 95#=======================================================================
96#
97# currency_code2code ( CODE,CODESET_IN,CODESET_OUT )
98#
99#=======================================================================
100
101sub currency_code2code {
102 (@_ == 3) or croak "currency_code2code() takes 3 arguments!";
103 my($code,$inset,$outset) = @_;
104 my($err,$tmp);
105 ($err,$code,$inset) = _code($code,$inset);
106 return undef if ($err);
107 ($err,$tmp,$outset) = _code("",$outset);
108 return undef if ($err);
109
110 return Locale::Codes::_code2code("currency",$code,$inset,$outset);
111}
6b14ceb7 112
113#=======================================================================
114#
f768f60b 115# all_currency_codes ( [CODESET] )
6b14ceb7 116#
117#=======================================================================
f768f60b 118
119sub all_currency_codes {
120 my($codeset) = @_;
121 my($err,$tmp);
122 ($err,$tmp,$codeset) = _code("",$codeset);
123 return undef if ($err);
124
125 return Locale::Codes::_all_codes("currency",$codeset);
47a334e9 126}
127
47a334e9 128
129#=======================================================================
6b14ceb7 130#
f768f60b 131# all_currency_names ( [CODESET] )
6b14ceb7 132#
133#=======================================================================
f768f60b 134
135sub all_currency_names {
136 my($codeset) = @_;
137 my($err,$tmp);
138 ($err,$tmp,$codeset) = _code("",$codeset);
139 return undef if ($err);
140
141 return Locale::Codes::_all_names("currency",$codeset);
47a334e9 142}
143
f768f60b 144#=======================================================================
145#
146# rename_currency ( CODE,NAME [,CODESET] )
147#
148#=======================================================================
149
150sub rename_currency {
151 my($code,$new_name,@args) = @_;
152 my $nowarn = 0;
153 $nowarn = 1, pop(@args) if ($args[$#args] eq "nowarn");
154 my $codeset = shift(@args);
155 my $err;
156 ($err,$code,$codeset) = _code($code,$codeset);
157
158 return Locale::Codes::_rename("currency",$code,$new_name,$codeset,$nowarn);
159}
6b14ceb7 160
161#=======================================================================
162#
f768f60b 163# add_currency ( CODE,NAME [,CODESET] )
6b14ceb7 164#
165#=======================================================================
f768f60b 166
167sub add_currency {
168 my($code,$name,@args) = @_;
169 my $nowarn = 0;
170 $nowarn = 1, pop(@args) if ($args[$#args] eq "nowarn");
171 my $codeset = shift(@args);
172 my $err;
173 ($err,$code,$codeset) = _code($code,$codeset);
174
175 return Locale::Codes::_add_code("currency",$code,$name,$codeset,$nowarn);
47a334e9 176}
177
f768f60b 178#=======================================================================
179#
180# delete_currency ( CODE [,CODESET] )
181#
182#=======================================================================
183
184sub delete_currency {
185 my($code,@args) = @_;
186 my $nowarn = 0;
187 $nowarn = 1, pop(@args) if ($args[$#args] eq "nowarn");
188 my $codeset = shift(@args);
189 my $err;
190 ($err,$code,$codeset) = _code($code,$codeset);
191
192 return Locale::Codes::_delete_code("currency",$code,$codeset,$nowarn);
193}
47a334e9 194
195#=======================================================================
f768f60b 196#
197# add_currency_alias ( NAME,NEW_NAME )
198#
47a334e9 199#=======================================================================
f768f60b 200
201sub add_currency_alias {
202 my($name,$new_name,$nowarn) = @_;
203 $nowarn = (defined($nowarn) && $nowarn eq "nowarn" ? 1 : 0);
204
205 return Locale::Codes::_add_alias("currency",$name,$new_name,$nowarn);
47a334e9 206}
207
f768f60b 208#=======================================================================
209#
210# delete_currency_alias ( NAME )
211#
212#=======================================================================
213
214sub delete_currency_alias {
215 my($name,$nowarn) = @_;
216 $nowarn = (defined($nowarn) && $nowarn eq "nowarn" ? 1 : 0);
217
218 return Locale::Codes::_delete_alias("currency",$name,$nowarn);
219}
220
221#=======================================================================
222#
223# rename_currency_code ( CODE,NEW_CODE [,CODESET] )
224#
225#=======================================================================
47a334e9 226
f768f60b 227sub rename_currency_code {
228 my($code,$new_code,@args) = @_;
229 my $nowarn = 0;
230 $nowarn = 1, pop(@args) if ($args[$#args] eq "nowarn");
231 my $codeset = shift(@args);
232 my $err;
233 ($err,$code,$codeset) = _code($code,$codeset);
234 ($err,$new_code,$codeset) = _code($new_code,$codeset) if (! $err);
235
236 return Locale::Codes::_rename_code("currency",$code,$new_code,$codeset,$nowarn);
237}
238
239#=======================================================================
240#
241# add_currency_code_alias ( CODE,NEW_CODE [,CODESET] )
242#
243#=======================================================================
244
245sub add_currency_code_alias {
246 my($code,$new_code,@args) = @_;
247 my $nowarn = 0;
248 $nowarn = 1, pop(@args) if ($args[$#args] eq "nowarn");
249 my $codeset = shift(@args);
250 my $err;
251 ($err,$code,$codeset) = _code($code,$codeset);
252 ($err,$new_code,$codeset) = _code($new_code,$codeset) if (! $err);
253
254 return Locale::Codes::_add_code_alias("currency",$code,$new_code,$codeset,$nowarn);
255}
256
257#=======================================================================
258#
259# delete_currency_code_alias ( CODE [,CODESET] )
260#
261#=======================================================================
262
263sub delete_currency_code_alias {
264 my($code,@args) = @_;
265 my $nowarn = 0;
266 $nowarn = 1, pop(@args) if ($args[$#args] eq "nowarn");
267 my $codeset = shift(@args);
268 my $err;
269 ($err,$code,$codeset) = _code($code,$codeset);
270
271 return Locale::Codes::_delete_code_alias("currency",$code,$codeset,$nowarn);
272}
273
2741;
275# Local Variables:
276# mode: cperl
277# indent-tabs-mode: nil
278# cperl-indent-level: 3
279# cperl-continued-statement-offset: 2
280# cperl-continued-brace-offset: 0
281# cperl-brace-offset: 0
282# cperl-brace-imaginary-offset: 0
283# cperl-label-offset: -2
284# End: