The Perl Toolchain Summit 2025 Needs You: You can help 🙏 Learn more

NAME

Template::Refine::Fragment - represent and refine a fragment of HTML

SYNOPSIS

my $frag = Template::Refine::Fragment->new_from_string(
'<p>Hello, <span class="world"/>.' # invalid HTML ok
);
my $refined = $frag->process(
Template::Refine::Processor::Rule->new(
selector => Template::Refine::Processor::Rule::Select::XPath->new(
pattern => '//*[@class="world"]',
),
transformer => Template::Refine::Processor::Rule::Transform::Replace::WithText->new(
replacement => sub {
return 'world';
},
),
),
);
return $refined->render; # "<p>Hello, <span class="world">world</span>.</p>"

METHODS

new( fragment => $fragment )

Accepts one argument, fragment, which is the XML::LibXML::DocumentFragment that you want to operate on.

The constructors below are more useful.

new_from_dom( $dom )

Accepts an XML::LibXML::DOM object

new_from_string( $html_string )

Accepts an HTML string

new_from_file( $filename )

Accepts a filename containing HTML

fragment

Return the XML::LibXML::DocumentFragment that backs this object.

process( @rules )

Apply Template::Refine::Processor::Rules in @rules and return a new Template::Refine::Fragment.

render

Return the fragment as valid HTML

BUGS

Report to RT.

VERSION CONTROL

You can browse the repository at:

http://git.jrock.us/?p=Template-Refine.git;a=summary

You can clone the repository by typing:

Please e-mail me any patches. Thanks in advance for your help!

AUTHOR

Jonathan Rockway <jrockway@cpan.org>

COPYRIGHT

Copyright (c) 2008 Infinity Interactive. All rights reserved This
program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.