use strict;
use feature "state";
-plan tests => 19;
+plan tests => 23;
ok( ! defined state $uninit, q(state vars are undef by default) );
is( $f2->(), 1, 'generator 2' );
is( $f1->(), 3, 'generator 1 again' );
is( $f2->(), 2, 'generator 2 once more' );
+
+{
+ package countfetches;
+ our $fetchcount = 0;
+ sub TIESCALAR {bless {}};
+ sub FETCH { ++$fetchcount; 18 };
+ tie my $y, "countfetches";
+ sub foo { state $x = $y; $x++ }
+ ::is( foo(), 18, "initialisation with tied variable" );
+ ::is( foo(), 19, "increments correctly" );
+ ::is( foo(), 20, "increments correctly, twice" );
+ ::is( $fetchcount, 1, "fetch only called once" );
+}