package XML::Overlay; use strict; use warnings; use vars qw/$VERSION/; use base qw/Class::XML/; $VERSION = "0.01"; __PACKAGE__->has_children('target' => 'XML::Overlay::target'); sub process { my ($self, $context) = @_; my @changes; foreach ($self->target) { push(@changes, $_->action_closure($context)); } foreach (@changes) { $_->(); } } =head1 NAME XML::Overlay - Apply overlays to XML documents =head1 SYNOPSIS # Original XML document: # Overlay document: bar my $o_tree = XML::Overlay->new(xml => $o_source); # Load overlay doc my $d_tree = Class::XML->new(xml => $d_source); # Load initial doc $o_tree->process($d_tree); print "${d_tree}"; # Class::XML used above for overloaded stringify # Outputs: =head1 DESCRIPTION XML::Overlay is a simple collection of Class::XML modules that provide a mechanism somewhat inspired by Mozilla's XUL Overlays, but designed for manipulating general XML documents. The overlay document contains one or more B elements, each with an B attribute which specifies what nodes of the source document should be captured and transformed; each B element contains one or more B elements which specifies the action(s) to perform on each XPath node captured by the parent. Note that the XPath tree is modified in-place, so ensure you process a copy if you want your original document intact afterwards as well! =head1 DETAILS =head2 Tags =head3 Overlay The root of an XML::Overlay document; any attributes are ignored, as are any children that aren't a B tag =head3 target Has a single significant attribute, B, which specifies an XPath expression that is evaluated against the document being transformed to work out which nodes this transform should target. Its only significant children are B tags, which each specify a single action which is performed in order of the tags' appearance against the target nodeset. Any other children and attributes are ignored. =head3 action Has two significant attributes, B and B; B specifies the type of action to be performed (see below for a full list). B names the attribute to be affected by actions which act upon attributes of the target node(s). =head2 Allowable B types =head3 setAttribute Sets the attribute specified by the B attribute on the B tag to the string value of the tag's contents =head3 removeAttribute Removed the attribute specified by the B attribute on the B tag =head3 appendChild Appends the contents of the B tag at the end of the child nodes of the target node(s) =head3 insertBefore Inserts the contents of the B tag before each target node =head3 insertAfter Inserts the contents of the B tag after each target node =head3 delete Deletes all target nodes and any children thereof =head1 AUTHOR Matt S Trout =head1 LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1;