From: Rafael Garcia-Suarez Date: Wed, 3 May 2006 22:40:28 +0000 (+0000) Subject: New test case for state variables with ties, suggested by Nicholas X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5d1e1362bca3ef5bc255eeeafbbd67ab16a83104;p=p5sagit%2Fp5-mst-13.2.git New test case for state variables with ties, suggested by Nicholas p4raw-id: //depot/perl@28088 --- diff --git a/t/op/state.t b/t/op/state.t index 3b68879..260fa8b 100644 --- a/t/op/state.t +++ b/t/op/state.t @@ -9,7 +9,7 @@ BEGIN { use strict; use feature "state"; -plan tests => 19; +plan tests => 23; ok( ! defined state $uninit, q(state vars are undef by default) ); @@ -64,3 +64,16 @@ my $f2 = generator(); 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" ); +}