Getopt-EX-i18n
view release on metacpan or search on metacpan
lib/Getopt/EX/i18n.pm view on Meta::CPAN
sort { $a->[1] cmp $b->[1] ||
lc $a->[0] cmp lc $b->[0] || $a->[0] cmp $b->[0] }
map { [ $_, $opthash{$_}->cc ] }
keys %opthash;
};
for my $opt (@keys) {
my $obj = $opthash{$opt};
my $option = $opt{prefix} . $opt;
my $name = $obj->name;
my $locale = $locale{$name};
my $call = "&setenv($opt{env}=$locale)";
$module->setopt($option, $call) if $arg{set};
if ($arg{show}) {
printf "option %-*s %s # %s / %s\n",
(state $optwidth = length($opt{prefix}) + length($name)),
$option, $call,
$obj->cc_name, $obj->lang_name;
}
}
exit if $arg{exit};
return ();
lib/Getopt/EX/i18n.pm view on Meta::CPAN
sub locales {
chomp( my @locale = `locale -a` );
grep { /^\w\w_\w\w$/ } @locale;
}
sub setopt {
%opt = (%opt, @_);
}
sub setenv {
while (@_ >= 2) {
my($key, $value) = splice @_, 0, 2;
if ($opt{verbose}) {
my $l = Local::LocaleObj->create($value);
warn sprintf("%s=%s (%s / %s)\n",
$key, $value, $l->lang_name, $l->cc_name);
}
$ENV{$key} = $value;
}
return ();
t/01_basic.t view on Meta::CPAN
# Test setopt function
{
# Test setopt (function exists and can be called)
ok eval { Getopt::EX::i18n::setopt(verbose => 1, list => 1); 1 }, 'setopt function works';
# Reset options
Getopt::EX::i18n::setopt(verbose => 0, list => 0);
ok 1, 'setopt can reset options';
}
# Test setenv function
{
local %ENV;
Getopt::EX::i18n::setenv('LANG', 'ja_JP.UTF-8');
is $ENV{LANG}, 'ja_JP.UTF-8', 'setenv sets environment variable';
# Test multiple pairs
Getopt::EX::i18n::setenv('LC_ALL', 'en_US.UTF-8', 'LC_TIME', 'fr_FR.UTF-8');
is $ENV{LC_ALL}, 'en_US.UTF-8', 'setenv sets first pair';
is $ENV{LC_TIME}, 'fr_FR.UTF-8', 'setenv sets second pair';
}
# Test setup function
{
# Skip if locale command is not available
SKIP: {
skip "locale command not available", 1 unless grep { -x "$_/locale" } split /:/, $ENV{PATH};
# Test that setup function can be called
ok eval { Getopt::EX::i18n::setup(); 1 }, 'setup function works';
( run in 0.683 second using v1.01-cache-2.11-cpan-3989ada0592 )