Make L<perltrap> refer to L<perldelta>
[p5sagit/p5-mst-13.2.git] / pod / perlcall.pod
index b69c539..85e0237 100644 (file)
@@ -1795,7 +1795,7 @@ series of C functions to act as the interface to Perl, thus
 
 In this case the functions C<fn1>, C<fn2>, and C<fn3> are used to
 remember the Perl subroutine to be called. Each of the functions holds
-a separate hardwired index which is used in the function C<Pcb> to
+a separate hard-wired index which is used in the function C<Pcb> to
 access the C<Map> array and actually call the Perl subroutine.
 
 There are some obvious disadvantages with this technique.
@@ -1803,7 +1803,7 @@ There are some obvious disadvantages with this technique.
 Firstly, the code is considerably more complex than with the previous
 example.
 
-Secondly, there is a hardwired limit (in this case 3) to the number of
+Secondly, there is a hard-wired limit (in this case 3) to the number of
 callbacks that can exist simultaneously. The only way to increase the
 limit is by modifying the code to add more functions and then
 recompiling.  None the less, as long as the number of functions is
@@ -1915,6 +1915,44 @@ refers to the last.
 
 =back
 
+=head2 Creating and calling an anonymous subroutine in C
+
+As we've already shown, L<perl_call_sv> can be used to invoke an
+anonymous subroutine.  However, our example showed how Perl script
+invoking an XSUB to preform this operation.  Let's see how it can be
+done inside our C code:
+
+   SV *perl_eval(char *string, int croak_on_error)
+   {
+       dSP;
+       SV *sv = newSVpv(string,0);
+
+       PUSHMARK(sp);
+       perl_eval_sv(sv, G_SCALAR);
+       SvREFCNT_dec(sv);
+
+       SPAGAIN;
+       sv = POPs;
+       PUTBACK;
+
+       if (croak_on_error && SvTRUE(GvSV(errgv)))
+            croak(SvPV(GvSV(errgv),na));
+
+       return sv;
+   }
+
+ ...
+
+ SV *cvrv = perl_eval("sub { print 'You will not find me cluttering any namespace!' }", TRUE);
+
+ ...
+
+ perl_call_sv(cvrv, G_VOID|G_NOARGS);
+
+L<perl_eval_sv> is used to compile the anonymous subroutine, which can
+then be POPed off the stack.  Once this code reference is in hand, it
+can be mixed in with all the previous examples we've shown.
+
 =head1 SEE ALSO
 
 L<perlxs>, L<perlguts>, L<perlembed>