Skip to content

Instantly share code, notes, and snippets.

/clone.diff Secret

Created October 23, 2015 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/eb4ca47836d1a26e7f2c to your computer and use it in GitHub Desktop.
Save anonymous/eb4ca47836d1a26e7f2c to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/DOM.pm b/lib/Mojo/DOM.pm
index 2bda8b1..86ee7f1 100644
--- a/lib/Mojo/DOM.pm
+++ b/lib/Mojo/DOM.pm
@@ -15,6 +15,7 @@ use Mojo::DOM::CSS;
use Mojo::DOM::HTML;
use Mojo::Util 'squish';
use Scalar::Util qw(blessed weaken);
+use Storable 'dclone';
sub all_text { shift->_all_text(1, @_) }
@@ -280,7 +281,11 @@ sub _offset {
sub _parent { $_[0]->tree->[$_[0]->type eq 'tag' ? 3 : 2] }
-sub _parse { Mojo::DOM::HTML->new(xml => shift->xml)->parse(shift)->tree }
+sub _parse {
+ my ($self, $html) = @_;
+ return dclone $html->tree if blessed $html && $html->isa('Mojo::DOM');
+ return Mojo::DOM::HTML->new(xml => $self->xml)->parse($html)->tree;
+}
sub _replace {
my ($self, $parent, $tree, $new) = @_;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment