Skip to content

Commit

Permalink
use a little less code in Mojo::DOM::CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 14, 2015
1 parent 2727039 commit 58d601c
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions lib/Mojo/DOM/CSS.pm
Expand Up @@ -24,11 +24,14 @@ sub select { _select(0, shift->tree, _compile(@_)) }
sub select_one { _select(1, shift->tree, _compile(@_)) }

sub _ancestor {
my ($selectors, $current, $tree, $pos) = @_;
my ($selectors, $current, $tree, $pos, $one) = @_;

while ($current = $current->[3]) {
return undef if $current->[0] eq 'root' || $current eq $tree;
return 1 if _combinator($selectors, $current, $tree, $pos);
last if $one;
}

return undef;
}

Expand Down Expand Up @@ -56,7 +59,7 @@ sub _combinator {
}

# ">" (parent only)
return _parent($selectors, $current, $tree, ++$pos) if $c eq '>';
return _ancestor($selectors, $current, $tree, ++$pos, 1) if $c eq '>';

# "~" (preceding siblings)
return _sibling($selectors, $current, $tree, 0, ++$pos) if $c eq '~';
Expand Down Expand Up @@ -138,13 +141,6 @@ sub _match {

sub _name {qr/(?:^|:)\Q@{[_unescape(shift)]}\E$/}

sub _parent {
my ($selectors, $current, $tree, $pos) = @_;
return undef unless my $parent = $current->[3];
return undef if $parent->[0] eq 'root' || $parent eq $tree;
return _combinator($selectors, $parent, $tree, $pos);
}

sub _pc {
my ($class, $args, $current) = @_;

Expand Down

0 comments on commit 58d601c

Please sign in to comment.