fix inject_after_scope again
Graham Knop [Tue, 18 Jun 2013 18:55:28 +0000 (14:55 -0400)]
lib/Filter/Keyword.pm
lib/Filter/Keyword/Filter.pm
lib/Filter/Keyword/Parser.pm

index 30db54d..11fd578 100644 (file)
@@ -145,13 +145,11 @@ sub have_match {
 
 sub inject_after_scope {
   my $inject = shift;
+  my $parser = $Filter::Keyword::Filter::ACTIVE_FILTERS[-1]->parser;
+
   on_scope_end {
-    filter_add(sub {
-      DEBUG && print $inject;
-      $_ = $inject;
-      filter_del;
-      1;
-    });
+    my $code = $parser->code;
+    $parser->code($inject . $code);
   };
 }
 
index b79160f..262b3b6 100644 (file)
@@ -25,14 +25,17 @@ sub _build_parser {
   );
 }
 
+our @ACTIVE_FILTERS;
 sub install {
   my ($self) = @_;
   return if $self->active;
+  push @ACTIVE_FILTERS, $self;
   $self->_set_active(1);
   filter_add($self);
   on_scope_end {
     $self->_set_active(0);
     filter_del;
+    pop @ACTIVE_FILTERS;
   };
   $self;
 }
index 9abe38e..860c237 100644 (file)
@@ -85,7 +85,7 @@ sub fetch_more {
 sub match_source {
   my ($self, $first, $second) = @_;
   $self->fetch_more while $self->code =~ /\A$first\s+\z/;
-  if (my @match = ($self->code =~ /(.*?${first}\s+${second})(.*\n?)\z/)) {
+  if (my @match = ($self->code =~ /(.*?${first}\s+${second})((?s).*)\z/)) {
     my $code = pop @match;
     $self->code($code);
     my $found = shift(@match);