Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
better names for a few functions
  • Loading branch information
kraih committed Dec 30, 2013
1 parent ac79e79 commit 8de63d8
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/Mojo/DOM.pm
Expand Up @@ -125,7 +125,7 @@ sub prepend { shift->_add(0, @_) }
sub prepend_content {
my ($self, $new) = @_;
my $tree = $self->tree;
splice @$tree, _offset($tree), 0, _link($self->_parse("$new"), $tree);
splice @$tree, _start($tree), 0, _link($self->_parse("$new"), $tree);
return $self;
}

Expand All @@ -143,7 +143,7 @@ sub replace {
sub replace_content {
my ($self, $new) = @_;
my $tree = $self->tree;
splice @$tree, _offset($tree), $#$tree, _link($self->_parse("$new"), $tree);
splice @$tree, _start($tree), $#$tree, _link($self->_parse("$new"), $tree);
return $self;
}

Expand Down Expand Up @@ -216,7 +216,7 @@ sub _add {
return $self if (my $tree = $self->tree)->[0] eq 'root';

my $parent = $tree->[3];
splice @$parent, _parent($parent, $tree) + $offset, 0,
splice @$parent, _offset($parent, $tree) + $offset, 0,
_link($self->_parse("$new"), $parent);

return $self;
Expand Down Expand Up @@ -267,14 +267,12 @@ sub _link {

sub _nodes {
return unless my $tree = shift;
return @$tree[_offset($tree) .. $#$tree];
return @$tree[_start($tree) .. $#$tree];
}

sub _offset { $_[0][0] eq 'root' ? 1 : 4 }

sub _parent {
sub _offset {
my ($parent, $child) = @_;
my $i = _offset($parent);
my $i = _start($parent);
$_ eq $child ? last : $i++ for @$parent[$i .. $#$parent];
return $i;
}
Expand All @@ -286,7 +284,7 @@ sub _render { Mojo::DOM::HTML->new(tree => shift, xml => shift)->render }
sub _replace {
my ($self, $tree, $new) = @_;
my $parent = $tree->[3];
splice @$parent, _parent($parent, $tree), 1, _link($new, $parent);
splice @$parent, _offset($parent, $tree), 1, _link($new, $parent);
return $self->parent;
}

Expand All @@ -310,6 +308,8 @@ sub _siblings {
return $merge ? [@before, @after] : [\@before, \@after];
}

sub _start { $_[0][0] eq 'root' ? 1 : 4 }

sub _text {
my ($nodes, $recurse, $trim) = @_;

Expand Down

0 comments on commit 8de63d8

Please sign in to comment.