- SEE ALSO
- COPYRIGHT AND LICENSE
HTML::Manipulator::Document - object-oriented interface to HTML::Manipulator (with some added features)
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');
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.
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.
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.
my $new = HTML::Manipulator::replace($html, title => 'New news', headline77=>'All clear?');
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.
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.
Use this method to get the HTML content from the object.
This method lets you save the HTML content of the object to a 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.
Thilo Planz, <firstname.lastname@example.org>
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.