]> git.vpit.fr Git - perl/modules/Sub-Op.git/blobdiff - lib/Sub/Op.pm
Rename the "len" member of the sub_op_config_t struct to "namelen"
[perl/modules/Sub-Op.git] / lib / Sub / Op.pm
index 0085cb1eadd14bb8ba4d68ab1a8fc2b645cde6bc..6b421c4be5a17f3f6b3a9a2f91e63386c48f53b5 100644 (file)
@@ -50,11 +50,11 @@ In your XS file :
     BOOT:
     {
      sub_op_config_t c;
-     c.name  = "reftype";
-     c.len   = sizeof("reftype")-1;
-     c.pp    = scalar_util_reftype;
-     c.check = 0;
-     c.ud    = NULL;
+     c.name    = "reftype";
+     c.namelen = sizeof("reftype")-1;
+     c.pp      = scalar_util_reftype;
+     c.check   = 0;
+     c.ud      = NULL;
      sub_op_register(aTHX_ &c);
     }
 
@@ -142,8 +142,14 @@ my $sw = Variable::Magic::wizard(
   my $pkg = $data->{pkg};
   my $fqn = join '::', $pkg, $name;
 
-  no strict 'refs';
-  *$fqn = $placeholder unless exists &$fqn;
+  {
+   local $SIG{__WARN__} = sub {
+    CORE::warn(@_) unless $_[0] =~ /^Constant subroutine.*redefined/;
+   } if _constant_sub(do { no strict 'refs'; \&$fqn });
+   no strict 'refs';
+   no warnings 'redefine';
+   *$fqn = $placeholder;
+  }
 
   return;
  },
@@ -155,6 +161,7 @@ sub _tag {
  my $fqn = join '::', $pkg, $name;
 
  return {
+  old   => _defined_sub($fqn) ? \&$fqn : undef,
   proto => prototype($fqn),
  };
 }
@@ -208,7 +215,7 @@ Allowed to be static.
 
 =item *
 
-C<STRLEN len>
+C<STRLEN namelen>
 
 C<name>'s length, in bytes.
 
@@ -296,11 +303,22 @@ sub disable {
  my $pkg = @_ > 0 ? $_[0] : caller;
  my $map = _map($pkg);
 
+ my $fqn = join '::', $pkg, $name;
+
  if (defined $map) {
-  my $proto = $map->{$name}->{proto};
+  my $tag = $map->{$name};
+
+  my $old = $tag->{old};
+  if (defined $old) {
+   no strict 'refs';
+   no warnings 'redefine';
+   *$fqn = $old;
+  }
+
+  my $proto = $tag->{proto};
   if (defined $proto) {
    no strict 'refs';
-   Scalar::Util::set_prototype(\&{"${pkg}::$name"}, $proto);
+   Scalar::Util::set_prototype(\&$fqn, $proto);
   }
 
   delete $map->{$name};
@@ -429,6 +447,10 @@ L<ExtUtils::Depends>.
 
 L<subs::auto>.
 
+L<B::Hooks::XSUB::CallAsOp> provides a C API to declare XSUBs that effectively call a specific PP function.
+Thus, it allows you to write XSUBs with the PP stack conventions used for implementing perl core keywords.
+There's no opcode replacement and no parsing hacks.
+
 L<B::Hooks::OP::Check::EntersubForCV>.
 
 =head1 AUTHOR