| 1 | package Complete::Country; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | our $DATE = '2019-07-18'; # DATE | |||||||||||
| 4 | 1 | our $VERSION = '0.003'; # VERSION | |||||||||||
| 5 | |||||||||||||
| 6 | 1 | ▶ | use 5.010001; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 1 | ▶ | use Complete::Common qw(:all); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 1 | our %SPEC; | |||||||||||
| 13 | 1 | ▶ | use Exporter 'import'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 1 | our @EXPORT_OK = qw(complete_country_code); | |||||||||||
| 15 | |||||||||||||
| 16 | $SPEC{complete_country_code} = { | ||||||||||||
| 17 | 1 | v => 1.1, | |||||||||||
| 18 | summary => 'Complete from list of ISO-3166 country codes', | ||||||||||||
| 19 | args => { | ||||||||||||
| 20 | word => { | ||||||||||||
| 21 | schema => 'str*', | ||||||||||||
| 22 | req => 1, | ||||||||||||
| 23 | pos => 0, | ||||||||||||
| 24 | }, | ||||||||||||
| 25 | variant => { | ||||||||||||
| 26 | schema => [str=>{in=>['alpha-2','alpha-3']}], | ||||||||||||
| 27 | default => 'alpha-2', | ||||||||||||
| 28 | }, | ||||||||||||
| 29 | }, | ||||||||||||
| 30 | result_naked => 1, | ||||||||||||
| 31 | }; | ||||||||||||
| 32 | 0 | ▶ | sub complete_country_code { | ||||||||||
|
Subroutine
complete_country_code: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||
| 33 | 0 | require Complete::Util; | |||||||||||
| 34 | |||||||||||||
| 35 | 0 | state $codes = do { | |||||||||||
| 36 | 0 | require Locale::Codes::Country_Codes; | |||||||||||
| 37 | 0 | my $codes = {}; | |||||||||||
| 38 | 0 | my $id2names = $Locale::Codes::Data{'country'}{'id2names'}; | |||||||||||
| 39 | 0 | my $id2alpha2 = $Locale::Codes::Data{'country'}{'id2code'}{'alpha-2'}; | |||||||||||
| 40 | 0 | my $id2alpha3 = $Locale::Codes::Data{'country'}{'id2code'}{'alpha-3'}; | |||||||||||
| 41 | |||||||||||||
| 42 | 0 | for my $id (keys %$id2names) { | |||||||||||
| 43 | 0 | ▶ | if (my $c = $id2alpha2->{$id}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | 0 | $codes->{'alpha-2'}{$c} = $id2names->{$id}[0]; | |||||||||||
| 45 | } | ||||||||||||
| 46 | 0 | ▶ | if (my $c = $id2alpha3->{$id}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 47 | 0 | $codes->{'alpha-3'}{$c} = $id2names->{$id}[0]; | |||||||||||
| 48 | } | ||||||||||||
| 49 | } | ||||||||||||
| 50 | 0 | $codes; | |||||||||||
| 51 | }; | ||||||||||||
| 52 | |||||||||||||
| 53 | 0 | my %args = @_; | |||||||||||
| 54 | 0 | ▶ | my $word = $args{word} // ''; | ||||||||||
|
Condition0%0/2
$args{"word"} // ""
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table0%0/2
A
A= $args{"word"}
| |||||||||||||
| 55 | 0 | ▶ | my $variant = $args{variant} // 'alpha-2'; | ||||||||||
|
Condition0%0/2
$args{"variant"} // "alpha-2"
MC/DC0%0/1
$args{"variant"} // "alpha-2"
$args{"variant"}
Truth table0%0/2
A
A= $args{"variant"}
| |||||||||||||
| 56 | 0 | my $hash = $codes->{$variant}; | |||||||||||
| 57 | 0 | ▶ | return [] unless $hash; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | |||||||||||||
| 59 | 0 | Complete::Util::complete_hash_key( | |||||||||||
| 60 | word => $word, | ||||||||||||
| 61 | hash => $hash, | ||||||||||||
| 62 | summaries_from_hash_values => 1, | ||||||||||||
| 63 | ); | ||||||||||||
| 64 | } | ||||||||||||
| 65 | |||||||||||||
| 66 | 1 | 1; | |||||||||||
| 67 | # ABSTRACT: Complete from list of ISO-3166 country codes | ||||||||||||
| 68 | |||||||||||||
| 69 | __END__ | ||||||||||||