DEV Community

Cover image for Type library kura meets built-in class.
kobaken
kobaken

Posted on

1

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay