line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::DWIM; |
2
|
|
|
|
|
|
|
$VERSION = '1.05'; |
3
|
|
|
|
|
|
|
my $dwimity = " \t"x4; |
4
|
|
|
|
|
|
|
my $dwimop = '...'; |
5
|
|
|
|
|
|
|
my $string = qr< (?:["][^"\\]*(?:\\.[^"\\]*)*["] |
6
|
|
|
|
|
|
|
| ['][^'\\]*(?:\\.[^'\\]*)*['] |
7
|
|
|
|
|
|
|
) |
8
|
|
|
|
|
|
|
>sx; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub dwim { |
11
|
0
|
|
|
0
|
0
|
0
|
local $_ = pop; |
12
|
0
|
|
|
|
|
0
|
my $table; |
13
|
0
|
|
|
|
|
0
|
my $odd=0; |
14
|
1
|
|
|
1
|
|
3401
|
use Data::Dumper 'Dumper'; |
|
1
|
|
|
|
|
18619
|
|
|
1
|
|
|
|
|
735
|
|
15
|
0
|
|
|
|
|
0
|
my @bits = split qr<(?!\s*\bx)($string|[\$\@%]\w+|[])}[({\w\s;/]+)>; |
16
|
0
|
|
|
|
|
0
|
for ($b=0;$b<@bits;$b+=2) { |
17
|
0
|
0
|
|
|
|
0
|
next unless $bits[$b]; |
18
|
0
|
|
|
|
|
0
|
$table .= $bits[$b]."\n"; |
19
|
0
|
|
|
|
|
0
|
$bits[$b] = $dwimop; |
20
|
|
|
|
|
|
|
} |
21
|
0
|
|
|
|
|
0
|
$_ = join "", @bits; |
22
|
0
|
|
|
|
|
0
|
$table = unpack "b*", $table; |
23
|
0
|
|
|
|
|
0
|
$table =~ tr/01/ \t/; |
24
|
0
|
|
|
|
|
0
|
$table =~ s/(.{8})/\n~$1/g; |
25
|
0
|
|
|
|
|
0
|
"$_\n~$dwimity$table"; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub undwim { |
29
|
1
|
|
|
1
|
0
|
21
|
local ($_,$table) = $_[0] =~ /(.*?)\n~$dwimity\n(.*)/sm; |
30
|
1
|
|
|
|
|
19
|
$table =~ s/[~\n]//g; |
31
|
1
|
|
|
|
|
3
|
$table =~ tr/ \t/01/; |
32
|
1
|
|
|
|
|
12
|
my @table = split /\n/, pack "b*", $table; |
33
|
1
|
|
|
|
|
14
|
s/\Q$dwimop/shift @table/ge; |
|
6
|
|
|
|
|
22
|
|
34
|
1
|
|
|
|
|
139
|
$_ |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
0
|
0
|
|
sub dwum { $_[0] =~ /^$dwimity/ } |
38
|
|
|
|
|
|
|
open 0 or print "Can't enDWIM '$0'\n" and exit; |
39
|
|
|
|
|
|
|
(my $code = join "", <0>) =~ s/(.*)^\s*use\s+Acme::DWIM\s*;(\s*?)\n//sm; |
40
|
|
|
|
|
|
|
my $pre = $1; |
41
|
|
|
|
|
|
|
my $dwum = $2||"" eq $dwimity; |
42
|
|
|
|
|
|
|
local $SIG{__WARN__} = \&dwum; |
43
|
|
|
|
|
|
|
do {eval $pre . undwim $code; print STDERR $@ if $@; exit} if $dwum; |
44
|
|
|
|
|
|
|
open 0, ">$0" or print "Cannot DWIM with '$0'\n" and exit; |
45
|
|
|
|
|
|
|
print {0} $pre."use Acme::DWIM;$dwimity\n", dwim $code and exit; |
46
|
|
|
|
|
|
|
__END__ |