Perl6-Pugs
view release on metacpan or search on metacpan
docs/articles/tpr.pod view on Meta::CPAN
You've probably seen Perl 5 functions that go out of their way to accept
either positional args, or a hash or hashref with named args. There's no
need to do that any more. If you have a function you'll be calling many
times with a changing set of arguments, you can keep them in a hash and
use the I<comma reduce> operator C<[,]> to flatten it:
sub make_many_cars ($howmany) {
my @cars;
for 1 .. $howmany { # the parens can be omitted here in Perl 6
my %car_prefs = get_user_prefs();
push @cars, make_car([,]%car_prefs);
}
return @cars;
}
=item Lightweight closure syntax
Every block acts like a closure in Perl 6. The syntax is at once simplified
-- you don't need to say C<sub> to declare anonymous pieces of code -- and
extended to include formal parameters.
ext/Locale-KeyedText/examples/inverter1/MyApp.pl view on Meta::CPAN
use v6-alpha;
use Locale::KeyedText;
use MyLib;
###########################################################################
###########################################################################
sub main () {
# user indicates language pref as command line argument
my Str @user_lang_prefs = @*ARGS.grep:{ $_ ~~ m/^<[a-zA-Z]>+$/ };
@user_lang_prefs = 'Eng'
if @user_lang_prefs == 0;
my Locale::KeyedText::Translator $translator .= new(
set_names => ['MyApp::L::', 'MyLib::L::'],
member_names => @user_lang_prefs,
);
show_message( $translator, Locale::KeyedText::Message.new(
msg_key => 'MYAPP_HELLO' ) );
# INPUT_LINE:
while (1) {
show_message( $translator, Locale::KeyedText::Message.new(
msg_key => 'MYAPP_PROMPT' ) );
ext/Locale-KeyedText/examples/inverter2/MyApp.pl view on Meta::CPAN
use v6-alpha;
use Locale::KeyedText;
use MyLib;
###########################################################################
###########################################################################
sub main () {
# user indicates language pref as command line argument
my Str @user_lang_prefs = @*ARGS.grep:{ $_ ~~ m/^<[a-zA-Z]>+$/ };
@user_lang_prefs = 'Eng'
if @user_lang_prefs == 0;
my Locale::KeyedText::Translator $translator .= new(
set_names => ['MyApp::L::', 'MyLib::L::'],
member_names => @user_lang_prefs,
);
show_message( $translator, Locale::KeyedText::Message.new(
msg_key => 'MYAPP_HELLO' ) );
# INPUT_LINE:
while (1) {
show_message( $translator, Locale::KeyedText::Message.new(
msg_key => 'MYAPP_PROMPT' ) );
ext/Rosetta/examples/shell.pl view on Meta::CPAN
use v6-alpha;
use Rosetta::Shell;
my Str @cmd_line_args = @*ARGS.grep:{ $_ ~~ m/^<[a-zA-Z:_]>+$/ };
my ($engine_name, @user_lang_prefs) = @cmd_line_args;
$engine_name //= 'Rosetta::Engine::Example';
@user_lang_prefs = 'en'
if @user_lang_prefs == 0;
Rosetta::Shell::main( engine_name => $engine_name,
user_lang_prefs => @user_lang_prefs );
ext/Rosetta/lib/Rosetta/Shell.pm view on Meta::CPAN
# External packages used by the Rosetta::Shell module, that do export symbols:
# (None Yet)
# State variables used by the Rosetta::Shell module:
my Locale::KeyedText::Translator $translator;
my Rosetta::Interface::DBMS $dbms;
###########################################################################
sub main (Str :$engine_name!, Str :@user_lang_prefs? = 'en') {
$translator .= new(
set_names => [
'Rosetta::Shell::L::',
'Rosetta::L::',
'Rosetta::Model::L::',
'Locale::KeyedText::L::',
$engine_name ~ '::L::',
],
member_names => @user_lang_prefs,
);
_show_message( Locale::KeyedText::Message.new(
msg_key => 'ROS_S_HELLO' ) );
try {
$dbms = Rosetta::Interface::DBMS.new(
engine_name => $engine_name );
};
if ($!) {
( run in 0.607 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )