| 1 | package CLDR::Number::Format::Currency; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use CLDR::Number::Data::Currency; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 6 | our $VERSION = '0.00_03'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 6 | with qw( CLDR::Number::Role::Format ); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | has currency_code => ( | ||||||||||||||||||||||||||||
| 14 | is => 'rw', | ||||||||||||||||||||||||||||
| 15 | isa => sub { | ||||||||||||||||||||||||||||
| 16 | 17 | ▶ | croak 'uninitialized value' if !defined $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 17 | ▶ | croak qq{invalid value "$_[0]"} if $_[0] !~ m{ ^ [A-Z]{3} $ }x; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | }, | ||||||||||||||||||||||||||||
| 19 | 17 | ▶ | coerce => sub { defined $_[0] ? uc $_[0] : $_[0] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 6 | trigger => 1, | |||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | has currency_sign => ( | ||||||||||||||||||||||||||||
| 24 | is => 'rw', | ||||||||||||||||||||||||||||
| 25 | isa => sub { | ||||||||||||||||||||||||||||
| 26 | 26 | ▶ | croak "currency_sign is not defined" if !defined $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | }, | ||||||||||||||||||||||||||||
| 28 | 6 | ); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # TODO: accounting NYI | ||||||||||||||||||||||||||||
| 31 | has accounting => ( | ||||||||||||||||||||||||||||
| 32 | is => 'rw', | ||||||||||||||||||||||||||||
| 33 | 12 | ▶ | coerce => sub { $_[0] ? 1 : 0 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 6 | default => 0, | |||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | has cash => ( | ||||||||||||||||||||||||||||
| 38 | is => 'rw', | ||||||||||||||||||||||||||||
| 39 | 12 | ▶ | coerce => sub { $_[0] ? 1 : 0 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 6 | trigger => 1, | |||||||||||||||||||||||||||
| 41 | default => 0, | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 6 | has _pattern_type => ( | |||||||||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||||||||||
| 46 | default => 'currency', | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | after _trigger_locale => sub { | ||||||||||||||||||||||||||||
| 50 | 14 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 14 | ▶ | if ($self->currency_code) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 9 | $self->_build_currency_sign; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 14 | ▶ | if (my $decimal = $self->_get_data(symbols => 'currency_decimal')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 2 | $self->decimal_sign($decimal); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 6 | }; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | ▶ | sub BUILD {} | |||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | sub _trigger_currency_code { | ||||||||||||||||||||||||||||
| 64 | 17 | ▶ | my ($self, $currency_code) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_trigger_currency_code: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 17 | $self->_build_currency_sign; | |||||||||||||||||||||||||||
| 67 | 17 | $self->_trigger_cash; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | sub _build_currency_sign { | ||||||||||||||||||||||||||||
| 71 | 26 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_build_currency_sign: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||
| 72 | 26 | my $data = $CLDR::Number::Data::Currency::LOCALES; | |||||||||||||||||||||||||||
| 73 | 26 | my $currency_sign; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 26 | ▶ | return if $self->_has_init_arg('currency_sign'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 24 | for my $locale (@{$self->_locale_inheritance}) { | |||||||||||||||||||||||||||
| 78 | 21 | ▶ | next if !exists $data->{$locale} || !exists $data->{$locale}{$self->currency_code}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $data->{$locale} and exists $data->{$locale}{$self->currency_code}
MC/DC50%1/2
exists $data->{$locale} and exists $data->{$locale}{$self->currency_code}
exists $data->{$locale}
exists $data->{$locale}{$self->currency_code}
Truth table66%2/3
A and B
A= exists $data->{$locale}B= exists $data->{$locale}{$self->currency_code}
| |||||||||||||||||||||||||||||
| 79 | 14 | $currency_sign = $data->{$locale}{$self->currency_code}; | |||||||||||||||||||||||||||
| 80 | 14 | last; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 24 | ▶ | $self->currency_sign($currency_sign || $self->currency_code); | ||||||||||||||||||||||||||
|
Condition66%2/3
$currency_sign || $self->currency_code
MC/DC0%0/2
$currency_sign || $self->currency_code
$currency_sign
$self->currency_code
Truth table66%2/3
A || B
A= $currency_signB= $self->currency_code
| |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | sub _trigger_cash { | ||||||||||||||||||||||||||||
| 87 | 17 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_trigger_cash: called CC=7 SCAR=22.8
| |||||||||||||||||||||||||||||
| 88 | 17 | my $currencies = $CLDR::Number::Data::Currency::CURRENCIES; | |||||||||||||||||||||||||||
| 89 | my $currency_data | ||||||||||||||||||||||||||||
| 90 | = $self->currency_code && exists $currencies->{$self->currency_code} | ||||||||||||||||||||||||||||
| 91 | ? $currencies->{$self->currency_code} | ||||||||||||||||||||||||||||
| 92 | 17 | ▶ | : $currencies->{DEFAULT}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->currency_code and exists $$currencies{$self->currency_code}
MC/DC50%1/2
$self->currency_code and exists $$currencies{$self->currency_code}
$self->currency_code
exists $$currencies{$self->currency_code}
Truth table66%2/3
A and B
A= $self->currency_codeB= exists $$currencies{$self->currency_code}
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 17 | ▶ | if ($self->cash && exists $currency_data->{cash_digits}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->cash and exists $currency_data->{"cash_digits"}
MC/DC0%0/2
$self->cash and exists $currency_data->{"cash_digits"}
$self->cash
exists $currency_data->{"cash_digits"}
Truth table33%1/3
A and B
A= $self->cashB= exists $currency_data->{"cash_digits"}
| |||||||||||||||||||||||||||||
| 95 | 0 | $self->minimum_fraction_digits($currency_data->{cash_digits}); | |||||||||||||||||||||||||||
| 96 | 0 | $self->maximum_fraction_digits($currency_data->{cash_digits}); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | else { | ||||||||||||||||||||||||||||
| 99 | 17 | $self->minimum_fraction_digits($currency_data->{digits}); | |||||||||||||||||||||||||||
| 100 | 17 | $self->maximum_fraction_digits($currency_data->{digits}); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 17 | ▶ | if ($self->cash && exists $currency_data->{cash_rounding}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->cash and exists $currency_data->{"cash_rounding"}
MC/DC0%0/2
$self->cash and exists $currency_data->{"cash_rounding"}
$self->cash
exists $currency_data->{"cash_rounding"}
Truth table33%1/3
A and B
A= $self->cashB= exists $currency_data->{"cash_rounding"}
| |||||||||||||||||||||||||||||
| 104 | 0 | $self->rounding_increment($currency_data->{cash_rounding}); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | else { | ||||||||||||||||||||||||||||
| 107 | 17 | $self->rounding_increment($currency_data->{rounding}); | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | sub format { | ||||||||||||||||||||||||||||
| 112 | 23 | ▶ | my ($self, $num) = @_; | ||||||||||||||||||||||||||
|
Subroutine
format: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 23 | ▶ | croak 'Missing required attribute: currency_code' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | unless $self->currency_code; | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 22 | my $format = $self->_format_number($num); | |||||||||||||||||||||||||||
| 118 | 22 | $format =~ s{ยค}{$self->currency_sign}e; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 22 | return $format; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 6 | 1; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | __END__ | ||||||||||||||||||||||||||||