summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/ext/XS-APItest/t/lexsub.t
blob: 25985f60b4b52704882f4fd952d71fdd05a08b05 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use Test::More tests => 5;
use XS::APItest;


sub fribbler { 2*shift }
{
    BEGIN { lexical_import fribbler => sub { 3*shift } }
    is fribbler(15), 45, 'lexical subs via pad_add_name';
}
is fribbler(15), 30, 'XS-allocated lexical subs falling out of scope';

{
    BEGIN { lexical_import fribbler => sub { 3*shift } }
    is fribbler(15), 45, 'lexical subs via pad_add_name';
    no warnings;
    use feature 'lexical_subs';
    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";
}