add strictures commit (out of order)
[catagits/HTML-Zoom.git] / lib / HTML / Zoom / SelectorParser.pm
index 9bc7bc3..9e96980 100644 (file)
@@ -1,7 +1,6 @@
 package HTML::Zoom::SelectorParser;
 
-use strict;
-use warnings FATAL => 'all';
+use strictures 1;
 use base qw(HTML::Zoom::SubObject);
 use Carp qw(confess);
 
@@ -81,6 +80,28 @@ sub _raw_parse_simple_selector {
         }
       };
 
+    # '[attr~=bar]' - match attribute contains word
+    /\G\[$sel_re~=$match_value_re\]/gc and
+      return do {
+        my $attribute = $1;
+        my $value = $2;
+        sub {
+          $_[0]->{attrs}{$attribute}
+          && $_[0]->{attrs}{$attribute} =~ qr/\b\Q$value\E\b/;
+        }
+      };
+
+    # '[attr!=bar]' - match attribute contains prefix (for language matches)
+    /\G\[$sel_re\|=$match_value_re\]/gc and
+      return do {
+        my $attribute = $1;
+        my $value = $2;
+        sub {
+          $_[0]->{attrs}{$attribute}
+          && $_[0]->{attrs}{$attribute} =~ qr/^\Q$value\E(?:-|$)/;
+        }
+      };
+
     # '[attr=bar]' - match attributes
     /\G\[$sel_re=$match_value_re\]/gc and
       return do {
@@ -92,7 +113,18 @@ sub _raw_parse_simple_selector {
         }
       };
 
-    # '[attr] - match attribute being present:
+    # '[attr!=bar]' - attributes doesn't match
+    /\G\[$sel_re!=$match_value_re\]/gc and
+      return do {
+        my $attribute = $1;
+        my $value = $2;
+        sub {
+          ! ($_[0]->{attrs}{$attribute}
+          && $_[0]->{attrs}{$attribute} eq $value);
+        }
+      };
+
+    # '[attr]' - match attribute being present:
     /\G\[$sel_re\]/gc and
       return do {
         my $attribute = $1;