line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::PerlML; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
36983
|
use 5.005; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
144
|
|
4
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
116
|
|
5
|
3
|
|
|
3
|
|
6189
|
use PPI; |
|
3
|
|
|
|
|
572243
|
|
|
3
|
|
|
|
|
106
|
|
6
|
3
|
|
|
3
|
|
2849
|
use Perl::SAX; |
|
3
|
|
|
|
|
91401
|
|
|
3
|
|
|
|
|
112
|
|
7
|
3
|
|
|
3
|
|
4245
|
use XML::Parser::PerlSAX; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use base qw(XML::SAX::Base); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use vars qw{$VERSION $CODE}; |
11
|
|
|
|
|
|
|
BEGIN { |
12
|
|
|
|
|
|
|
$VERSION = '1.00'; |
13
|
|
|
|
|
|
|
$CODE = ''; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
|
|
|
|
|
|
return bless {@_[1 .. $#_]}, $_[0]; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub characters { |
21
|
|
|
|
|
|
|
$CODE .= $_[1]->{Data}; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub xml2code { |
25
|
|
|
|
|
|
|
XML::Parser::PerlSAX->new( |
26
|
|
|
|
|
|
|
Handler => Acme::PerlML->new |
27
|
|
|
|
|
|
|
)->parse($_[0]); |
28
|
|
|
|
|
|
|
return $CODE; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub code2xml { |
32
|
|
|
|
|
|
|
my $Document = PPI::Document->new(\$_[0]); |
33
|
|
|
|
|
|
|
my $SAX = Perl::SAX->new; |
34
|
|
|
|
|
|
|
$SAX->parse( $Document ); |
35
|
|
|
|
|
|
|
return ${ $SAX->{Output} }; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Allow people to use Acme::PerlML () sanely |
39
|
|
|
|
|
|
|
sub import { |
40
|
|
|
|
|
|
|
## This code isn't Acme::Bleach evil yet as that would be teh hard to debug |
41
|
|
|
|
|
|
|
open 0 or die "Couldn't open $0: $!"; |
42
|
|
|
|
|
|
|
(my $code = join "", <0>) =~ s/(.*)^\s*use\s+Acme::PerlML\s*;\n//sm; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Already converted |
45
|
|
|
|
|
|
|
if ( $code =~ /^/m ) { |
46
|
|
|
|
|
|
|
eval xml2code($code); |
47
|
|
|
|
|
|
|
exit(); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $xml = code2xml($code) or die "Failed to convert Perl to XML"; |
51
|
|
|
|
|
|
|
no strict 'refs'; |
52
|
|
|
|
|
|
|
open 0, ">$0" or die "Cannot make the switch for '$0' : $!\n"; |
53
|
|
|
|
|
|
|
print {0} "$1\nuse Acme::PerlML;\n" . $xml; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__ |