NAME

HTML::Manipulator::Document - object-oriented interface to HTML::Manipulator (with some added features)

SYNOPSIS

use HTML::Manipulator::Document;

my $doc = HTML::Manipulator::Document->from_file('test.html');
print $doc->replace('headline'=>'New Headline');

print $doc->as_string;

$doc->save_as('/some/file.html');

DESCRIPTION

This module provides an object-oriented interface to the functions of the HTML::Manipulator module. It also has the additional features to load HTML from and save it to a file.

You use it by calling one of the two constructor methods, which return an object of this class. The object has methods that mirror the functions of HTML::Manipulator.

Constructors

Instances can be be created from HTML documents in memory (contained in a string) or from a file.

my $doc = HTML::Manipulator::Document->from_string('<html>blah</html>');

my $doc = HTML::Manipulator::Document->from_file('test.html');

The from_file() constructor takes a file handle or a file name.

HTML::Manipulator methods

All of the functions of HTML::Manipulator are available as methods.

In HTML::Manipulator, the first parameter is always the HTML text. In the object-oriented interface the HTML document was already specified in the constructor, making the parameter obsolete. You must therefore omit that first parameter.

For example

my $new = HTML::Manipulator::replace($html, 
     title => 'New news', headline77=>'All clear?');

becomes

my $obj = HTML::Manipulator::Document->from_string($html);
my $new = $obj->replace(
	 title => 'New news', headline77=>'All clear?');

The methods return the same results as the functions they wrap. See HTML::Manipulator for details on what functions there are and how they work.

replace and insert methods

In addition to returning the new HTML text, the replace and insert groups of methods also change the content of the HTML document represented by the object.

as_string() method

Use this method to get the HTML content from the object.

save_as() method

This method lets you save the HTML content of the object to a file:

$doc->save_as('/path/to/file');

Any missing directories leading up to the file will be created automatically (if possible). If the file could not be created, the method croaks.

SEE ALSO

HTML::Manipulator

perltoot

AUTHOR

Thilo Planz, <thilo@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2004/05 by Thilo Planz

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.