anonsub.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#!./perl
# fresh_perl_is, and fresh_perl_is uses a closure -- a special
# case of what this program tests for.
chdir 't' if -d 't';
@INC = '../lib';
$|=1;
undef $/;
$tmpfile = "asubtmp000";
1 while -f ++$tmpfile;
if (s/^\s*(-\w+)//){
$switch = $1;
}
my $status = $?;
$results =~ s/\n+$//;
# allow expected output to be written as if $prog is on STDIN
$expected =~ s/\n+$//;
print "not ";
}
print "ok ", ++$i, "\n";
}
sub test_invalid_decl {
eval $code;
} else {
}
}
eval "sub #foo\n{print 1}";
print "ok ", ++$i, "\n";
} else {
print "not ok ", ++$i, "\n# GOT: $@";
}
sub X {
my $n = "ok 1\n";
sub { print $n };
}
my $x = X();
undef &X;
$x->();
ok 1
########
sub X {
my $n = "ok 1\n";
sub {
my $dummy = $n; # eval can't close on $n without internal reference
eval 'print $n';
die $@ if $@;
};
}
my $x = X();
undef &X;
$x->();
ok 1
########
sub X {
my $n = "ok 1\n";
eval 'sub { print $n }';
}
my $x = X();
die $@ if $@;
undef &X;
$x->();
ok 1
########
sub X;
sub X {
my $n = "ok 1\n";
eval 'sub Y { my $p = shift; $p->() }';
die $@ if $@;
Y(sub { print $n });
}
X();
ok 1
########
print sub { return "ok 1\n" } -> ();
ok 1