Skip to content

Instantly share code, notes, and snippets.

/clone.diff Secret

Created October 23, 2015 13:31
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/b1ec23ba686eb9cb31a5 to your computer and use it in GitHub Desktop.
Save anonymous/b1ec23ba686eb9cb31a5 to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/DOM/HTML.pm b/lib/Mojo/DOM/HTML.pm
index 97e1d25..59d5a29 100644
--- a/lib/Mojo/DOM/HTML.pm
+++ b/lib/Mojo/DOM/HTML.pm
@@ -3,6 +3,7 @@ use Mojo::Base -base;
use Mojo::Util qw(html_unescape xml_escape);
use Scalar::Util 'weaken';
+use Storable 'dclone';
has tree => sub { ['root'] };
has 'xml';
@@ -101,7 +102,10 @@ my %BLOCK = map { $_ => 1 } (
);
sub parse {
- my ($self, $html) = (shift, "$_[0]");
+ my ($self, $html) = @_;
+
+ return $self->tree(dclone $html->tree)->xml($html->xml)
+ if ref $html && $html->isa('Mojo::DOM');
my $xml = $self->xml;
my $current = my $tree = ['root'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment