Skip to content

Commit

Permalink
Add intro_my to XS::APItest::lexical_import
Browse files Browse the repository at this point in the history
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’.
  • Loading branch information
Father Chrysostomos committed Jun 6, 2016
1 parent e2733f9 commit 59f30b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions ext/XS-APItest/APItest.xs
Expand Up @@ -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;
}

Expand Down
13 changes: 12 additions & 1 deletion ext/XS-APItest/t/lexsub.t
@@ -1,4 +1,4 @@
use Test::More tests => 4;
use Test::More tests => 5;
use XS::APItest;


Expand All @@ -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";
}

0 comments on commit 59f30b2

Please sign in to comment.