| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package XML::Overlay; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24659
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
32
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
27
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use vars qw/$VERSION/; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
7331
|
|
|
6
|
1
|
|
|
1
|
|
12
|
use base qw/Class::XML/; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
2219
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$VERSION = "0.01"; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
__PACKAGE__->has_children('target' => 'XML::Overlay::target'); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub process { |
|
13
|
|
|
|
|
|
|
my ($self, $context) = @_; |
|
14
|
|
|
|
|
|
|
my @changes; |
|
15
|
|
|
|
|
|
|
foreach ($self->target) { |
|
16
|
|
|
|
|
|
|
push(@changes, $_->action_closure($context)); |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
foreach (@changes) { |
|
19
|
|
|
|
|
|
|
$_->(); |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 NAME |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
XML::Overlay - Apply overlays to XML documents |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Original XML document: |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Overlay document: |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
bar |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $o_tree = XML::Overlay->new(xml => $o_source); # Load overlay doc |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $d_tree = Class::XML->new(xml => $d_source); # Load initial doc |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$o_tree->process($d_tree); |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
print "${d_tree}"; # Class::XML used above for overloaded stringify |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Outputs: |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
XML::Overlay is a simple collection of Class::XML modules that provide a |
|
79
|
|
|
|
|
|
|
mechanism somewhat inspired by Mozilla's XUL Overlays, but designed for |
|
80
|
|
|
|
|
|
|
manipulating general XML documents. The overlay document contains one or more |
|
81
|
|
|
|
|
|
|
B elements, each with an B attribute which specifies what nodes |
|
82
|
|
|
|
|
|
|
of the source document should be captured and transformed; each B |
|
83
|
|
|
|
|
|
|
element contains one or more B elements which specifies the action(s) |
|
84
|
|
|
|
|
|
|
to perform on each XPath node captured by the parent. |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Note that the XPath tree is modified in-place, so ensure you process a copy if |
|
87
|
|
|
|
|
|
|
you want your original document intact afterwards as well! |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 DETAILS |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 Tags |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head3 Overlay |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
The root of an XML::Overlay document; any attributes are ignored, as are any |
|
96
|
|
|
|
|
|
|
children that aren't a B tag |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head3 target |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Has a single significant attribute, B, which specifies an XPath |
|
101
|
|
|
|
|
|
|
expression that is evaluated against the document being transformed to work |
|
102
|
|
|
|
|
|
|
out which nodes this transform should target. Its only significant children |
|
103
|
|
|
|
|
|
|
are B tags, which each specify a single action which is performed in |
|
104
|
|
|
|
|
|
|
order of the tags' appearance against the target nodeset. Any other children |
|
105
|
|
|
|
|
|
|
and attributes are ignored. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head3 action |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Has two significant attributes, B and B; B specifies |
|
110
|
|
|
|
|
|
|
the type of action to be performed (see below for a full list). B |
|
111
|
|
|
|
|
|
|
names the attribute to be affected by actions which act upon attributes of the |
|
112
|
|
|
|
|
|
|
target node(s). |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 Allowable B types |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head3 setAttribute |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Sets the attribute specified by the B attribute on the B |
|
119
|
|
|
|
|
|
|
tag to the string value of the tag's contents |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head3 removeAttribute |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Removed the attribute specified by the B attribute on the B |
|
124
|
|
|
|
|
|
|
tag |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head3 appendChild |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Appends the contents of the B tag at the end of the child nodes of the |
|
129
|
|
|
|
|
|
|
target node(s) |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head3 insertBefore |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Inserts the contents of the B tag before each target node |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head3 insertAfter |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Inserts the contents of the B tag after each target node |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head3 delete |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Deletes all target nodes and any children thereof |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 AUTHOR |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Matt S Trout |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 LICENSE |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
150
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |