The type library kura now possible to use the Perl with built-in class. This allows you to gather objects and types.
use v5.40;
use experimental 'class';
class Fruit {
use Exporter 'import';
use Types::Common -types;
# kura meets built-in class!
use kura Name => StrLength[1, 255];
field $name :param :reader;
ADJUST {
Name->assert_valid($name);
}
}
my $fruit = Fruit->new(name => ''); # Error!
This is a unique feature of kura, that isn't possible with Type::Library.
Feel free to give it a try!
This article is for Japanese Perl Advent Calendar 2024
Top comments (0)