merge wrap fixes from Mojolicious 6.34
Dan Book [Fri, 4 Dec 2015 18:01:08 +0000 (13:01 -0500)]
.travis.yml
Changes
README.pod
lib/DOM/Tiny.pm
t/dom.t

index ed5c2e7..e4734d6 100644 (file)
@@ -1,5 +1,6 @@
 language: perl
 perl:
+  - "5.22"
   - "5.20"
   - "5.18"
   - "5.16"
diff --git a/Changes b/Changes
index 4f1671b..4bc93f7 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,6 @@
 {{$NEXT}}
   - Merge several CSS bugfixes and improvements from Mojolicious 6.31 and 6.32.
+  - Merge wrap and wrap_content bugfixes from Mojolicious 6.34.
 
 0.002     2015-11-09 19:28:42 EST
   - Support perl 5.8 (mst)
index 29e6d47..a033942 100644 (file)
@@ -394,7 +394,7 @@ objects. All selectors listed in L</"SELECTORS"> are supported.
 
   $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>')
@@ -662,7 +662,7 @@ before this node as L<DOM::Tiny> objects.
 
   $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>')
@@ -866,8 +866,8 @@ C<undef> if none could be found.
 
   $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;
@@ -885,8 +885,8 @@ first innermost element.
 
   $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;
index febc2a5..f7da74c 100644 (file)
@@ -364,8 +364,8 @@ sub _text {
 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;
@@ -782,7 +782,7 @@ objects. All selectors listed in L</"SELECTORS"> are supported.
 
   $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>')
@@ -1050,7 +1050,7 @@ before this node as L<DOM::Tiny> objects.
 
   $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>')
@@ -1254,8 +1254,8 @@ C<undef> if none could be found.
 
   $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;
@@ -1273,8 +1273,8 @@ first innermost element.
 
   $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;
diff --git a/t/dom.t b/t/dom.t
index a6b8a72..0a55239 100644 (file)
--- a/t/dom.t
+++ b/t/dom.t
@@ -243,6 +243,8 @@ is $dom->at('b')->child_nodes->[1]->next, undef, 'no siblings';
 is $dom->at('script')->child_nodes->first->wrap('<i>:)</i>')->root,
   '<script><i>:)a</i><b>fce</b>1<b>d</b></script>', 'right result';
 is $dom->at('i')->child_nodes->first->wrap_content('<b></b>')->root,
+  '<script><i>:)a</i><b>fce</b>1<b>d</b></script>', 'no changes';
+is $dom->at('i')->child_nodes->first->wrap('<b></b>')->root,
   '<script><i><b>:)</b>a</i><b>fce</b>1<b>d</b></script>', 'right result';
 is $dom->at('b')->child_nodes->first->ancestors->map('tag')->join(','),
   'b,i,script', 'right result';
@@ -1270,8 +1272,9 @@ is "$dom", <<EOF, 'right result';
 EOF
 is $dom->at('div')->text, 'A-1', 'right text';
 is $dom->at('iv'), undef, 'no result';
-$dom->prepend('l')->prepend('alal')->prepend('a');
-is "$dom", <<EOF, 'no change';
+is $dom->prepend('l')->prepend('alal')->prepend('a')->type, 'root',
+  'right type';
+is "$dom", <<EOF, 'no changes';
 <ul>
     24<div>A-1</div>25<li>A</li><p>A1</p>23
     <p>B</p>
@@ -1279,8 +1282,8 @@ is "$dom", <<EOF, 'no change';
 </ul>
 <div>D</div>
 EOF
-$dom->append('lalala');
-is "$dom", <<EOF, 'no change';
+is $dom->append('lalala')->type, 'root', 'right type';
+is "$dom", <<EOF, 'no changes';
 <ul>
     24<div>A-1</div>25<li>A</li><p>A1</p>23
     <p>B</p>
@@ -2125,7 +2128,10 @@ is $dom->all_text, 'DOM Test', 'right text';
 
 # Wrap elements
 $dom = DOM::Tiny->new('<a>Test</a>');
+is "$dom", '<a>Test</a>', 'right result';
 is $dom->wrap('<b></b>')->type, 'root', 'right type';
+is "$dom", '<a>Test</a>', 'no changes';
+is $dom->at('a')->wrap('<b></b>')->type, 'tag', 'right type';
 is "$dom", '<b><a>Test</a></b>', 'right result';
 is $dom->at('b')->strip->at('a')->wrap('A')->tag, 'a', 'right tag';
 is "$dom", '<a>Test</a>', 'right result';