line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::Invisible; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
73702
|
use strict; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
5
|
use Exporter qw(import); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
6
|
1
|
|
|
1
|
|
455
|
use Pegex::Grammar; |
|
1
|
|
|
|
|
4814
|
|
|
1
|
|
|
|
|
6
|
|
7
|
1
|
|
|
1
|
|
504
|
use Pegex::Parser; |
|
1
|
|
|
|
|
10020
|
|
|
1
|
|
|
|
|
34
|
|
8
|
1
|
|
|
1
|
|
541
|
use XML::Invisible::Receiver; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
63
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(make_parser ast2xml); |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
7
|
use constant DEBUG => $ENV{XML_INVISIBLE_DEBUG}; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
418
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub make_parser { |
16
|
3
|
|
|
3
|
1
|
141
|
my ($grammar_text) = @_; |
17
|
3
|
|
|
|
|
15
|
my $grammar = Pegex::Grammar->new(text => $grammar_text); |
18
|
3
|
|
|
|
|
192
|
my $parser = Pegex::Parser->new( |
19
|
|
|
|
|
|
|
grammar => $grammar, |
20
|
|
|
|
|
|
|
receiver => XML::Invisible::Receiver->new, |
21
|
|
|
|
|
|
|
debug => DEBUG, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
sub { |
24
|
3
|
|
|
3
|
|
15
|
my ($ixml_text) = @_; |
25
|
3
|
|
|
|
|
11
|
$parser->parse($ixml_text); |
26
|
3
|
|
|
|
|
434
|
}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $xml_loaded = 0; |
30
|
|
|
|
|
|
|
sub ast2xml { |
31
|
3
|
50
|
|
3
|
1
|
5638
|
do { require XML::LibXML; $xml_loaded = 1 } unless $xml_loaded; |
|
3
|
|
|
|
|
486
|
|
|
0
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my ($ast) = @_; |
33
|
0
|
|
|
|
|
|
my $doc = XML::LibXML->createDocument("1.0", "UTF-8"); |
34
|
0
|
|
|
|
|
|
$doc->addChild(_item2elt($ast)); |
35
|
0
|
|
|
|
|
|
$doc; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _item2elt { |
39
|
0
|
|
|
0
|
|
|
my ($item) = @_; |
40
|
0
|
0
|
|
|
|
|
die "Unknown item '$item' passed" if ref $item ne 'HASH'; |
41
|
0
|
|
|
|
|
|
my $elt = XML::LibXML::Element->new($item->{nodename}); |
42
|
0
|
|
0
|
|
|
|
my $attrs = $item->{attributes} || {}; |
43
|
0
|
|
|
|
|
|
$elt->setAttribute($_, $attrs->{$_}) for keys %$attrs; |
44
|
0
|
0
|
|
|
|
|
for (@{ $item->{children} || [] }) { |
|
0
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if (!ref) { |
46
|
0
|
|
|
|
|
|
$elt->appendTextNode($_); |
47
|
|
|
|
|
|
|
} else { |
48
|
0
|
|
|
|
|
|
$elt->addChild(_item2elt($_)); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
|
$elt; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |