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