line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl6::Placeholders; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1436
|
use Filter::Simple; |
|
1
|
|
|
|
|
31442
|
|
|
1
|
|
|
|
|
8
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my %giftwrap = ( |
8
|
|
|
|
|
|
|
'sort' => sub {"{$_[0]\->(\$a,\$b)}"}, |
9
|
|
|
|
|
|
|
'grep' => sub {"{$_[0]\->(\$_)}"}, |
10
|
|
|
|
|
|
|
'map' => sub {"{$_[0]\->(\$_)}"}, |
11
|
|
|
|
|
|
|
'sub' => sub {$_[0]}, |
12
|
|
|
|
|
|
|
'' => sub {$_[0]}, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
179
|
use re 'eval'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
418
|
|
16
|
|
|
|
|
|
|
our $code = qr{ (?: [^{}]+ | \{ (??{ $code }) \} )* }x; |
17
|
|
|
|
|
|
|
our $placeholder = qr{ (?: $code (?: (??{ $carvar }) $code ) )+ }x; |
18
|
|
|
|
|
|
|
our $carvar = qr{ (?: \$\w+ (?: |
19
|
|
|
|
|
|
|
(?:->)? (?:\[$placeholder\]|\{$placeholder\}) )+ |
20
|
|
|
|
|
|
|
| \$\^\w+ |
21
|
|
|
|
|
|
|
) |
22
|
|
|
|
|
|
|
}x; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
FILTER_ONLY |
25
|
|
|
|
|
|
|
executable => sub { |
26
|
|
|
|
|
|
|
s<(sub|sort|map|grep)?\s*(?=.*\$\^\w)\{($placeholder)\}> { |
27
|
|
|
|
|
|
|
my ($context,$code) = ($1||"",$2); |
28
|
|
|
|
|
|
|
my %vars; |
29
|
|
|
|
|
|
|
@vars{$code =~ m/(\$\^\w+)/g} = (); |
30
|
|
|
|
|
|
|
my $vars = join ',', sort keys %vars; |
31
|
|
|
|
|
|
|
my $decl = qq{my($vars)=\@_;}; |
32
|
|
|
|
|
|
|
$decl = "" if $code =~ /\Q$decl/; |
33
|
|
|
|
|
|
|
$code = qq{ sub {$decl $code } }; |
34
|
|
|
|
|
|
|
$code =~ s/\$\^(\w+)/\$$1/g; |
35
|
|
|
|
|
|
|
"$context ". $giftwrap{$context}($code); |
36
|
|
|
|
|
|
|
}ge; |
37
|
|
|
|
|
|
|
}, |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
__END__ |