| 1 | package AmberDB::Locale::Currency; | ||
| 2 | |||
| 3 | use 5.016; | ||
| 4 | use warnings; | ||
| 5 | use utf8; | ||
| 6 | use Carp qw(croak cluck); | ||
| 7 | |||
| 8 | our $VERSION = '5.26.6'; | ||
| 9 | my $CREATED = '2026-08-06'; | ||
| 10 | |||
| 11 | # Master ISO 4217 Currency Dictionary | ||
| 12 | # Value objects: immutable, static, universal data. | ||
| 13 | my %CURRENCIES = ( | ||
| 14 | 'TRY' => { num => '949', name => 'Turkish Lira', symbol => '₺', digits => 2 }, | ||
| 15 | 'USD' => { num => '840', name => 'US Dollar', symbol => '$', digits => 2 }, | ||
| 16 | 'EUR' => { num => '978', name => 'Euro', symbol => '€', digits => 2 }, | ||
| 17 | 'GBP' => { num => '826', name => 'Pound Sterling', symbol => '£', digits => 2 }, | ||
| 18 | 'RUB' => { num => '643', name => 'Russian Ruble', symbol => '₽', digits => 2 }, | ||
| 19 | 'AZN' => { num => '944', name => 'Azerbaijani Manat',symbol => '₼', digits => 2 }, | ||
| 20 | 'SAR' => { num => '682', name => 'Saudi Riyal', symbol => 'ر.س', digits => 2 }, | ||
| 21 | 'JPY' => { num => '392', name => 'Japanese Yen', symbol => '¥', digits => 0 }, | ||
| 22 | 'CHF' => { num => '756', name => 'Swiss Franc', symbol => 'CHF', digits => 2 }, | ||
| 23 | 'CAD' => { num => '124', name => 'Canadian Dollar', symbol => 'CA$', digits => 2 }, | ||
| 24 | 'AUD' => { num => '036', name => 'Australian Dollar',symbol => 'A$', digits => 2 }, | ||
| 25 | 'CNY' => { num => '156', name => 'Chinese Yuan', symbol => '¥', digits => 2 }, | ||
| 26 | ); | ||
| 27 | |||
| 28 | my @CURRENCY_ORDER = qw(TRY USD EUR GBP RUB AZN SAR JPY CHF CAD AUD CNY); | ||
| 29 | |||
| 30 | # Get currency hash by 3-letter ISO code | ||
| 31 | # AmberDB::Locale::Currency->cur_code('TRY') -> { num=>'949', name=>'Türk Lirası', symbol=>'₺', digits=>2 } | ||
| 32 | sub cur_code { | ||
| 33 | my ( $class_or_self, $code ) = @_; | ||
| 34 | return unless defined $code; | ||
| 35 | return $CURRENCIES{ uc($code) }; | ||
| 36 | } | ||
| 37 | |||
| 38 | # Get currency symbol by ISO code | ||
| 39 | # AmberDB::Locale::Currency->cur_symbol('TRY') -> '₺' | ||
| 40 | sub cur_symbol { | ||
| 41 | my ( $class_or_self, $code ) = @_; | ||
| 42 | return '' unless defined $code; | ||
| 43 | my $c = $CURRENCIES{ uc($code) }; | ||
| 44 | return $c ? $c->{symbol} : uc($code); | ||
| 45 | } | ||
| 46 | |||
| 47 | # Get currency name by ISO code | ||
| 48 | # AmberDB::Locale::Currency->cur_name('TRY') -> 'Türk Lirası' | ||
| 49 | sub cur_name { | ||
| 50 | my ( $class_or_self, $code ) = @_; | ||
| 51 | return '' unless defined $code; | ||
| 52 | my $c = $CURRENCIES{ uc($code) }; | ||
| 53 | return $c ? $c->{name} : uc($code); | ||
| 54 | } | ||
| 55 | |||
| 56 | # Get all currencies as [ [$code, $name], ... ] for form selects/dropdowns | ||
| 57 | sub cur_all { | ||
| 58 | return map { [ $_, $CURRENCIES{$_}->{name} ] } @CURRENCY_ORDER; | ||
| 59 | } | ||
| 60 | |||
| 61 | 1; |