Skip Menu |

This queue is for tickets about the Zydeco CPAN distribution.

Report information
The Basics
Id: 132230
Status: resolved
Priority: 0/
Queue: Zydeco

People
Owner: Nobody in particular
Requestors: roger.tsang [...] gmail.com
Cc:
AdminCc:

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



Subject: builder invoked multiple times for attribute with type => Bool
Date: Wed, 25 Mar 2020 20:06:01 -0400
To: bug-Zydeco [...] rt.cpan.org
From: Roger Tsang <roger.tsang [...] gmail.com>
It appears type => Bool default coercion runs the attribute's default / builder multiple times. This may cause unwanted side-effects. I've seen this behavior in perl-5.30.2 on FreeBSD 12 and strawberry-perl-5.30.1.1 on Windows 10. Zydeco test attached. Zydeco.t .. # Seeded srand with seed '20200325' from local date. ok 1 ok 2 - override default coercion not ok 3 - lazy builder # Failed test 'lazy builder' # at Zydeco.t line 33. # +-------+--------------------------------------------+----------+--------+ # | PATH | GOT | CHECK | LNs | # +-------+--------------------------------------------+----------+--------+ # | | MyApp::Something=HASH(0x802a551c8) | <OBJECT> | 33, 33 | # | | | | | # | two() | <EXCEPTION: Value "2" did not pass type co | 1 | 462 | # | | nstraint "Bool" (in $self->{"two"}) at (ev | | | # | | al 345) line 28\n | | | # | | Value "2" did not pass type constraint | | | # | | "Bool" (in $self->{"two"})> | | | # +-------+--------------------------------------------+----------+--------+ not ok 4 - lazy # Failed test 'lazy' # at Zydeco.t line 34. # +---------+------------------------------------------+----------+--------+ # | PATH | GOT | CHECK | LNs | # +---------+------------------------------------------+----------+--------+ # | | MyApp::Something=HASH(0x802a551c8) | <OBJECT> | 34, 34 | # | | | | | # | three() | <EXCEPTION: Value "2" did not pass type | 1 | 462 | # | | constraint "Bool" (in $self->{"three"}) | | | # | | at (eval 369) line 29\n | | | # | | Value "2" did not pass type constrai | | | # | | nt "Bool" (in $self->{"three"})> | | | # +---------+------------------------------------------+----------+--------+ not ok 5 - lazy implied # Failed test 'lazy implied' # at Zydeco.t line 35. # +--------+-------------------------------------------+----------+--------+ # | PATH | GOT | CHECK | LNs | # +--------+-------------------------------------------+----------+--------+ # | | MyApp::Something=HASH(0x802a551c8) | <OBJECT> | 35, 35 | # | | | | | # | four() | <EXCEPTION: Value "2" did not pass type c | 1 | 462 | # | | onstraint "Bool" (in $self->{"four"}) at | | | # | | (eval 346) line 29\n | | | # | | Value "2" did not pass type constrain | | | # | | t "Bool" (in $self->{"four"})> | | | # +--------+-------------------------------------------+----------+--------+ ok 6 - add first ok 7 - add first ok 8 - add first not ok 9 - add first # Failed test 'add first' # at Zydeco.t line 41. # +-----------+-----------------------------------+----+----------+--------+ # | PATH | GOT | OP | CHECK | LNs | # +-----------+-----------------------------------+----+----------+--------+ # | | MyApp::Something=HASH(0x802a551c8 | | <OBJECT> | 41, 41 | # | | ) | | | | # | | | | | | # | counter() | 3 | eq | 2 | 462 | # +-----------+-----------------------------------+----+----------+--------+ not ok 10 - add first # Failed test 'add first' # at Zydeco.t line 42. # +-----------+-----------------------------------+----+----------+--------+ # | PATH | GOT | OP | CHECK | LNs | # +-----------+-----------------------------------+----+----------+--------+ # | | MyApp::Something=HASH(0x802a551c8 | | <OBJECT> | 42, 42 | # | | ) | | | | # | | | | | | # | counter() | 3 | eq | 2 | 462 | # +-----------+-----------------------------------+----+----------+--------+ not ok 11 - add first # Failed test 'add first' # at Zydeco.t line 43. # +-----------+-----------------------------------+----+----------+--------+ # | PATH | GOT | OP | CHECK | LNs | # +-----------+-----------------------------------+----+----------+--------+ # | | MyApp::Something=HASH(0x802a551c8 | | <OBJECT> | 43, 43 | # | | ) | | | | # | | | | | | # | counter() | 3 | eq | 2 | 462 | # +-----------+-----------------------------------+----+----------+--------+ not ok 12 ok 13 - lazy # Failed test at Zydeco.t line 45. # +---------+--------------------------------+----+----------+--------+ # | PATH | GOT | OP | CHECK | LNs | # +---------+--------------------------------+----+----------+--------+ # | | MyApp::Other=HASH(0x8031b92a0) | | <OBJECT> | 45, 45 | # | count() | 2 | eq | 1 | 462 | # +---------+--------------------------------+----+----------+--------+ not ok 14 # Failed test at Zydeco.t line 48. # +---------+--------------------------------+----+----------+--------+ # | PATH | GOT | OP | CHECK | LNs | # +---------+--------------------------------+----+----------+--------+ # | | MyApp::Other=HASH(0x8031b9498) | | <OBJECT> | 48, 48 | # | count() | 8 | eq | 2 | 462 | # +---------+--------------------------------+----+----------+--------+ ok 15 - not lazy not ok 16 1..16 # Failed test at Zydeco.t line 51. # +---------+--------------------------------+----+----------+--------+ # | PATH | GOT | OP | CHECK | LNs | # +---------+--------------------------------+----+----------+--------+ # | | MyApp::Other=HASH(0x8031b9498) | | <OBJECT> | 51, 51 | # | count() | 12 | eq | 2 | 462 | # +---------+--------------------------------+----+----------+--------+ Dubious, test returned 9 (wstat 2304, 0x900) Failed 9/16 subtests Test Summary Report ------------------- Zydeco.t (Wstat: 2304 Tests: 16 Failed: 9) Failed tests: 3-5, 9-12, 14, 16 Non-zero exit status: 9 Files=1, Tests=16, 1 wallclock secs ( 0.01 usr 0.02 sys + 0.51 cusr 0.52 csys = 1.05 CPU) Result: FAIL

Message body is not shown because sender requested not to inline it.

A lot of this seems to be an issue with how MooX::TypeTiny deals with coercions. Uninstalling MooX::TypeTiny results in most of your test script passing. Tests 14 and 16 still fail.
The reasons tests 14 and 16 fail is that they're just wrong. They seem to be assuming that $count will be reset to 0 for each instance of the object, but it won't be.
Fixed in Zydeco 0.517 by no longer using MooX::TypeTiny.
Subject: Re: [rt.cpan.org #132230] builder invoked multiple times for attribute with type => Bool
Date: Thu, 9 Apr 2020 00:38:39 -0400
To: bug-Zydeco [...] rt.cpan.org
From: Roger Tsang <roger.tsang [...] gmail.com>
Thanks