ignore if attr doesn't exist.
Simon Elliott [Sat, 4 Jun 2011 14:17:52 +0000 (15:17 +0100)]
lib/HTML/Zoom/FilterBuilder.pm
t/actions.t

index 3c44a7c..5135e32 100644 (file)
@@ -83,13 +83,15 @@ sub remove_from_attribute {
   my $self = shift;
   my $attr = $self->_parse_attribute_args(@_);
   sub {
+
     my $a = (my $evt = $_[0])->{attrs};
+    my @kupd = grep {exists $a->{$_}} keys %$attr;
     +{ %$evt, raw => undef, raw_attrs => undef,
        attrs => {
          %$a,
          #TODO needs to support multiple removes
          map { my $tar = $_; $_ => join ' ', 
-          map {$attr->{$tar} ne $_} split ' ', $a->{$_} } keys %$attr
+          map {$attr->{$tar} ne $_} split ' ', $a->{$_} } @kupd
       },
     }
   };
index 1b8b1fb..d1dcc54 100644 (file)
@@ -125,6 +125,20 @@ is(
   'remove name from attribute'
 );
 
+is(
+  run_for { $_->remove_from_attribute({ madeup => 'main' }) },
+  $tmpl,
+  'remove name from non existing attribute (ignored)'
+);
+
+($expect = $tmpl) =~ s/class="main"/class=""/;
+
+is(
+  run_for { $_->remove_class( 'main' ) },
+  $expect,
+  'remove_class'
+);
+
 ($expect = $tmpl) =~ s/ class="main"//;
 
 is(