Subject: | Typed attributes loses values |
$ perl -MDios -e '
class foo {
has Int %!bar;
method baz { $bar{1} = 2; };
method bazz { $bar{1} };
}
my $foo = foo->new();
$foo->baz;
print "Result: >", $foo->bazz, "<\n";
'
Result: ><
Changing the %bar definition:
`has %!bar;` -> Result: >2<
`has Code %!bar;` -> Value (2) for %bar attribute is not of type Code
`has %.bar;` -> assigned value is not a reference
`has %.bar = ();` -> Result: >2<
`has Int %.bar = ();` -> Result: ><
It looks like for every following call to baz %bar is fresh again (the scope assumption is a wild guess ... ; ARRAY & HASH seems affected)
Also i don't understand the error for `has %.bar;` ... i did not see a assignment and the variable is not required.
The attached patch add some testcases to t/attribute_basic.t