X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FHTML%2FZoom%2FSelectorParser.pm;h=aba112376414ef384241b804567a5a9ee3f65b9b;hb=03e514ef00966bd6299310fded151dd0304d4fc3;hp=7d3c6a52b00897a492794c9a415646c24537bb5d;hpb=456a815dd80c8a43c7d5a04d353377426a94048f;p=catagits%2FHTML-Zoom.git diff --git a/lib/HTML/Zoom/SelectorParser.pm b/lib/HTML/Zoom/SelectorParser.pm index 7d3c6a5..aba1123 100644 --- a/lib/HTML/Zoom/SelectorParser.pm +++ b/lib/HTML/Zoom/SelectorParser.pm @@ -2,6 +2,7 @@ package HTML::Zoom::SelectorParser; use strict; use warnings FATAL => 'all'; +use base qw(HTML::Zoom::SubObject); use Carp qw(confess); my $sel_char = '-\w_'; @@ -17,6 +18,19 @@ sub _raw_parse_simple_selector { /\G\*/gc and return sub { 1 }; + # 'el[attr="foo"] + + /\G$sel_re\[$sel_re="$sel_re"\]/gc and + return do { + my $name = $1; + my $attr = $2; + my $val = $3; + sub { + $_[0]->{name} && $_[0]->{name} eq $name and + $_[0]->{attrs}{$attr} && $_[0]->{attrs}{$attr} eq $val + } + }; + # 'element' - match on tag name /\G$sel_re/gc and @@ -41,7 +55,31 @@ sub _raw_parse_simple_selector { my @cl = split(/\./, $cls); sub { $_[0]->{attrs}{class} - && !grep $_[0]->{attrs}{class} !~ /\b$_\b/, @cl + && !grep $_[0]->{attrs}{class} !~ /(^|\s+)$_($|\s+)/, @cl + } + }; + + # 'el.class1' - element + class + + /\G$sel_re\.$sel_re/gc and + return do { + my $cls = $1; + my $name = $2; + sub { + $_[0]->{name} && $_[0]->{name} eq $name and + $_[0]->{attrs}{class} && $_[0]->{attrs}{class} eq $cls + } + }; + + # 'el#id' - element + id + + /\G$sel_re#$sel_re/gc and + return do { + my $id = $1; + my $name = $2; + sub { + $_[0]->{name} && $_[0]->{name} eq $name and + $_[0]->{attrs}{id} && $_[0]->{attrs}{id} eq $id } }; @@ -59,7 +97,7 @@ sub parse_selector { PARSE: { do { push(@sub, $self->_raw_parse_simple_selector($_)); last PARSE if (pos == length); - /\G\s*,\s*/gc or confess "Selectors not comma separated"; + #/\G\s*,\s*/gc or confess "Selectors not comma separated"; } until (pos == length) }; return $sub[0] if (@sub == 1); return sub { @@ -68,7 +106,7 @@ sub parse_selector { } }; } -} - +} + 1;