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;