sub _wrap {
my ($self, $content, $new) = @_;
- $content = 1 if (my $tree = $self->tree)->[0] eq 'root';
- $content = 0 if $tree->[0] ne 'root' && $tree->[0] ne 'tag';
+ return $self if (my $tree = $self->tree)->[0] eq 'root' && !$content;
+ return $self if $tree->[0] ne 'root' && $tree->[0] ne 'tag' && $content;
# Find innermost tag
my $current;
$dom = $dom->append('<p>I ♥ DOM::Tiny!</p>');
-Append HTML/XML fragment to this node.
+Append HTML/XML fragment to this node (for all node types other than C<root>).
# "<div><h1>Test</h1><h2>123</h2></div>"
$dom->parse('<div><h1>Test</h1></div>')
$dom = $dom->prepend('<p>I ♥ DOM::Tiny!</p>');
-Prepend HTML/XML fragment to this node.
+Prepend HTML/XML fragment to this node (for all node types other than C<root>).
# "<div><h1>Test</h1><h2>123</h2></div>"
$dom->parse('<div><h2>123</h2></div>')
$dom = $dom->wrap('<div></div>');
-Wrap HTML/XML fragment around this node, placing it as the last child of the
-first innermost element.
+Wrap HTML/XML fragment around this node (for all node types other than C<root>),
+placing it as the last child of the first innermost element.
# "<p>123<b>Test</b></p>"
$dom->parse('<b>Test</b>')->at('b')->wrap('<p>123</p>')->root;
$dom = $dom->wrap_content('<div></div>');
-Wrap HTML/XML fragment around this node's content, placing it as the last
-children of the first innermost element.
+Wrap HTML/XML fragment around this node's content (for C<root> and C<tag>
+nodes), placing it as the last children of the first innermost element.
# "<p><b>123Test</b></p>"
$dom->parse('<p>Test<p>')->at('p')->wrap_content('<b>123</b>')->root;