Type library kura meets built-in class.

kfly8

kobaken

Posted on November 25, 2024

Type library kura meets built-in class.

https://metacpan.org/pod/kura

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!
Enter fullscreen mode Exit fullscreen mode

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

💖 💪 🙅 🚩
kfly8
kobaken

Posted on November 25, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related