This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add intro_my to XS::APItest::lexical_import
authorFather Chrysostomos <sprout@cpan.org>
Mon, 6 Jun 2016 20:40:12 +0000 (13:40 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 6 Jun 2016 20:58:48 +0000 (13:58 -0700)
so that code thieves will have some correct code to steal.

Without intro_my(), the lexical subs installed in a ‘use’ block will
not be visible to the following statement, but only the one after it.
BEGIN blocks already get intro_my called, so it worked already with a
BEGIN block, but not with ‘use’.

ext/XS-APItest/APItest.xs
ext/XS-APItest/t/lexsub.t

index f175acd..caeb810 100644 (file)
@@ -4091,6 +4091,7 @@ lexical_import(SV *name, CV *cv)
                              padadd_STATE, 0, 0);
        SvREFCNT_dec(PL_curpad[off]);
        PL_curpad[off] = SvREFCNT_inc(cv);
+       intro_my();
        LEAVE;
     }
 
index 2d66add..25985f6 100644 (file)
@@ -1,4 +1,4 @@
-use Test::More tests => 4;
+use Test::More tests => 5;
 use XS::APItest;
 
 
@@ -17,3 +17,14 @@ is fribbler(15), 30, 'XS-allocated lexical subs falling out of scope';
     our sub fribbler;
     is fribbler(15), 30, 'our sub overrides XS-registered lexical sub';
 }
+
+# With ‘use’ rather than explicit BEGIN:
+package Lexical::Exporter {
+    sub import { shift; ::lexical_import @_; return }
+}
+BEGIN { ++$INC{"Lexical/Exporter.pm"} }
+
+{
+    use Lexical::Exporter fribbler => sub { shift() . "foo" };
+    is fribbler("bar"), "barfoo";
+}