App-optex
view release on metacpan or search on metacpan
domingo, 22 de octubre de 2017, 18:00:00 JST
When the specified module was not found in library path, **optex**
ignores the option and stops argument processing immediately. Ignored
options are passed through to the target command.
Module is also used with subroutine call. Suppose
`~/.optex.d/env.pm` module look like:
package env;
sub setenv {
while (($a, $b) = splice @_, 0, 2) {
$ENV{$a} = $b;
}
}
1;
Then it can be used in more generic fashion. In the next example,
first format is easy to read, but second one is more easy to type
because it does not have special characters to be escaped.
% date -Menv::setenv(LANG=de_DE) # need shell quote
% date -Menv::setenv=LANG=de_DE # alternative format
So 22 Okt 2017 18:00:00 JST
Option aliases can be also declared in the module, at the end of file,
following special literal `__DATA__`. Using this, you can prepare
multiple set of options for different purposes. Think about generic
**i18n** module:
package i18n;
1;
__DATA__
option --cn -Menv::setenv(LANG=zh_CN) // ä¸å½èª - ç°¡ä½å
option --tw -Menv::setenv(LANG=zh_TW) // ä¸å½èª - ç¹ä½å
option --us -Menv::setenv(LANG=en_US) // è±èª
option --fr -Menv::setenv(LANG=fr_FR) // ãã©ã³ã¹èª
option --de -Menv::setenv(LANG=de_DE) // ãã¤ãèª
option --it -Menv::setenv(LANG=it_IT) // ã¤ã¿ãªã¢èª
option --jp -Menv::setenv(LANG=ja_JP) // æ¥æ¬èª
option --kr -Menv::setenv(LANG=ko_KR) // éå½èª
option --br -Menv::setenv(LANG=pt_BR) // ãã«ãã¬ã«èª - ãã©ã¸ã«
option --es -Menv::setenv(LANG=es_ES) // ã¹ãã¤ã³èª
option --ru -Menv::setenv(LANG=ru_RU) // ãã·ã¢èª
This can be used like:
% date -Mi18n --tw
2017å¹´10æ22æ¥ é±æ¥ 18æ00å00ç§ JST
You can declare autoload module in your `~/.optex.d/optex.rc` like:
autoload -Mi18n --cn --tw --us --fr --de --it --jp --kr --br --es --ru
lib/App/optex/util.pm view on Meta::CPAN
use strict;
use warnings;
use List::Util qw(pairmap);
=pod
=over 7
=item B<setenv>(I<NAME>=VALUE,I<NAME2>=VALUE2,...)
Set environment variable I<NAME> to I<VALUE>, and so on.
=back
=cut
sub setenv {
pairmap { $ENV{$a} = $b } @_;
}
=pod
=over 7
=item B<chdir>(B<PATH>=I<directory>)
Change working directory to I<directory>.
script/optex view on Meta::CPAN
domingo, 22 de octubre de 2017, 18:00:00 JST
When the specified module was not found in library path, B<optex>
ignores the option and stops argument processing immediately. Ignored
options are passed through to the target command.
Module is also used with subroutine call. Suppose
F<~/.optex.d/env.pm> module look like:
package env;
sub setenv {
while (($a, $b) = splice @_, 0, 2) {
$ENV{$a} = $b;
}
}
1;
Then it can be used in more generic fashion. In the next example,
first format is easy to read, but second one is more easy to type
because it does not have special characters to be escaped.
% date -Menv::setenv(LANG=de_DE) # need shell quote
% date -Menv::setenv=LANG=de_DE # alternative format
So 22 Okt 2017 18:00:00 JST
Option aliases can be also declared in the module, at the end of file,
following special literal C<__DATA__>. Using this, you can prepare
multiple set of options for different purposes. Think about generic
B<i18n> module:
package i18n;
1;
__DATA__
option --cn -Menv::setenv(LANG=zh_CN) // ä¸å½èª - ç°¡ä½å
option --tw -Menv::setenv(LANG=zh_TW) // ä¸å½èª - ç¹ä½å
option --us -Menv::setenv(LANG=en_US) // è±èª
option --fr -Menv::setenv(LANG=fr_FR) // ãã©ã³ã¹èª
option --de -Menv::setenv(LANG=de_DE) // ãã¤ãèª
option --it -Menv::setenv(LANG=it_IT) // ã¤ã¿ãªã¢èª
option --jp -Menv::setenv(LANG=ja_JP) // æ¥æ¬èª
option --kr -Menv::setenv(LANG=ko_KR) // éå½èª
option --br -Menv::setenv(LANG=pt_BR) // ãã«ãã¬ã«èª - ãã©ã¸ã«
option --es -Menv::setenv(LANG=es_ES) // ã¹ãã¤ã³èª
option --ru -Menv::setenv(LANG=ru_RU) // ãã·ã¢èª
This can be used like:
% date -Mi18n --tw
2017å¹´10æ22æ¥ é±æ¥ 18æ00å00ç§ JST
You can declare autoload module in your F<~/.optex.d/optex.rc> like:
autoload -Mi18n --cn --tw --us --fr --de --it --jp --kr --br --es --ru
script/optex view on Meta::CPAN
this distribution, including binary files, unless explicitly noted
otherwise.
Copyright 2017-2024 Kazumasa Utashiro
=cut
# LocalWords: optex rc iso greple awk pdf LANG ENV Oct JST domingo
# LocalWords: setenv autoload PERLLIB BINDIR Utashiro Kazumasa
( run in 0.867 second using v1.01-cache-2.11-cpan-3989ada0592 )