NAME

Template::Refine::Utils - sugar up some common Template::Refine operations

SYNOPSIS

use Template::Refine::Fragment;
use Template::Refine::Utils qw(simple_replace replace_text);

my $f = Template::Refine::Fragment->new_from_string('<p>Hello</p>');
say $f->process(
    simple_replace {
        my $n = shift;
        replace_text $n, 'Goodbye'
    } '//p',
)->render; # prints <p>Goodbye</p>

EXPORT

None by default. You can request simple_replace and replace_text. This module use Sub::Exporter, so you can rename the imports if you like.

API STABILITY

I will probably add more utilities here in future releases.

FUNCTIONS

replace_text( $node, $text )

This makes a copy of $node and replaces the copied node's children with a text node containing $text.

As an example, if you pass in a node that looks like <p>Hello, <b>world</b>.</p> and the text Foo, the result will be <p>Foo</p>.

simple_replace BLOCK $xpath

Generates a Template::Refine::Processor::Rule that selects nodes matching the xpath and transforms them with the provided BLOCK.

This will save you a lot of typing.

SEE ALSO

Template::Refine::Fragment

XML::LibXML

XML::LibXML::Node

XML::LibXML::Element

XML::LibXML::Text