After parsing an HTML file with HTML::TreeBuilder one gets back a large nested data structure:
my $tree = HTML::TreeBuilder->new_from_file($filename);
In the interest of efficiency, I would like to develop Perl modules which have the HTML parsed and already in-memory at mod_perl startup time:
package html::page::hello_world;
my $tree = HTML::TreeBuilder->new_from_file('/html/hello_world.html');
sub new {
$tree
}
1;
This way, the module is used at server startup time and the constructor call incurs no delay due to parsing the HTML file. However, there is one problem: once the returned tree is modified, the new would return that same modified tree instead of a tree representing a fresh parse of the HTML file.
I therefore want to clone the tree and return a clone:
package html::page::hello_world;
my $tree = HTML::TreeBuilder->new_from_file('/html/hello_world.html');
my $clone = $tree->clone;
sub new {
my $retval = $clone;
$clone = $tree->clone;
$retval;
}
1;
But I don't want the overhead of making the new clone in the same process. I want to do something like a fork and return the pre-made clone to the caller immediately so it doesn't have to wait and manufacture a new clone in a separate thread/process.
Could anyone recommend a strategy/module for doing this?
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |