move matcher sub installation to keyword
Graham Knop [Tue, 18 Jun 2013 08:23:15 +0000 (04:23 -0400)]
lib/Filter/Keyword.pm
lib/Filter/Keyword/Parser.pm

index 34cc098..2671ea0 100644 (file)
@@ -7,6 +7,7 @@ use Scalar::Util qw(weaken);
 use Package::Stash::PP;
 use B qw(svref_2object);
 use B::Hooks::EndOfScope;
+use Scalar::Util qw(set_prototype);
 
 sub _compiling_file () {
   my $depth = 0;
@@ -104,6 +105,15 @@ sub save_refcount {
   $self->globref_refcount(svref_2object($self->globref)->REFCNT);
 }
 
+sub install_matcher {
+  my ($self, $post) = @_;
+  my $stash = $self->stash;
+  my $sub = sub {};
+  set_prototype(\&$sub, '*;@') unless $post eq '(';
+  { no warnings 'redefine', 'prototype'; *{$self->globref} = $sub; }
+  $self->save_refcount;
+}
+
 sub have_match {
   my ($self) = @_;
   return 0 unless defined($self->globref_refcount);
index 9382ceb..2c80ad3 100644 (file)
@@ -1,8 +1,6 @@
 package Filter::Keyword::Parser;
 use Moo;
 
-use Scalar::Util qw(set_prototype);
-
 has reader => (is => 'ro', required => 1);
 
 has re_add => (is => 'ro', required => 1);
@@ -79,10 +77,7 @@ sub check_match {
             $keyword->keyword_name, qr/(\(|[A-Za-z][A-Za-z_0-9]*|{)/
           )
     ) {
-      my $sub = sub {};
-      set_prototype(\&$sub, '*;@') unless $matches->[0] eq '(';
-      { no warnings 'redefine'; *{$keyword->globref} = $sub; }
-      $keyword->save_refcount;
+      $keyword->install_matcher($matches->[0]);
       $self->current_match($matches);
       $self->short_circuit(1);
       return ($stripped, 1);