diff options
author | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2006-05-03 22:40:28 +0000 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2006-05-03 22:40:28 +0000 |
commit | 5d1e1362bca3ef5bc255eeeafbbd67ab16a83104 (patch) | |
tree | 39507f3ac406d81a8a899a9ddaf12d44a0db4618 /t/op | |
parent | 712d05cf9bbf674929d5e38c5bb989d87c51f19b (diff) | |
download | perl-5d1e1362bca3ef5bc255eeeafbbd67ab16a83104.tar.gz |
New test case for state variables with ties, suggested by Nicholas
p4raw-id: //depot/perl@28088
Diffstat (limited to 't/op')
-rw-r--r-- | t/op/state.t | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/t/op/state.t b/t/op/state.t index 3b68879600..260fa8bf38 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" ); +} |