{"id":15015366,"url":"https://github.com/kfly8/kura","last_synced_at":"2026-03-18T02:34:40.826Z","repository":{"id":253524385,"uuid":"843725139","full_name":"kfly8/kura","owner":"kfly8","description":"Store constraints for Data::Checks, Type::Tiny, Moose, and more.","archived":false,"fork":false,"pushed_at":"2025-12-29T05:44:06.000Z","size":82,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-30T10:01:16.622Z","etag":null,"topics":["perl","types"],"latest_commit_sha":null,"homepage":"","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kfly8.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-17T08:21:28.000Z","updated_at":"2025-12-29T05:44:09.000Z","dependencies_parsed_at":"2025-01-19T17:10:30.818Z","dependency_job_id":"bc010363-6763-4cf3-ae75-5a7dbe5ddc30","html_url":"https://github.com/kfly8/kura","commit_stats":null,"previous_names":["kfly8/kura"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/kfly8/kura","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfly8%2Fkura","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfly8%2Fkura/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfly8%2Fkura/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfly8%2Fkura/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kfly8","download_url":"https://codeload.github.com/kfly8/kura/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfly8%2Fkura/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30642996,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-18T01:41:58.583Z","status":"online","status_checked_at":"2026-03-18T02:00:07.824Z","response_time":104,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["perl","types"],"created_at":"2024-09-24T19:47:05.498Z","updated_at":"2026-03-18T02:34:40.817Z","avatar_url":"https://github.com/kfly8.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Actions Status](https://github.com/kfly8/kura/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/kfly8/kura/actions?workflow=test) [![Coverage Status](https://img.shields.io/coveralls/kfly8/kura/main.svg?style=flat)](https://coveralls.io/r/kfly8/kura?branch=main) [![MetaCPAN Release](https://badge.fury.io/pl/kura.svg)](https://metacpan.org/release/kura)\n# NAME\n\nkura - Store constraints for Data::Checks, Type::Tiny, Moose, and more.\n\n# SYNOPSIS\n\n```perl\nuse Exporter 'import';\n\nuse Types::Common -types;\nuse Email::Valid;\n\nuse kura Name  =\u003e StrLength[1, 255];\nuse kura Email =\u003e sub { Email::Valid-\u003eaddress($_[0]) };\n```\n\n# DESCRIPTION\n\nKura - means \"Traditional Japanese storehouse\" - stores constraints, such as [Data::Checks](https://metacpan.org/pod/Data%3A%3AChecks), [Type::Tiny](https://metacpan.org/pod/Type%3A%3ATiny), [Moose::Meta::TypeConstraint](https://metacpan.org/pod/Moose%3A%3AMeta%3A%3ATypeConstraint), [Mouse::Meta::TypeConstraint](https://metacpan.org/pod/Mouse%3A%3AMeta%3A%3ATypeConstraint), [Specio](https://metacpan.org/pod/Specio), and more.\nThis module is useful for storing constraints in a package and exporting them to other packages. Following are the features of Kura:\n\n- Simple Declaration\n- Export Constraints\n- Store Favorite Constraints\n\n## FEATURES\n\n### Simple Declaration\n\n```perl\nuse kura NAME =\u003e CONSTRAINT;\n```\n\nKura makes it easy to declare constraints. This usage is same as [constant](https://metacpan.org/pod/constant) pragma!\nDefault implementation of `CONSTRAINT` can accept following these types:\n\n- Object having a `check` method\n\n    Many constraint libraries has a `check` method, such as [Type::Tiny](https://metacpan.org/pod/Type%3A%3ATiny), [Moose::Meta::TypeConstraint](https://metacpan.org/pod/Moose%3A%3AMeta%3A%3ATypeConstraint), [Mouse::Meta::TypeConstraint](https://metacpan.org/pod/Mouse%3A%3AMeta%3A%3ATypeConstraint), [Specio](https://metacpan.org/pod/Specio) and more. Kura accepts these objects.\n\n    ```perl\n    use Types::Common -types;\n    use kura Name =\u003e StrLength[1, 255];\n    ```\n\n- Allowed constraint classes\n\n    Kura allows these classes: [Data::Validator](https://metacpan.org/pod/Data%3A%3AValidator), [Poz::Types](https://metacpan.org/pod/Poz%3A%3ATypes). Here is an example of using [Poz](https://metacpan.org/pod/Poz):\n\n    ```perl\n    use Poz qw(z);\n    use kura Name  =\u003e z-\u003estring-\u003emin(1)-\u003emax(255);\n    ```\n\n- Code reference\n\n    Code reference makes Type::Tiny object internally.\n\n    ```perl\n    use kura Name =\u003e sub { length($_[0]) \u003e 0 };\n    # =\u003e Name isa Type::Tiny and check method equals to this coderef.\n    ```\n\n- Hash reference\n\n    Hash reference also makes Type::Tiny object internally.\n\n    ```perl\n    use kura Name =\u003e {\n        constraint =\u003e sub { length($_[0]) \u003e 0,\n        message    =\u003e sub { 'Invalid name' },\n    };\n    # =\u003e Name isa Type::Tiny\n    ```\n\n### Export Constraints\n\nKura allows you to export constraints to other packages using your favorite exporter such as [Exporter](https://metacpan.org/pod/Exporter), [Exporter::Tiny](https://metacpan.org/pod/Exporter%3A%3ATiny), and more.\n\n```perl\npackage MyPkg {\n    use parent 'Exporter::Tiny';\n    use Data::Checks qw(StrEq);\n\n    use kura Foo =\u003e StrEq('foo');\n}\n\nuse MyPkg qw(Foo);\nFoo-\u003echeck('foo'); # true\nFoo-\u003echeck('bar'); # false\n```\n\n### Store Favorite Constraints\n\nKura stores your favorite constraints such as [Data::Checks](https://metacpan.org/pod/Data%3A%3AChecks), [Type::Tiny](https://metacpan.org/pod/Type%3A%3ATiny), [Moose::Meta::TypeConstraint](https://metacpan.org/pod/Moose%3A%3AMeta%3A%3ATypeConstraint), [Mouse::Meta::TypeConstraint](https://metacpan.org/pod/Mouse%3A%3AMeta%3A%3ATypeConstraint), [Specio](https://metacpan.org/pod/Specio), [Data::Validator](https://metacpan.org/pod/Data%3A%3AValidator), [Poz::Types](https://metacpan.org/pod/Poz%3A%3ATypes) and more.\n\n```\nData::Checks -----------------\u003e +--------+\n                                |        |\nType::Tiny -------------------\u003e |        |\n                                |  Kura  | ---\u003e Named Value Constraints!\nMoose::Meta::TypeConstraint --\u003e |        |\n                                |        |\nYourFavoriteConstraint -------\u003e +--------+\n```\n\nIf your project uses multiple constraint libraries, kura allows you to simplify your codes and making it easier to manage different constraint systems. This is especially useful in large projects or when migrating from one constraint system to another.\nHere is an example of using multiple constraints:\n\n```perl\npackage MyFoo {\n    use Exporter 'import';\n    use Data::Checks qw(StrEq);\n    use kura Foo =\u003e StrEq('foo');\n}\n\npackage MyBar {\n    use Exporter 'import';\n    use Types::Standard -types;\n    use kura Bar =\u003e Str \u0026 sub { $_[0] eq 'bar' };\n}\n\npackage MyBaz {\n    use Exporter 'import';\n    use Moose::Util::TypeConstraints;\n    use kura Baz =\u003e subtype as 'Str' =\u003e where { $_[0] eq 'baz' };\n}\n\npackage MyQux {\n    use Exporter 'import';\n    use kura Qux =\u003e sub { $_[0] eq 'qux' };\n}\n\nuse MyFoo qw(Foo);\nuse MyBar qw(Bar);\nuse MyBaz qw(Baz);\nuse MyQux qw(Qux); # CodeRef converted to Type::Tiny\n\nok  Foo-\u003echeck('foo') \u0026\u0026 !Foo-\u003echeck('bar') \u0026\u0026 !Foo-\u003echeck('baz') \u0026\u0026 !Foo-\u003echeck('qux');\nok !Bar-\u003echeck('foo') \u0026\u0026  Bar-\u003echeck('bar') \u0026\u0026 !Bar-\u003echeck('baz') \u0026\u0026 !Bar-\u003echeck('qux');\nok !Baz-\u003echeck('foo') \u0026\u0026 !Baz-\u003echeck('bar') \u0026\u0026  Baz-\u003echeck('baz') \u0026\u0026 !Baz-\u003echeck('qux');\nok !Qux-\u003echeck('foo') \u0026\u0026 !Qux-\u003echeck('bar') \u0026\u0026 !Qux-\u003echeck('baz') \u0026\u0026  Qux-\u003echeck('qux');\n```\n\n## WHY USE KURA\n\nKura serves a similar purpose to [Type::Library](https://metacpan.org/pod/Type%3A%3ALibrary) which is bundled with [Type::Tiny](https://metacpan.org/pod/Type%3A%3ATiny) but provides distinct advantages in specific use cases:\n\n- Built-in Class Support\n\n    While Type::Library tightly integrates with Type::Tiny, Kura works with built-in classes.\n\n    ```perl\n    class Fruit {\n        use Exporter 'import';\n        use Types::Common -types;\n\n        # kura meets built-in class!\n        use kura Name =\u003e StrLength[1, 255];\n\n        field $name :param :reader;\n    }\n    ```\n\n- Simpler Declaration\n\n    Kura simplifies type constraint declarations. Unlike Type::Library, there's no need to write name twice.\n\n    Kura:\n\n    ```perl\n    use Exporter 'import';\n    use Types::Common -types;\n\n    use kura Name =\u003e StrLength[1, 255];\n    use kura Level =\u003e IntRange[1, 100];\n    use kura Player =\u003e Dict[ name =\u003e Name, level =\u003e Level ];\n    ```\n\n    Type::Library:\n\n    ```perl\n    use Types::Library -declare =\u003e [qw(Name Level Player)]; # Need to write name twice\n    use Types::Common -types;\n    use Type::Utils -all;\n\n    declare Name, as StrLength[1, 255];\n    declare Level, as IntRange[1, 100];\n    declare Player, as Dict[ name =\u003e Name, level =\u003e Level ];\n    ```\n\n- Minimal Exported Functions\n\n    Kura avoids the extra `is_*`, `assert_*`, and `to_*` functions exported by Type::Library.\n    This keeps your namespace cleaner and focuses on the essential `check` method.\n\n- Multiple Constraints\n\n    Kura is not limited to Type::Tiny. It supports multiple constraint libraries such as Moose, Mouse, Specio, Data::Checks and more. This flexibility allows consistent management of type constraints in projects that mix different libraries.\n\nWhile Type::Library is powerful and versatile, Kura stands out for its simplicity, flexibility, and ability to integrate with multiple constraint systems.\nIt’s particularly useful in projects where multiple type constraint libraries coexist or when leveraging built-in class syntax.\n\n## NOTE\n\n### Order of declaration\n\nWhen declaring constraints, it is important to define child constraints before their parent constraints to avoid errors.\nIf constraints are declared in the wrong order, you might encounter errors like **Bareword not allowed**. Ensure that all dependencies are declared beforehand to prevent such issues.\nFor example:\n\n```perl\n# Bad order\nuse kura Parent =\u003e Dict[ name =\u003e Child ]; # =\u003e Bareword \"Child\" not allowed\nuse kura Child =\u003e Str;\n\n# Good order\nuse kura Child =\u003e Str;\nuse kura Parent =\u003e Dict[ name =\u003e Child ];\n```\n\n### Need to load Exporter\n\nIf you forget to put `use Exporter 'import';`, you get an error like this:\n\n```perl\npackage MyFoo {\n    # use Exporter 'import'; # Forgot to load Exporter!!\n    use Data::Checks qw(StrEq);\n    use kura Foo =\u003e StrEq('foo');\n}\n\nuse MyFoo qw(Foo);\n# =\u003e ERROR!\nAttempt to call undefined import method with arguments (\"Foo\" ...) via package \"MyFoo\"\n(Perhaps you forgot to load the package?)\n```\n\n## `@EXPORT_OK` and `@KURA` are automatically set\n\nPackage variables `@EXPORT_OK` and `@KURA` are automatically set when you use `kura` in your package:\n\n```perl\npackage MyFoo {\n    use Exporter 'import';\n    use Types::Common -types;\n    use kura Foo1 =\u003e StrLength[1, 255];\n    use kura Foo2 =\u003e StrLength[1, 1000];\n\n    our @EXPORT_OK;\n    push @EXPORT_OK, qw(hello);\n\n    sub hello { 'Hello, Foo!' }\n}\n\n# Automatically set the caller package to MyFoo\nMyFoo::EXPORT_OK # =\u003e ('Foo1', 'Foo2', 'hello')\nMyFoo::KURA      # =\u003e ('Foo1', 'Foo2')\n```\n\nIt is useful when you want to export constraints. For example, you can tag `@KURA` with `%EXPORT_TAGS`:\n\n```perl\npackage MyBar {\n    use Exporter 'import';\n    use Types::Common -types;\n    use kura Bar1 =\u003e StrLength[1, 255];\n    use kura Bar2 =\u003e StrLength[1, 1000];\n\n    our %EXPORT_TAGS = (\n        types =\u003e \\@MyBar::KURA,\n    );\n}\n\nuse MyBar qw(:types);\n# =\u003e Bar1, Bar2 are exported\n```\n\nIf you don't want to export constraints, put a prefix `_` to the constraint name:\n\n```perl\nuse kura _PrivateFoo =\u003e Str;\n# =\u003e \"_PrivateFoo\" is not exported\n```\n\n## Customizing Constraints\n\nIf you want to customize constraints, `create_constraint` function is a hook point. You can override this function to customize constraints.\nFollowing are examples of customizing constraints:\n\n```perl\npackage mykura {\n    use kura ();\n    use MyConstraint;\n\n    sub import {\n        shift;\n        my ($name, $args) = @_;\n\n        my $caller = caller;\n\n        no strict 'refs';\n        local *{\"kura::create_constraint\"} = \\\u0026create_constraint;\n\n        kura-\u003eimport_into($caller, $name, $args);\n    }\n\n    sub create_constraint {\n        my ($args, $opts) = @_;\n        return (undef, \"Invalid mykura arguments\") unless (ref $args||'') eq 'HASH';\n        return (MyConstraint-\u003enew(%$args), undef);\n    }\n}\n\npackage main {\n    use mykura Name =\u003e { constraint =\u003e sub { length($_[0]) \u003e 0 } };\n}\n```\n\n# LICENSE\n\nCopyright (C) kobaken.\n\nThis library is free software; you can redistribute it and/or modify\nit under the same terms as Perl itself.\n\n# AUTHOR\n\nkobaken \u003ckentafly88@gmail.com\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkfly8%2Fkura","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkfly8%2Fkura","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkfly8%2Fkura/lists"}