| 1 | package Sah::Schema::currency::code; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||
| 4 | 1 | our $DATE = '2020-03-08'; # DATE | |||||||||
| 5 | 1 | our $DIST = 'Sah-Schemas-Currency'; # DIST | |||||||||
| 6 | 1 | our $VERSION = '0.008'; # VERSION | |||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Locale::Codes::Currency_Codes (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | my $codes = [sort keys %{ $Locale::Codes::Data{'currency'}{'code2id'}{alpha} }]; | |||||||||
| 11 | 1 | ▶ | die "Can't extract any currency codes from Locale::Codes::Currency_Codes" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 12 | unless @$codes; | ||||||||||
| 13 | |||||||||||
| 14 | 1 | our $schema = [str => { | |||||||||
| 15 | summary => 'Currency code', | ||||||||||
| 16 | description => <<'_', | ||||||||||
| 17 | |||||||||||
| 18 | Accept only current (not retired) codes. Code will be converted to uppercase. | ||||||||||
| 19 | |||||||||||
| 20 | _ | ||||||||||
| 21 | match => '\A[A-Z]{3}\z', | ||||||||||
| 22 | in => $codes, | ||||||||||
| 23 | 'x.perl.coerce_rules' => ['From_str::to_upper'], | ||||||||||
| 24 | examples => [ | ||||||||||
| 25 | {value=>'', valid=>0}, | ||||||||||
| 26 | {value=>'idr', valid=>1, validated_value=>'IDR'}, | ||||||||||
| 27 | {value=>'foo', valid=>0}, | ||||||||||
| 28 | ], | ||||||||||
| 29 | }, {}]; | ||||||||||
| 30 | |||||||||||
| 31 | 1 | 1; | |||||||||
| 32 | # ABSTRACT: Currency code | ||||||||||
| 33 | |||||||||||
| 34 | __END__ | ||||||||||