App-LocaleCodesUtils
view release on metacpan or search on metacpan
lib/App/LocaleCodesUtils.pm view on Meta::CPAN
package App::LocaleCodesUtils;
use 5.010001;
use strict;
use warnings;
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2023-08-06'; # DATE
our $DIST = 'App-LocaleCodesUtils'; # DIST
our $VERSION = '0.004'; # VERSION
our %SPEC;
$SPEC{country_code2code} = {
v => 1.1,
summary => 'Convert country code (alpha2 <-> alpha3)',
args => {
code => {
schema => 'country::code',
req => 1,
pos => 0,
},
},
};
sub country_code2code {
require Locale::Codes::Country;
my %args = @_;
my $code = $args{code};
my $code2;
if (length($code) == 2) {
$code2 = Locale::Codes::Country::country_code2code($code, 'alpha-2', 'alpha-3');
} elsif (length($code) == 3) {
$code2 = Locale::Codes::Country::country_code2code($code, 'alpha-3', 'alpha-2');
} else {
return [400, "Please specify alpha-2 or alpha-3 code"];
}
return [404, "Unknown or non-unique code '$code'"] unless defined $code2;
[200, "OK", $code2];
}
$SPEC{language_code2code} = {
v => 1.1,
summary => 'Convert language code (alpha2 <-> alpha3)',
args => {
code => {
schema => 'language::code',
req => 1,
pos => 0,
},
},
};
sub language_code2code {
require Locale::Codes::Language;
my %args = @_;
my $code = $args{code};
my $code2;
if (length($code) == 2) {
$code2 = Locale::Codes::Language::language_code2code($code, 'alpha-2', 'alpha-3');
} elsif (length($code) == 3) {
$code2 = Locale::Codes::Language::language_code2code($code, 'alpha-3', 'alpha-2');
} else {
return [400, "Please specify alpha-2 or alpha-3 code"];
}
return [404, "Unknown or non-unique code '$code'"] unless defined $code2;
[200, "OK", $code2];
}
1;
# ABSTRACT: Utilities related to locale codes
__END__
=pod
=encoding UTF-8
=head1 NAME
App::LocaleCodesUtils - Utilities related to locale codes
=head1 VERSION
This document describes version 0.004 of App::LocaleCodesUtils (from Perl distribution App-LocaleCodesUtils), released on 2023-08-06.
=head1 DESCRIPTION
This distributions provides the following command-line utilities:
=over
=item * L<country-code2code>
=item * L<language-code2code>
=item * L<list-countries>
=item * L<list-currencies>
=item * L<list-languages>
=item * L<list-scripts>
=back
=head1 FUNCTIONS
=head2 country_code2code
Usage:
country_code2code(%args) -> [$status_code, $reason, $payload, \%result_meta]
Convert country code (alpha2 <-E<gt> alpha3).
This function is not exported.
Arguments ('*' denotes required arguments):
=over 4
=item * B<code>* => I<country::code>
(No description)
( run in 1.675 second using v1.01-cache-2.11-cpan-39bf76dae61 )