Skip Menu |
 

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

Report information
The Basics
Id: 128337
Status: resolved
Priority: 0/
Queue: Type-Tiny

People
Owner: perl [...] toby.ink
Requestors: violapiratejunky [...] gmail.com
Cc:
AdminCc:

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



Subject: Support something similar to Params::ValidationCompiler#named_to_list
Download (untitled) / with headers
text/plain 170b
It would be nice if Type::Params supported something like named_to_list in Params::ValidationCompiler: https://metacpan.org/pod/Params::ValidationCompiler#named_to_list
Download (untitled) / with headers
text/plain 353b
On 2019-01-23T19:43:53Z, srchulo wrote: Show quoted text
That looks pretty possible. Would only be a few lines of code, I think. Might be able to include it before the next stable release. What should be done with missing optional parameters (with no defaults)? Should it just return undef for those?
Download (untitled) / with headers
text/plain 599b
That's what Params::ValidationCompiler does, and I think that makes the most sense. I believe this would also line up with the behavior in the object returned from compile_named_oo. On Fri Jan 25 09:00:40 2019, TOBYINK wrote: Show quoted text
> On 2019-01-23T19:43:53Z, srchulo wrote: > > That looks pretty possible. Would only be a few lines of code, I > think. Might be able to include it before the next stable release. > > What should be done with missing optional parameters (with no > defaults)? Should it just return undef for those?
Download (untitled) / with headers
text/plain 603b
On 2019-01-27T17:38:09Z, srchulo wrote: Show quoted text
> That's what Params::ValidationCompiler does, and I think that makes > the most sense. I believe this would also line up with the behavior in > the object returned from compile_named_oo.
compile_named_oo will return undef if you call a method corresponding to a missing named parameter, but it does also have `has_foo` methods. With named_to_list, there's effectively no way to distinguish between a value of undef and a missing value. But in many cases, you don't care about that distinction anyway, so I don't think that's a problem provided it's documented.
On Sun Jan 27 19:32:30 2019, TOBYINK wrote: Show quoted text
> On 2019-01-27T17:38:09Z, srchulo wrote:
> > That's what Params::ValidationCompiler does, and I think that makes > > the most sense. I believe this would also line up with the behavior > > in > > the object returned from compile_named_oo.
> > compile_named_oo will return undef if you call a method corresponding > to a missing named parameter, but it does also have `has_foo` methods. > > With named_to_list, there's effectively no way to distinguish between > a value of undef and a missing value. But in many cases, you don't > care about that distinction anyway, so I don't think that's a problem > provided it's documented.
Yeah, I agree-- as long as it's documented, I think it's fine. And if someone cares, they can use the oo method. Also, I believe this matches up with the normal compile() with positional parameters? # Positional parameters state $check = compile(Int, Optional[Int], Optional[Int]); my ($foo, $bar, $baz) = $check->(@_); # $bar and $baz are optional
Download (untitled) / with headers
text/plain 406b
I think with compile(), you should be able to check the length of the returned list. Anyway... https://github.com/tobyink/p5-type-tiny/commit/608b259604cf18ba794239959fdc8f6a2b4e1646 So you should be able to do {named_to_list=>1} to get what you want. You can also do {named_to_list=>\@keys} to indicate what order you want the list to be returned in. (No sanity checks are performed on the key names!)
Download (untitled) / with headers
text/plain 542b
On Sun Jan 27 20:01:38 2019, TOBYINK wrote: Show quoted text
> I think with compile(), you should be able to check the length of the > returned list. > > Anyway... > > https://github.com/tobyink/p5-type- > tiny/commit/608b259604cf18ba794239959fdc8f6a2b4e1646 > > So you should be able to do {named_to_list=>1} to get what you want. > > You can also do {named_to_list=>\@keys} to indicate what order you > want the list to be returned in. (No sanity checks are performed on > the key names!)
That looks great! Thank you :) That looks great! Thank you :)
Release 1.005_002 which is only a trial version, but includes this feature.
Download (untitled) / with headers
text/plain 164b
On Tue Jan 29 07:50:00 2019, TOBYINK wrote: Show quoted text
> Release 1.005_002 which is only a trial version, but includes this feature.
Great, thank you! I'm already using it :)


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.