Skip to content

Commit

Permalink
improved wrap method in Mojo::DOM to allow wrapping of the root node
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 5, 2014
1 parent 9ecfcd1 commit fc47fbb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,6 +1,7 @@

4.77 2014-02-05
- Added wrap_content method to Mojo::DOM.
- Improved wrap method in Mojo::DOM to allow wrapping of the root node.

4.76 2014-02-04
- Added wrap method to Mojo::DOM.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/DOM.pm
Expand Up @@ -378,7 +378,7 @@ sub _trim {
sub _wrap {
my ($self, $content, $new) = @_;

return $self if (my $tree = $self->tree)->[0] eq 'root' && !$content;
$content = 1 if (my $tree = $self->tree)->[0] eq 'root';

# Find innermost tag
my $current;
Expand Down
5 changes: 3 additions & 2 deletions t/mojo/dom.t
Expand Up @@ -2012,8 +2012,9 @@ is $dom->all_text, 'Mojo Test', 'right text';

# Wrap elements
$dom = Mojo::DOM->new('<a>Test</a>');
is $dom->wrap('<no></no>')->root->to_xml, '<a>Test</a>', 'right result';
is $dom->at('a')->wrap('A')->type, 'a', 'right element';
is $dom->wrap('<b></b>')->node, 'root', 'right node';
is "$dom", '<b><a>Test</a></b>', 'right result';
is $dom->at('b')->strip->at('a')->wrap('A')->type, 'a', 'right element';
is "$dom", '<a>Test</a>', 'right result';
is $dom->at('a')->wrap('<b></b>')->type, 'a', 'right element';
is "$dom", '<b><a>Test</a></b>', 'right result';
Expand Down

0 comments on commit fc47fbb

Please sign in to comment.