Commit | Line | Data |
---|---|---|
59f30b2e | 1 | use Test::More tests => 5; |
0be5d18d FC |
2 | use XS::APItest; |
3 | ||
4 | ||
5 | sub fribbler { 2*shift } | |
6 | { | |
7 | BEGIN { lexical_import fribbler => sub { 3*shift } } | |
8 | is fribbler(15), 45, 'lexical subs via pad_add_name'; | |
9 | } | |
10 | is 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 | } | |
59f30b2e FC |
20 | |
21 | # With ‘use’ rather than explicit BEGIN: | |
22 | package Lexical::Exporter { | |
23 | sub import { shift; ::lexical_import @_; return } | |
24 | } | |
25 | BEGIN { ++$INC{"Lexical/Exporter.pm"} } | |
26 | ||
27 | { | |
28 | use Lexical::Exporter fribbler => sub { shift() . "foo" }; | |
29 | is fribbler("bar"), "barfoo"; | |
30 | } |