Skip to content

Commit

Permalink
added another wrap example
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 4, 2014
1 parent 57f1d72 commit a453d84
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/Mojo/DOM.pm
Expand Up @@ -133,8 +133,7 @@ sub remove { shift->replace('') }

sub replace {
my ($self, $new) = @_;
my $tree = $self->tree;
return $self->parse($new) if $tree->[0] eq 'root';
return $self->parse($new) if (my $tree = $self->tree)->[0] eq 'root';
return $self->_replace($tree, $self->_parse("$new"));
}

Expand All @@ -150,8 +149,7 @@ sub siblings { _select(Mojo::Collection->new(@{_siblings($_[0], 1)}), $_[1]) }

sub strip {
my $self = shift;
my $tree = $self->tree;
return $self if $tree->[0] eq 'root';
return $self if (my $tree = $self->tree)->[0] eq 'root';
return $self->_replace($tree, ['root', _nodes($tree)]);
}

Expand Down Expand Up @@ -204,10 +202,9 @@ sub type {
sub wrap {
my ($self, $new) = @_;

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

# Find innermost tag
# Find inmost tag
my $current;
my $first = $new = $self->_parse("$new");
$current = $first while $first = first { $_->[0] eq 'tag' } _nodes($first);
Expand Down Expand Up @@ -815,13 +812,16 @@ This element's type.
=head2 wrap
$dom = $dom->wrap('<div></div>');
$dom = $dom->wrap('<p></p>');
Wrap HTML/XML fragment around this element.
# "<div><h1>A</h1>B</div>"
$dom->parse('<h1>A</h1>')->at('h1')->wrap('<div>B</div>')->root;
# "<div><div><h1>A</h1></div>B</div>"
$dom->parse('<h1>A</h1>')->at('h1')->wrap('<div><div></div>B</div>')->root;
=head2 xml
my $bool = $dom->xml;
Expand Down

0 comments on commit a453d84

Please sign in to comment.