# '[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
return do {
my $attribute = $1;
my $value = $2;
- sub{
+ sub {
$_[0]->{attrs}{$attribute}
&& $_[0]->{attrs}{$attribute} eq $value;
}
/\G\[$sel_re\]/gc and
return do {
my $attribute = $1;
- $_[0]->{attrs}{$attribute};
- }
+ sub {
+ exists $_[0]->{attrs}{$attribute};
+ }
+ };
+
+ # none of the above matched, try catching some obvious errors:
+
+ # indicate unmatched square bracket:
+ /\G\[[^\]]*/gc and $_[0]->_blam('Unmatched [');
}
}