From: Matt S Trout Date: Fri, 28 May 2010 10:36:18 +0000 (+0100) Subject: clean up and fix selector parser code to match improved tests X-Git-Tag: release_0.009004~51 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTML-Zoom.git;a=commitdiff_plain;h=6818876e0628aa9f0abd811f35bcd8ec3b912a78 clean up and fix selector parser code to match improved tests --- diff --git a/lib/HTML/Zoom/SelectorParser.pm b/lib/HTML/Zoom/SelectorParser.pm index 4e4f11c..d3a505a 100644 --- a/lib/HTML/Zoom/SelectorParser.pm +++ b/lib/HTML/Zoom/SelectorParser.pm @@ -50,29 +50,35 @@ sub _raw_parse_simple_selector { # '[attr^=foo]' - match attribute with ^ anchored regex /\G\[$sel_re\^=$match_value_re\]/gc and - return do{ + return do { my $attribute = $1; my $value = $2; - $_[0]->{attrs}{$attribute} - && $_[0]->{attrs}{$attribute} =~ qr/^\Q$value\E/; + sub { + $_[0]->{attrs}{$attribute} + && $_[0]->{attrs}{$attribute} =~ qr/^\Q$value\E/; + } }; # '[attr$=foo]' - match attribute with $ anchored regex /\G\[$sel_re\$=$match_value_re\]/gc and - return do{ + return do { my $attribute = $1; my $value = $2; - $_[0]->{attrs}{$attribute} - && $_[0]->{attrs}{$attribute} =~ qr/\Q$value\E$/; + sub { + $_[0]->{attrs}{$attribute} + && $_[0]->{attrs}{$attribute} =~ qr/\Q$value\E$/; + } }; # '[attr*=foo] - match attribute with regex: /\G\[$sel_re\*=$match_value_re\]/gc and - return do{ + return do { my $attribute = $1; my $value = $2; - $_[0]->{attrs}{$attribute} - && $_[0]->{attrs}{$attribute} =~ qr/\Q$value\E$/; + sub { + $_[0]->{attrs}{$attribute} + && $_[0]->{attrs}{$attribute} =~ qr/\Q$value\E/; + } }; # '[attr=bar]' - match attributes @@ -80,7 +86,7 @@ sub _raw_parse_simple_selector { return do { my $attribute = $1; my $value = $2; - sub{ + sub { $_[0]->{attrs}{$attribute} && $_[0]->{attrs}{$attribute} eq $value; } @@ -90,7 +96,9 @@ sub _raw_parse_simple_selector { /\G\[$sel_re\]/gc and return do { my $attribute = $1; - $_[0]->{attrs}{$attribute}; + sub { + exists $_[0]->{attrs}{$attribute}; + } } } }