Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: haukex [...] zero-g.net
Cc:
AdminCc:

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



Subject: string constraint fails with (constraint|inline)_generator
Hi, See the attached file - the script will fail (with the error messages at the bottom of the file) if a string is passed as a "constraint", but not if the constraint is passed as a coderef. It will also not fail if *both* "constraint_generator" and "inline_generator" are commented out. Also, as an aside, it's unclear to me from the documentation whether I can provide only an "inline_generator" without providing a "constraint_generator"? Thanks and Happy Holidays, -- Hauke D
Subject: typetiny_bug.pl
#!/usr/bin/env perl use warnings; use strict; BEGIN { package Example::Types { use Type::Library -base; use Types::Standard -types; __PACKAGE__->add_type( name => 'MultipleOf', parent => Int, #constraint => sub { /\A\d+\z/ }, # works constraint => '/\A\d+\z/', # fails constraint_generator => sub { my $i = assert_Int(shift); return sub { $_ % $i == 0 }; }, inline_generator => sub { my $i = shift; return sub { my $varname = pop; return (undef, "$varname % $i == 0"); }; }, ); __PACKAGE__->make_immutable; } Example::Types->import(':all'); } use Test::More; use Test::TypeTiny; should_pass("1", MultipleOf); done_testing; __END__ Argument "/\\A\\d+\\z/" isn't numeric in numeric eq (==) at .../lib/site_perl/5.28.1/Type/Tiny.pm line 417. Argument "/\\A\\d+\\z/" isn't numeric in numeric eq (==) at .../lib/site_perl/5.28.1/Type/Tiny.pm line 417. Argument "/\\A\\d+\\z/" isn't numeric in numeric eq (==) at .../lib/site_perl/5.28.1/Type/Tiny.pm line 417. Can't use string ("/\A\d+\z/") as a subroutine ref while "strict refs" in use at .../lib/site_perl/5.28.1/Type/Tiny.pm line 476. $ perl -MType::Tiny -le 'print $]; print $Type::Tiny::VERSION' 5.028001 1.008000
Type::Tiny's constructor includes the following: if (exists $params{constraint} and not ref $params{constraint} and not exists $params{constraint_generator} and not exists $params{inline_generator}) { # here it uses the string constraint # to make a constraint coderef and inlined coderef } But I have no recollection of why I limited this feature to only type constraints that don't have a constraint_generator or inline_generator. I'll think some more to figure out if there's a reason for this limitation and remove the restriction if I can't find one.
Patched in repo. This should be fixed in 1.008002 whenever it's released.
Hi, On Sun Dec 29 17:09:24 2019, TOBYINK wrote: Show quoted text
> Patched in repo. This should be fixed in 1.008002 whenever it's released.
Looks good, thanks very much! Best, -- Hauke D
Fixed in 1.008002.
On Sat Jan 11 19:29:49 2020, TOBYINK wrote: Show quoted text
> Fixed in 1.008002.
Excellent, thank you very much! Best, -- Hauke D