Skip Menu |

This queue is for tickets about the Type-Tiny CPAN distribution.

Report information
The Basics
Id: 129650
Status: resolved
Worked: 15 min
Priority: 0/
Queue: Type-Tiny

People
Owner: perl [...] toby.ink
Requestors: schroeer [...] cpan.org
Cc:
AdminCc:

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



Subject: Allowable value of Type::Tiny::Enum should maintain order
Date: Wed, 22 May 2019 12:17:52 +0200
To: bug-Type-Tiny [...] rt.cpan.org
From: Daniel Schröer <schroeer [...] cpan.org>
The 'values' attribute/method of Type::Tiny::Enum returns a sorted list of the allowable value strings. That's an incompatibility to Moose's type constraint API where the specified order is maintained. I prefer Moose's behaviour.
On 2019-05-22T11:18:33+01:00, SCHROEER wrote: Show quoted text
> The 'values' attribute/method of Type::Tiny::Enum returns a sorted list of > the allowable value strings. That's an incompatibility to Moose's type > constraint API where the specified order is maintained. I prefer Moose's > behaviour.
It also removes duplicates from the list. It tries to cut things down to the essentials to make the check as efficient as possible. For example, if you consider: use feature 'say'; use Types::Standard -all; use Scalar::Util 'refaddr'; say refaddr($_->compiled_check) for Enum[qw(Y N)], Enum[qw(N Y)]; You'll see that the coderef returned by $type->compiled_check for both those enums has the same refaddr. It's reused the same coderef. So I certainly want to keep the current sorting and deduplication to "canonicalize" the list. But it should also be possible to retain a copy of the original list for introspection purposes, have the `values` method return that original list, and add a new method to return the canonicalized list. I'd probably also need to go through the code and figure out what other places are using the `values` method and expecting the canonicalized list, but that's probably not a lot of work. If you can submit some test cases for the behaviour of `values` that you expect, I can try to work it in before 1.006000.
Subject: Re: [rt.cpan.org #129650] Allowable value of Type::Tiny::Enum should maintain order
Date: Thu, 23 May 2019 23:32:28 +0200
To: bug-Type-Tiny [...] rt.cpan.org
From: Daniel Schröer <danielschroeer [...] googlemail.com>
Show quoted text
> > If you can submit some test cases for the behaviour of `values` that you > expect, I can try to work it in before 1.006000. >
In t/20-unit/Type-Tiny-Enum/basic.t there is is_deeply( [sort @{FBB->values}], [sort qw/foo bar baz/], 'FBB->values works', ); The desired behaviour is that this passes as well: is_deeply( [@{FBB->values}], [qw/foo bar baz/], 'FBB->values works', ); Thank you!
Subject: Re: [rt.cpan.org #129650] Allowable value of Type::Tiny::Enum should maintain order
Date: Wed, 29 May 2019 18:49:39 +0200
To: bug-Type-Tiny [...] rt.cpan.org
From: Daniel Schröer <schroeer [...] cpan.org>
Great. Thank you!
Releasing 1.006000 tomorrow, which will include this change.
On Mon Nov 11 17:16:16 2019, TOBYINK wrote: Show quoted text
> Releasing 1.006000 tomorrow, which will include this change.
For the record, the change in the result of `values` caused trouble in our DarkPAN modules. We've patched it with: $Type::Tiny::Enum::VERSION ge 1.006000 ? $enum->unique_values : $enum->values Another relevant question is: what about the arrayref overload for Enum? It used to be (and still is) values(), but now that the result of values() has changed, should that overload be changed to unique_values()? Regards, -- BooK
The current behaviour now matches how it was always documented, and more closely matches Moose::Meta::TypeConstraint::Enum. At no point in the past has the documentation ever implied that @$enum would give you a sorted list with only unique values, even if it once did do that, so I think I should keep things as they are now in 1.006000.