Two ideas about rubyish perl
作者:gugod 發佈於:There are several nice things that I want to port them from Ruby, to Perl, in the Rubyish distribution.
The first is to allowing a block as the last argument when calling a sub-routine, but with the syntax like:
foo($a, $b, $c) {
my ($d) = @_;
....
};
this means: calling "foo" subroutine with 4 arguments: $a, $b, $c and a code ref. Similar work had already been done in Markapl. However, Markapl turns only HTML tag names into special keywords, to do this for any possible sub-routine names, it'll definitely need more Devel::Declare-fu.
It's relatively trivial to port block_given? and yield to Perl.
The second is to allow question marks and/or in the subroutine name. It's possible to define such subroutine in Perl by saying:
*{"is_foo?"} = sub { ... };
And to call it:
# one way
*{"is_foo?"}->();
# the other
__PACKAGE__->can("is_foo?")->();
# and some more
$m = 'is_foo?';
__PACKAGE__->$m;
They only works without the strict pragma.