File: | blib/lib/Acme/Python.pm |
Coverage: | 66.7% |
line | stmt | bran | cond | sub | time | code |
---|---|---|---|---|---|---|
1 | package Acme::Python; | |||||
2 | ||||||
3 | $VERSION = 0.01; | |||||
4 | ||||||
5 | my $signed = "Hisssssssssssssssss"; | |||||
6 | ||||||
7 | sub encode { | |||||
8 | 0 | 0 | local $_ = unpack "b*", pop; | |||
9 | 0 0 | 0 0 | $_ = join ' ', map{ (/1/?'H':'h').'is'.('s' x length); } m/(0+|1+)/g; | |||
10 | 0 | 0 | s/(.{40,}?\s)/$1\n/g; | |||
11 | 0 | 0 | "$signed\n$_" | |||
12 | } | |||||
13 | sub decode { | |||||
14 | 1 | 31 | local $_ = pop; | |||
15 | 1 | 6065 | s/(^$signed|\s)//g; | |||
16 | 1 4494 | 20 51004 | s/([hH])is(s+)/ ($1 eq 'H'?'1':'0')x(length $2); /ge; | |||
17 | 1 | 3 | pack "b*", $_ | |||
18 | } | |||||
19 | sub garbled { | |||||
20 | 1 | 10 | $_[0] =~ /\S/ | |||
21 | } | |||||
22 | sub signed { | |||||
23 | 1 | 33 | $_[0] =~ /^$signed/ | |||
24 | } | |||||
25 | ||||||
26 | open 0 or print "Can't execute '$0'\n" and exit; | |||||
27 | ||||||
28 | (my $program = join "", <0>) =~ s/.*^\s*use\s+Acme::Python\s*;\n//sm; | |||||
29 | ||||||
30 | local $SIG{__WARN__} = \&garbled; | |||||
31 | ||||||
32 | do { | |||||
33 | 1 1 1 | 10 3 14 | eval decode $program; | |||
34 | exit | |||||
35 | } unless garbled $program && not signed $program; | |||||
36 | ||||||
37 | ||||||
38 | open 0, ">$0" or print "Can't python-ise '$0'\n" and exit; | |||||
39 | ||||||
40 | print {0} "use Acme::Python;\n", encode $program and exit; | |||||
41 |