1 package HTML::Zoom::SelectorParser;
4 use warnings FATAL => 'all';
8 my $sel_re = qr/([$sel_char]+)/;
10 sub _raw_parse_simple_selector {
11 for ($_[1]) { # same pos() as outside
13 # '*' - match anything
18 # 'element' - match on tag name
23 sub { $_[0]->{name} && $_[0]->{name} eq $name }
26 # '#id' - match on id attribute
31 sub { $_[0]->{attrs}{id} && $_[0]->{attrs}{id} eq $id }
34 # '.class1.class2' - match on intersection of classes
36 /\G((?:\.$sel_re)+)/gc and
38 my $cls = $1; $cls =~ s/^\.//;
39 my @cl = split(/\./, $cls);
42 && !grep $_[0]->{attrs}{class} !~ /\b$_\b/, @cl
46 confess "Couldn't parse $_ as starting with simple selector";
52 my $sel = $_[1]; # my pos() only please
57 push(@sub, $self->_raw_parse_simple_selector($_));
58 last PARSE if (pos == length);
59 /\G\s*,\s*/gc or confess "Selectors not comma separated";
60 } until (pos == length) };
61 return $sub[0] if (@sub == 1);
63 foreach my $inner (@sub) {
64 if (my $r = $inner->(@_)) { return $r }