Skip Menu |

This queue is for tickets about the Zydeco CPAN distribution.

Report information
The Basics
Id: 133448
Status: resolved
Worked: 10 min
Priority: 0/
Queue: Zydeco

People
Owner: Nobody in particular
Requestors: SMONFF [...] cpan.org
Cc:
AdminCc:

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



Subject: Predeclare for Using Type Constraints for Attributes
Hi Toby, In the third part of Zydeco::Manual, "Methods with signatures, type constraints, and coercion", there is a "Using Type Constraints for Attributes" section that describe how to pre-declare a type constraint to avoid barewords. I tried to pre-declare and use the quote-less form but didn't succeed. Dunno if it is me or if it could be a bug, or something you changed in the Zydeco features, but not in the doc. t/31_constraints.t .. Can't locate object method "get_type" via package "MyApp::Types" at /home/smonff/perl5/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/Type/Library.pm line 289. BEGIN failed--compilation aborted at t/31_constraints.t line 9. As soon as the quote are added around the type constraint, it pass. See the tests in the joined file. Cheers.
Subject: 31_constraints.t
use Test::More; package MyApp { use Zydeco declare => ['Person']; class Person { has name ( type => Str ); has children ( type => ArrayRef[Person] ); } } my $enfant = MyApp->new_person( name => 'Enfant'); my $parent = MyApp->new_person( name =>'Parent', children => [ $enfant ] ); is @{ $parent->children}[0]->name, 'Enfant'; done_testing;
Yeah, it's not perfect yet. The following works; it's just building a more complex type like ArrayRef[Person] which fails. It's caused by ArrayRef[Person] trying to find out if Person has any coercions before Person is fully defined, and it won't be fully defined until the "}" at the end of the class definition. I do think it's fixable, but needs to be fixed in Type::Tiny rather than Zydeco. ---- use strict; use warnings; use Test::More; package MyApp { use Zydeco declare => ['Person']; class Person { has name ( type => Str ); has children ( type => Person ); } } my $enfant = MyApp->new_person( name => 'Enfant'); my $parent = MyApp->new_person( name => 'Parent', children => $enfant ); is $parent->children->name, 'Enfant'; done_testing;
Yeah, this patch for Type::Tiny fixes things. It might be a while before the next stable release of Type::Tiny though.
Subject: rt133448.diff
diff -r 1ed389d30512 lib/Type/Tiny.pm --- a/lib/Type/Tiny.pm Fri Sep 25 17:23:53 2020 +0100 +++ b/lib/Type/Tiny.pm Wed Sep 30 01:44:23 2020 +0100 @@ -1008,11 +1008,15 @@ $P = $self->create_child_type(%options); - my $coercion; - $coercion = $self->coercion_generator->($self, $P, @_) - if $self->has_coercion_generator; - $P->coercion->add_type_coercions( @{$coercion->type_coercion_map} ) - if $coercion; + if ( $self->has_coercion_generator ) { + my @args = @_; + $P->{_build_coercion} = sub { + my $coercion = shift; + my $built = $self->coercion_generator->($self, $P, @args); + $coercion->add_type_coercions( @{$built->type_coercion_map} ) if $built; + $coercion->freeze; + }; + } } if (defined $key) @@ -1021,7 +1025,7 @@ Scalar::Util::weaken($param_cache{$key}); } - $P->coercion->freeze; + $P->coercion->freeze unless $self->has_coercion_generator; return $P; }
If you upgrade to Type-Tiny-1.011_004, it includes the fix. But it's not a stable release yet, so I wouldn't recommend making Art::World (or anything else) depend on it!
Le Mer 30 Sep 2020 10:47:22, TOBYINK a écrit :
Show quoted text
> If you upgrade to Type-Tiny-1.011_004, it includes the fix.
>
> But it's not a stable release yet, so I wouldn't recommend making
> Art::World (or anything else) depend on it!

I am gonna try it. Art::world is totally unstable, so it wouldn't suffer much of a Type::Tiny developement version, I guess. Thanks for the hard work, and I will keep in touch to swith to other versions and the next stable one.

I can confirm it totally solve the initial issue.

Le Sam 10 Oct 2020 17:19:44, SMONFF a écrit :
Show quoted text
> Le Mer 30 Sep 2020 10:47:22, TOBYINK a écrit :
> > If you upgrade to Type-Tiny-1.011_004, it includes the fix.
> >
> > But it's not a stable release yet, so I wouldn't recommend making
> > Art::World (or anything else) depend on it!
>
> I am gonna try it. Art::world is totally unstable, so it wouldn't
> suffer much
> of a Type::Tiny developement version, I guess. Thanks for the hard
> work, and I
> will keep in touch to swith to other versions and the next stable one.


FYI, Type::Tiny 1.012000 is now released including these changes.
Subject: Re: [rt.cpan.org #133448] Predeclare for Using Type Constraints for Attributes
Date: Wed, 28 Oct 2020 17:30:32 +0100
To: bug-Zydeco [...] rt.cpan.org
From: Sébastien Feugère <smonff [...] riseup.net>
Lol just sent you a private email about it. Le 28 octobre 2020 17:17:39 GMT+01:00, Toby Inkster via RT <bug-Zydeco@rt.cpan.org> a écrit : Show quoted text
><URL: https://rt.cpan.org/Ticket/Display.html?id=133448 > > >FYI, Type::Tiny 1.012000 is now released including these changes.