Schema/country/code/alpha3.pm

filter: Statementstmt 100% 12 / 12 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 93.3% 14 / 15 SCAR 0.0
CC
1
Cov
93%
BEGIN
1.0
CRAP 1.0
« Schema/country/code/alpha2.pm ↑ Summary Schema/country/code.pm »
1 package Sah::Schema::country::code::alpha3;
2  
3 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4 1 our $DATE = '2020-03-08'; # DATE
5 1 our $DIST = 'Sah-Schemas-Country'; # DIST
6 1 our $VERSION = '0.008'; # VERSION
7  
8 1 ▶use Locale::Codes::Country_Codes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 my $codes = [sort (
11 1 keys(%{ $Locale::Codes::Data{'country'}{'code2id'}{'alpha-3'} }),
12 )];
13 1 ▶die "Can't extract country codes from Locale::Codes::Country_Codes"
Branch: 1 branch
BranchTrueFalseTotal
unless @$codes 0 1 1
14 unless @$codes;
15  
16 1 our $schema = [str => {
17 summary => 'Country code (alpha-3)',
18 description => <<'_',
19  
20 Accept only current (not retired) codes. Only alpha-3 codes are accepted.
21  
22 Code will be converted to lowercase.
23  
24 _
25 match => '\A[a-z]{3}\z',
26 in => $codes,
27 'x.perl.coerce_rules' => ['From_str::to_lower'],
28 examples => [
29 {value=>'', valid=>0},
30 {value=>'ID' , valid=>0, summary=>'Only alpha-3 codes are allowed'},
31 {value=>'IDN', valid=>1, validated_value=>'idn'},
32 {value=>'xx', valid=>0},
33 {value=>'xxx', valid=>0},
34 ],
35 }, {}];
36  
37 1 1;
38 # ABSTRACT: Country code (alpha-3)
39  
40 __END__
41  
42 =pod
43  
44 =encoding UTF-8
45  
46 =head1 NAME
47  
48 Sah::Schema::country::code::alpha3 - Country code (alpha-3)
49  
50 =head1 VERSION
51  
52 This document describes version 0.008 of Sah::Schema::country::code::alpha3 (from Perl distribution Sah-Schemas-Country), released on 2020-03-08.
53  
54 =head1 SYNOPSIS
55  
56 Using with L<Data::Sah>:
57  
58 use Data::Sah qw(gen_validator);
59 my $vdr = gen_validator("country::code::alpha3*");
60 say $vdr->($data) ? "valid" : "INVALID!";
61  
62 # Data::Sah can also create a validator to return error message, coerced value,
63 # even validators in other languages like JavaScript, from the same schema.
64 # See its documentation for more details.
65  
66 Using in L<Rinci> function metadata (to be used with L<Perinci::CmdLine>, etc):
67  
68 package MyApp;
69 our %SPEC;
70 $SPEC{myfunc} = {
71 v => 1.1,
72 summary => 'Routine to do blah ...',
73 args => {
74 arg1 => {
75 summary => 'The blah blah argument',
76 schema => ['country::code::alpha3*'],
77 },
78 ...
79 },
80 };
81 sub myfunc {
82 my %args = @_;
83 ...
84 }
85  
86 Sample data:
87  
88 "" # INVALID
89  
90 "ID" # INVALID (Only alpha-3 codes are allowed)
91  
92 "IDN" # valid, becomes "idn"
93  
94 "xx" # INVALID
95  
96 "xxx" # INVALID
97  
98 =head1 DESCRIPTION
99  
100 Accept only current (not retired) codes. Only alpha-3 codes are accepted.
101  
102 Code will be converted to lowercase.
103  
104 =head1 HOMEPAGE
105  
106 Please visit the project's homepage at L<https://metacpan.org/release/Sah-Schemas-Country>.
107  
108 =head1 SOURCE
109  
110 Source repository is at L<https://github.com/perlancar/perl-Sah-Schemas-Country>.
111  
112 =head1 BUGS
113  
114 Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Sah-Schemas-Country>
115  
116 When submitting a bug or request, please include a test-file or a
117 patch to an existing test-file that illustrates the bug or desired
118 feature.
119  
120 =head1 SEE ALSO
121  
122 L<Sah::Schema::country::code::alpha2>
123  
124 L<Sah::Schema::country::code>
125  
126 =head1 AUTHOR
127  
128 perlancar <perlancar@cpan.org>
129  
130 =head1 COPYRIGHT AND LICENSE
131  
132 This software is copyright (c) 2020, 2019, 2018 by perlancar@cpan.org.
133  
134 This is free software; you can redistribute it and/or modify it under
135 the same terms as the Perl 5 programming language system itself.
136  
137 =cut
« Schema/country/code/alpha2.pm ↑ Summary Schema/country/code.pm »