Skip to content

Commit

Permalink
support old versions of Perl again
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 1, 2017
1 parent d9bdf4e commit c2dd40e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/Mojo/DOM.pm
Expand Up @@ -100,8 +100,8 @@ sub new {
return @_ ? $self->parse(@_) : $self;
}

sub next { $_[0]->_maybe($_[0]->_siblings(1, 1)->[0]) }
sub next_node { $_[0]->_maybe($_[0]->_siblings(0, 1)->[0]) }
sub next { $_[0]->_maybe($_[0]->_siblings(1, 1, 0)) }
sub next_node { $_[0]->_maybe($_[0]->_siblings(0, 1, 0)) }

sub parent {
my $self = shift;
Expand All @@ -117,8 +117,8 @@ sub preceding_nodes { $_[0]->_collect($_[0]->_siblings(0)) }
sub prepend { shift->_add(0, @_) }
sub prepend_content { shift->_content(0, 0, @_) }

sub previous { $_[0]->_maybe($_[0]->_siblings(1, 0)->[-1]) }
sub previous_node { $_[0]->_maybe($_[0]->_siblings(0, 0)->[-1]) }
sub previous { $_[0]->_maybe($_[0]->_siblings(1, 0, -1)) }
sub previous_node { $_[0]->_maybe($_[0]->_siblings(0, 0, -1)) }

sub remove { shift->replace('') }

Expand Down Expand Up @@ -285,19 +285,20 @@ sub _replace {
sub _select { $_[1] ? $_[0]->grep(matches => $_[1]) : $_[0] }

sub _siblings {
my ($self, $tags, $tail) = @_;
my ($self, $tags, $tail, $i) = @_;

my $tree = $self->tree;
return [] unless my $parent = $tree->[0] eq 'root' ? undef : _parent($tree);
return defined $i ? undef : [] if (my $tree = $self->tree)->[0] eq 'root';

my $nodes = _nodes($parent);
my $nodes = _nodes(_parent($tree));
my $match = -1;
defined($match++) and $_ eq $tree and last for @$nodes;

if ($tail) { splice @$nodes, 0, $match + 1 }
else { splice @$nodes, $match, ($#$nodes + 1) - $match }

return $tags ? [grep { $_->[0] eq 'tag' } @$nodes] : $nodes;
@$nodes = grep { $_->[0] eq 'tag' } @$nodes if $tags;

return defined $i ? $i == -1 && !@$nodes ? undef : $nodes->[$i] : $nodes;
}

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

0 comments on commit c2dd40e

Please sign in to comment.