Skip Menu |
 

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

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

People
Owner: perl [...] toby.ink
Requestors: spam-bitcard [...] yary.ack.org
Cc:
AdminCc:

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



Download (untitled) / with headers
text/plain 252b
If a type is parameterizable and has both a "constraint" and a "constraint_generator", then its "deep_explanation" will never be called. As a result validate_explain won't get the "nice" description even when available. See the example code, attached.
Subject: no_has_deep.t
Download no_has_deep.t
text/x-perl 1k
use strict; use warnings; use Type::Tiny; use Test::More; my $type_with = "Type::Tiny"->new ( constraint => sub { 0 }, # Reject everything name => "HasParam", message => sub { "$_ ain't got a number" }, constraint_generator => sub { sub { 0 } }, # Reject everything deep_explanation => sub { ["love to contradict"] }, ); my $type_without = "Type::Tiny"->new ( name => "HasParam", message => sub { "$_ ain't got a number" }, constraint_generator => sub { sub { 0 } }, # Reject everything deep_explanation => sub { ["love to contradict"] }, ); my $s = 'a string'; my $param_with = $type_with->parameterize('an ignored parameter'); my $param_without = $type_without->parameterize('an ignored parameter'); my $explain_with=join("\n ",'With a plain constraint:', @{$param_with->validate_explain($s,'$s')}); my $explain_without=join("\n ",'Without a plain constraint:', @{$param_without->validate_explain($s,'$s')}); diag "$explain_with\n"; diag "$explain_without\n"; ok $explain_with eq $explain_without;
From: spam-bitcard [...] yary.ack.org
The same problem if the type has a parent, even without having an explicit simple "constraint"
Subject: deep_explain not called on types when parameters are optional
From: spam-bitcard [...] yary.ack.org
Download (untitled) / with headers
text/plain 337b
I apologize for not having a subject, and for having a test case with issues. Enclosed is a better test file to show this. And lastly I apologize because apparently, there is no bug! Please feel free to add this updated test script, it may be useful if you do ever decide to change deep_explain internals. And you can close this ticket.
Subject: no_deep.t
Download no_deep.t
text/x-perl 1.5k
use strict; use warnings; use Type::Tiny; use Test::More; my $type_without = "Type::Tiny"->new ( name => "HasParam", message => sub { "$_ ain't got a number" }, constraint_generator => sub { sub { 0 } }, # Reject everything deep_explanation => sub { ["love to contradict"] }, ); my $type_with = "Type::Tiny"->new ( constraint => sub { 1 }, # Un-parameterized accepts al name => "HasParam", message => sub { "$_ ain't got a number" }, constraint_generator => sub { sub { 0 } }, # Reject everything deep_explanation => sub { ["love to contradict"] }, ); my $type_parent = "Type::Tiny"->new ( parent => $type_without, name => "HasParam", message => sub { "$_ ain't got a number" }, constraint_generator => sub { sub { 0 } }, # Reject everything deep_explanation => sub { ["love to contradict"] }, ); my $s = 'a string'; my $param_with = $type_with->parameterize('an ignored parameter'); my $param_parent = $type_parent->parameterize('an ignored parameter'); my $param_without = $type_without->parameterize('an ignored parameter'); my $explain_with=join("\n ",@{$param_with->validate_explain($s,'$s')}); my $explain_parent=join("\n ",@{$param_parent->validate_explain($s,'$s')}); my $explain_without=join("\n ",@{$param_without->validate_explain($s,'$s')}); diag "With a plain constraint:\n $explain_with\n"; diag "With a parent constraint:\n $explain_parent\n"; diag "Without a plain constraint:\n $explain_without\n"; ok $explain_with eq $explain_without; ok $explain_parent eq $explain_without;
Subject: An even better version of the test script
From: spam-bitcard [...] yary.ack.org
This one uses different names for the different types.
Subject: no_deep.t
Download no_deep.t
text/x-perl 1.7k
use strict; use warnings; use Type::Tiny; use Test::More; my $type_without = "Type::Tiny"->new ( name => "HasParam_without", message => sub { "$_ ain't got a number" }, constraint_generator => sub { sub { 0 } }, # Reject everything deep_explanation => sub { ["love to contradict"] }, ); my $type_with = "Type::Tiny"->new ( constraint => sub { 1 }, # Un-parameterized accepts al name => "HasParam_with", message => sub { "$_ ain't got a number" }, constraint_generator => sub { sub { 0 } }, # Reject everything deep_explanation => sub { ["love to contradict"] }, ); my $type_parent = "Type::Tiny"->new ( parent => $type_without, name => "HasParam_parent", message => sub { "$_ ain't got a number" }, constraint_generator => sub { sub { 0 } }, # Reject everything deep_explanation => sub { ["love to contradict"] }, ); my $s = 'a string'; my $param_with = $type_with->parameterize('an ignored parameter'); my $param_parent = $type_parent->parameterize('an ignored parameter'); my $param_without = $type_without->parameterize('an ignored parameter'); my $explain_with=join("\n ",@{$param_with->validate_explain($s,'$s')}); my $explain_parent=join("\n ",@{$param_parent->validate_explain($s,'$s')}); my $explain_without=join("\n ",@{$param_without->validate_explain($s,'$s')}); diag "With a plain constraint:\n $explain_with\n"; diag "With a parent constraint:\n $explain_parent\n"; diag "Without a plain constraint:\n $explain_without\n"; $explain_with =~ s/(HasParam)_\w+/$1/g; $explain_parent =~ s/(HasParam)_\w+/$1/g; $explain_without =~ s/(HasParam)_\w+/$1/g; ok $explain_with eq $explain_without; ok $explain_parent eq $explain_without;
apparently, there is no bug, so...


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.