Skip Menu |

This queue is for tickets about the Dios CPAN distribution.

Report information
The Basics
Id: 122805
Status: resolved
Priority: 0/
Queue: Dios

People
Owner: Nobody in particular
Requestors: felix.ostmann [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.002009
Fixed in: (no value)



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
From: felix.ostmann [...] gmail.com
and the patch ...
Subject: attributes_basic.patch
--- t/attributes_basic.t 2017-03-31 00:11:26.000000000 +0200 +++ t/attributes_basic.t.new 2017-08-15 09:28:50.215448343 +0200 @@ -1,7 +1,7 @@ use Dios; use Test::More; -plan tests => 19; +plan tests => 26; my $NAME = 'Damian'; my @NUMS = (1,2,3); @@ -48,6 +48,17 @@ return 1; } + + method check_all () { + + ::is $name, $NEWNAME => 'Name correct in other method'; + + ::is_deeply \@nums, \@NEWNUMS => 'Nums correct in other method'; + + ::is_deeply \%count, \%NEWCOUNT => 'Nums correct in other method'; + + return 1; + } } my $obj = Demo->new({ name => $NAME, count => \%COUNT, nums => \@NUMS }); @@ -64,6 +75,11 @@ ::is $obj->get_name, $NEWNAME => 'Retained updated name correctly'; ::is_deeply $obj->get_nums, \@NEWNUMS => 'Retained original nums correctly'; ::is_deeply $obj->get_count, \%NEWCOUNT => 'Retained original count correctly'; + +::is $obj->check_all(), 1 => 'Called foo() correctly'; +::is $obj->get_name, $NEWNAME => 'Retained updated name correctly'; +::is_deeply $obj->get_nums, \@NEWNUMS => 'Retained original nums correctly'; +::is_deeply $obj->get_count, \%NEWCOUNT => 'Retained original count correctly'; ::ok !defined eval{ $obj->set_name('etc'); 1 }, => 'Name setter failed, as expected'; ::ok !defined eval{ $obj->set_nums(['a']); 1 }, => 'Nums setter failed, as expected';
Subject: Re: [rt.cpan.org #122805] Typed attributes loses values
Date: Sun, 27 Aug 2017 13:33:51 +0000
To: bug-Dios [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Fixed in the latest release (0.002010) Thanks, Felix! Damian