+
+SKIP: {
+ skip 'No state variables before perl 5.10' => 3 * 2 unless "$]" >= 5.010;
+
+ my $desc = 'state variables';
+
+ {
+ local $@;
+ eval 'use feature "state"; sub herp { state $id = 123; return ++$id }';
+ die $@ if $@;
+ }
+
+ sub derp {
+ sub {
+ &uplevel(\&herp => UP);
+ }->();
+ }
+
+ for my $run (1 .. 3) {
+ local $@;
+ my $ret = eval {
+ derp()
+ };
+ is $@, '', "$desc: run $run did not croak";
+ is $ret, 123 + $run, "$desc: run $run returned the correct value";
+ }
+}