move matcher sub installation to keyword
[p5sagit/Filter-Keyword.git] / lib / Filter / Keyword.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);