| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CLDR::Number::Format::Currency; |
|
2
|
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
23150
|
use v5.8.1; |
|
|
11
|
|
|
|
|
27
|
|
|
4
|
11
|
|
|
11
|
|
124
|
use utf8; |
|
|
11
|
|
|
|
|
25
|
|
|
|
11
|
|
|
|
|
53
|
|
|
5
|
11
|
|
|
11
|
|
216
|
use Carp; |
|
|
11
|
|
|
|
|
14
|
|
|
|
11
|
|
|
|
|
706
|
|
|
6
|
11
|
|
|
11
|
|
322
|
use CLDR::Number::Constant qw( $C ); |
|
|
11
|
|
|
|
|
12
|
|
|
|
11
|
|
|
|
|
1015
|
|
|
7
|
11
|
|
|
11
|
|
5378
|
use CLDR::Number::Data::Currency; |
|
|
11
|
|
|
|
|
24
|
|
|
|
11
|
|
|
|
|
531
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
11
|
|
|
11
|
|
475
|
use Moo; |
|
|
11
|
|
|
|
|
8531
|
|
|
|
11
|
|
|
|
|
57
|
|
|
10
|
11
|
|
|
11
|
|
3867
|
use namespace::clean; |
|
|
11
|
|
|
|
|
7465
|
|
|
|
11
|
|
|
|
|
123
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.19'; |
|
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
|
|
741
|
my ($self, $currency_code) = @_; |
|
68
|
|
|
|
|
|
|
|
|
69
|
86
|
|
|
|
|
153
|
$self->_build_currency_sign; |
|
70
|
86
|
|
|
|
|
684
|
$self->_trigger_cash; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _build_currency_sign { |
|
74
|
168
|
|
|
168
|
|
153
|
my ($self) = @_; |
|
75
|
168
|
|
|
|
|
176
|
my $data = $CLDR::Number::Data::Currency::LOCALES; |
|
76
|
168
|
|
|
|
|
112
|
my $currency_sign; |
|
77
|
|
|
|
|
|
|
|
|
78
|
168
|
100
|
|
|
|
347
|
return if $self->_has_init_arg('currency_sign'); |
|
79
|
|
|
|
|
|
|
|
|
80
|
166
|
|
|
|
|
148
|
for my $locale (@{$self->_locale_inheritance}) { |
|
|
166
|
|
|
|
|
338
|
|
|
81
|
169
|
100
|
66
|
|
|
2492
|
next if !exists $data->{$locale} || !exists $data->{$locale}{$self->currency_code}; |
|
82
|
80
|
|
|
|
|
1327
|
$currency_sign = $data->{$locale}{$self->currency_code}; |
|
83
|
80
|
|
|
|
|
314
|
last; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
166
|
|
66
|
|
|
2316
|
$self->currency_sign($currency_sign || $self->currency_code); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _trigger_cash { |
|
90
|
86
|
|
|
86
|
|
85
|
my ($self) = @_; |
|
91
|
86
|
|
|
|
|
84
|
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
|
|
|
1089
|
: $currencies->{DEFAULT}; |
|
96
|
|
|
|
|
|
|
|
|
97
|
86
|
50
|
33
|
|
|
2904
|
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
|
|
|
|
|
5342
|
$self->minimum_fraction_digits($currency_data->{digits}); |
|
103
|
86
|
|
|
|
|
3081
|
$self->maximum_fraction_digits($currency_data->{digits}); |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
86
|
50
|
33
|
|
|
3437
|
if ($self->cash && exists $currency_data->{cash_rounding}) { |
|
107
|
0
|
|
|
|
|
0
|
$self->rounding_increment($currency_data->{cash_rounding}); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
else { |
|
110
|
86
|
|
|
|
|
525
|
$self->rounding_increment($currency_data->{rounding}); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub format { |
|
115
|
111
|
|
|
111
|
1
|
6688
|
my ($self, $num) = @_; |
|
116
|
|
|
|
|
|
|
|
|
117
|
111
|
|
|
|
|
251
|
$num = $self->_validate_number(format => $num); |
|
118
|
111
|
100
|
|
|
|
171
|
return undef unless defined $num; |
|
119
|
|
|
|
|
|
|
|
|
120
|
110
|
100
|
|
|
|
1605
|
croak 'Missing required attribute: currency_code' |
|
121
|
|
|
|
|
|
|
unless $self->currency_code; |
|
122
|
|
|
|
|
|
|
|
|
123
|
109
|
|
|
|
|
1790
|
my $sign = $self->currency_sign; |
|
124
|
109
|
|
|
|
|
522
|
my $format = $self->_format_number($num); |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# spacing before currency sign |
|
127
|
109
|
100
|
100
|
|
|
558
|
if ($sign =~ m{ ^ \PS }x && $format =~ m{ \d $C }x) { |
|
128
|
4
|
|
|
|
|
8
|
$sign = ' ' . $sign; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# spacing after currency sign |
|
132
|
109
|
100
|
100
|
|
|
495
|
if ($sign =~ m{ \PS $ }x && $format =~ m{ $C \d }x) { |
|
133
|
14
|
|
|
|
|
21
|
$sign .= ' '; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
109
|
|
|
|
|
395
|
$format =~ s{$C}{$sign}; |
|
137
|
|
|
|
|
|
|
|
|
138
|
109
|
|
|
|
|
435
|
return $format; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
__END__ |