use strict;
use feature "state";
-plan tests => 30;
+plan tests => 34;
ok( ! defined state $uninit, q(state vars are undef by default) );
# stateless assignment to a state variable
sub stateless {
- (state $reinitme) = 42;
+ no warnings 'misc';
+ (state $reinitme, my $foo) = (42, 'bar');
++$reinitme;
}
is( stateless(), 43, 'stateless function, first time' );
$xhval = stateful_hash();
is( $xhval, 1, 'uninitialized state hash after one iteration' );
+
+# state declaration with a list
+
+sub statelist {
+ # note that this should be a state assignment, while (state $lager, state $stout) shouldn't
+ state($lager, $stout) = (11, 22);
+ $lager++;
+ $stout++;
+ "$lager/$stout";
+}
+
+my $ls = statelist();
+is($ls, "12/23", 'list assignment to state scalars');
+$ls = statelist();
+is($ls, "13/24", 'list assignment to state scalars');
+
+sub statelist2 {
+ state($sherry, $bourbon) = (1 .. 2);
+ $sherry++;
+ $bourbon++;
+ "$sherry/$bourbon";
+}
+
+$ls = statelist2();
+is($ls, "2/3", 'list assignment to state scalars');
+$ls = statelist2();
+is($ls, "3/4", 'list assignment to state scalars');