1use Test::More tests => 5; 2use XS::APItest; 3 4 5sub fribbler { 2*shift } 6{ 7 BEGIN { lexical_import fribbler => sub { 3*shift } } 8 is fribbler(15), 45, 'lexical subs via pad_add_name'; 9} 10is fribbler(15), 30, 'XS-allocated lexical subs falling out of scope'; 11 12{ 13 BEGIN { lexical_import fribbler => sub { 3*shift } } 14 is fribbler(15), 45, 'lexical subs via pad_add_name'; 15 no warnings; 16 use feature 'lexical_subs'; 17 our sub fribbler; 18 is fribbler(15), 30, 'our sub overrides XS-registered lexical sub'; 19} 20 21# With ���use��� rather than explicit BEGIN: 22package Lexical::Exporter { 23 sub import { shift; ::lexical_import @_; return } 24} 25BEGIN { ++$INC{"Lexical/Exporter.pm"} } 26 27{ 28 use Lexical::Exporter fribbler => sub { shift() . "foo" }; 29 is fribbler("bar"), "barfoo"; 30} 31