6 set_up_inc( qw(../lib) );
7 plan (tests => 22); # some tests are run in BEGIN block
10 is __SUB__, "__SUB__", '__SUB__ is a bareword outside of use feature';
14 is __SUB__, undef, '__SUB__ under use v5.16';
17 use feature 'current_sub';
19 is __SUB__, undef, '__SUB__ returns undef outside of a subroutine';
20 is +()=__SUB__, 1, '__SUB__ returns undef in list context';
23 is foo, \&foo, '__SUB__ inside a named subroutine';
24 is foo->(), \&foo, '__SUB__ is callable';
25 is ref foo, 'CODE', '__SUB__ is a code reference';
27 my $subsub = sub { __SUB__ };
28 is &$subsub, $subsub, '__SUB__ inside anonymous non-closure';
32 push @subsubs, sub { return $x if @_; __SUB__ };
34 # Don’t loop here; we need to avoid interactions between the iterator
36 is $subsubs[0]()(0), 1, '__SUB__ inside closure (1)';
37 is $subsubs[1]()(0), 2, '__SUB__ inside closure (2)';
38 is $subsubs[2]()(0), 3, '__SUB__ inside closure (3)';
41 return "begin 1" if @_;
42 is CORE::__SUB__->(0), "begin 1", 'in BEGIN block'
45 return "begin 2" if @_;
46 is &CORE::__SUB__->(0), "begin 2", 'in BEGIN block via & (unoptimised)'
52 is CORE::__SUB__, \&bar, 'in sort block in sub with forw decl'
59 is &CORE::__SUB__, \&bur, '& in sort block in sub with forw decl'
66 grep { is CORE::__SUB__, \&squog,
67 'in grep block in sub with forw decl'
73 grep { is &CORE::__SUB__, \&squag,
74 '& in grep block in sub with forw decl'
80 is f, \&f, 'sub named () { __SUB__ } returns self ref';
81 my $f = sub () { __SUB__ };
82 is &$f, $f, 'anonymous sub(){__SUB__} returns self ref';
83 my $f2 = sub () { $f++ if 0; __SUB__ };
84 is &$f2, $f2, 'sub(){__SUB__} anonymous closure returns self ref';
85 $f = sub () { eval ""; __SUB__ };
86 is &$f, $f, 'anonymous sub(){eval ""; __SUB__} returns self ref';
88 local $ENV{PERL5DB} = 'sub DB::DB {}';
91 prog => '$f = sub(){CORE::__SUB__}; print qq-ok\n- if $f == &$f;',
94 'sub(){__SUB__} under -d';