line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CLDR::Number::Format::Currency; |
2
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
38814
|
use v5.8.1; |
|
11
|
|
|
|
|
39
|
|
4
|
11
|
|
|
11
|
|
158
|
use utf8; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
92
|
|
5
|
11
|
|
|
11
|
|
233
|
use Carp; |
|
11
|
|
|
|
|
17
|
|
|
11
|
|
|
|
|
2259
|
|
6
|
11
|
|
|
11
|
|
502
|
use CLDR::Number::Constant qw( $C ); |
|
11
|
|
|
|
|
27
|
|
|
11
|
|
|
|
|
1281
|
|
7
|
11
|
|
|
11
|
|
7903
|
use CLDR::Number::Data::Currency; |
|
11
|
|
|
|
|
31
|
|
|
11
|
|
|
|
|
591
|
|
8
|
|
|
|
|
|
|
|
9
|
11
|
|
|
11
|
|
897
|
use Moo; |
|
11
|
|
|
|
|
13998
|
|
|
11
|
|
|
|
|
129
|
|
10
|
11
|
|
|
11
|
|
5836
|
use namespace::clean; |
|
11
|
|
|
|
|
11993
|
|
|
11
|
|
|
|
|
180
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.16'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with qw( CLDR::Number::Role::Format ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has currency_code => ( |
17
|
|
|
|
|
|
|
is => 'rw', |
18
|
|
|
|
|
|
|
isa => sub { |
19
|
|
|
|
|
|
|
croak 'uninitialized value' if !defined $_[0]; |
20
|
|
|
|
|
|
|
croak qq{invalid value "$_[0]"} if $_[0] !~ m{ ^ [A-Z]{3} $ }x; |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
coerce => sub { defined $_[0] ? uc $_[0] : $_[0] }, |
23
|
|
|
|
|
|
|
trigger => 1, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has currency_sign => ( |
27
|
|
|
|
|
|
|
is => 'rw', |
28
|
|
|
|
|
|
|
isa => sub { |
29
|
|
|
|
|
|
|
croak "currency_sign is not defined" if !defined $_[0]; |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# TODO: accounting NYI |
34
|
|
|
|
|
|
|
has accounting => ( |
35
|
|
|
|
|
|
|
is => 'rw', |
36
|
|
|
|
|
|
|
coerce => sub { $_[0] ? 1 : 0 }, |
37
|
|
|
|
|
|
|
default => 0, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has cash => ( |
41
|
|
|
|
|
|
|
is => 'rw', |
42
|
|
|
|
|
|
|
coerce => sub { $_[0] ? 1 : 0 }, |
43
|
|
|
|
|
|
|
trigger => 1, |
44
|
|
|
|
|
|
|
default => 0, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has _pattern_type => ( |
48
|
|
|
|
|
|
|
is => 'ro', |
49
|
|
|
|
|
|
|
default => 'currency', |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
after _trigger_locale => sub { |
53
|
|
|
|
|
|
|
my ($self) = @_; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
if ($self->currency_code) { |
56
|
|
|
|
|
|
|
$self->_build_currency_sign; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
if (my $decimal = $self->_get_data(symbol => 'currency_decimal')) { |
60
|
|
|
|
|
|
|
$self->decimal_sign($decimal); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub BUILD {} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _trigger_currency_code { |
67
|
86
|
|
|
86
|
|
1041
|
my ($self, $currency_code) = @_; |
68
|
|
|
|
|
|
|
|
69
|
86
|
|
|
|
|
218
|
$self->_build_currency_sign; |
70
|
86
|
|
|
|
|
981
|
$self->_trigger_cash; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _build_currency_sign { |
74
|
168
|
|
|
168
|
|
218
|
my ($self) = @_; |
75
|
168
|
|
|
|
|
242
|
my $data = $CLDR::Number::Data::Currency::LOCALES; |
76
|
168
|
|
|
|
|
203
|
my $currency_sign; |
77
|
|
|
|
|
|
|
|
78
|
168
|
100
|
|
|
|
494
|
return if $self->_has_init_arg('currency_sign'); |
79
|
|
|
|
|
|
|
|
80
|
166
|
|
|
|
|
264
|
for my $locale (@{$self->_locale_inheritance}) { |
|
166
|
|
|
|
|
457
|
|
81
|
169
|
100
|
66
|
|
|
3741
|
next if !exists $data->{$locale} || !exists $data->{$locale}{$self->currency_code}; |
82
|
80
|
|
|
|
|
1956
|
$currency_sign = $data->{$locale}{$self->currency_code}; |
83
|
80
|
|
|
|
|
487
|
last; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
166
|
|
66
|
|
|
3391
|
$self->currency_sign($currency_sign || $self->currency_code); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _trigger_cash { |
90
|
86
|
|
|
86
|
|
135
|
my ($self) = @_; |
91
|
86
|
|
|
|
|
146
|
my $currencies = $CLDR::Number::Data::Currency::CURRENCIES; |
92
|
|
|
|
|
|
|
my $currency_data |
93
|
|
|
|
|
|
|
= $self->currency_code && exists $currencies->{$self->currency_code} |
94
|
|
|
|
|
|
|
? $currencies->{$self->currency_code} |
95
|
86
|
100
|
66
|
|
|
1584
|
: $currencies->{DEFAULT}; |
96
|
|
|
|
|
|
|
|
97
|
86
|
50
|
33
|
|
|
4203
|
if ($self->cash && exists $currency_data->{cash_digits}) { |
98
|
0
|
|
|
|
|
0
|
$self->minimum_fraction_digits($currency_data->{cash_digits}); |
99
|
0
|
|
|
|
|
0
|
$self->maximum_fraction_digits($currency_data->{cash_digits}); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
else { |
102
|
86
|
|
|
|
|
6747
|
$self->minimum_fraction_digits($currency_data->{digits}); |
103
|
86
|
|
|
|
|
4476
|
$self->maximum_fraction_digits($currency_data->{digits}); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
86
|
50
|
33
|
|
|
5013
|
if ($self->cash && exists $currency_data->{cash_rounding}) { |
107
|
0
|
|
|
|
|
0
|
$self->rounding_increment($currency_data->{cash_rounding}); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
else { |
110
|
86
|
|
|
|
|
760
|
$self->rounding_increment($currency_data->{rounding}); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub format { |
115
|
111
|
|
|
111
|
1
|
11150
|
my ($self, $num) = @_; |
116
|
|
|
|
|
|
|
|
117
|
111
|
|
|
|
|
402
|
$num = $self->_validate_number(format => $num); |
118
|
111
|
100
|
|
|
|
306
|
return undef unless defined $num; |
119
|
|
|
|
|
|
|
|
120
|
110
|
100
|
|
|
|
2240
|
croak 'Missing required attribute: currency_code' |
121
|
|
|
|
|
|
|
unless $self->currency_code; |
122
|
|
|
|
|
|
|
|
123
|
109
|
|
|
|
|
2626
|
my $sign = $self->currency_sign; |
124
|
109
|
|
|
|
|
771
|
my $format = $self->_format_number($num); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# spacing before currency sign |
127
|
109
|
100
|
100
|
|
|
817
|
if ($sign =~ m{ ^ \PS }x && $format =~ m{ \d $C }x) { |
128
|
4
|
|
|
|
|
13
|
$sign = ' ' . $sign; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# spacing after currency sign |
132
|
109
|
100
|
100
|
|
|
707
|
if ($sign =~ m{ \PS $ }x && $format =~ m{ $C \d }x) { |
133
|
14
|
|
|
|
|
34
|
$sign .= ' '; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
109
|
|
|
|
|
574
|
$format =~ s{$C}{$sign}; |
137
|
|
|
|
|
|
|
|
138
|
109
|
|
|
|
|
662
|
return $format; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
__END__ |