{"id":15015778,"url":"https://github.com/kfly8/kote","last_synced_at":"2026-03-14T08:36:50.425Z","repository":{"id":218445265,"uuid":"746064558","full_name":"kfly8/kote","owner":"kfly8","description":"Type::Tiny based type framework","archived":false,"fork":false,"pushed_at":"2024-08-15T04:35:04.000Z","size":77,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-19T17:11:14.295Z","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-01-21T00:22:15.000Z","updated_at":"2024-08-09T08:27:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"506f1fc1-7083-49cf-996a-13dc85ae3a04","html_url":"https://github.com/kfly8/kote","commit_stats":null,"previous_names":["kfly8/caseval","kfly8/kote"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfly8%2Fkote","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfly8%2Fkote/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfly8%2Fkote/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kfly8%2Fkote/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kfly8","download_url":"https://codeload.github.com/kfly8/kote/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243313631,"owners_count":20271218,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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:54.954Z","updated_at":"2025-12-25T08:52:14.866Z","avatar_url":"https://github.com/kfly8.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Actions Status](https://github.com/kfly8/kote/actions/workflows/test.yml/badge.svg)](https://github.com/kfly8/kote/actions) [![Coverage Status](https://img.shields.io/coveralls/kfly8/kote/main.svg?style=flat)](https://coveralls.io/r/kfly8/kote?branch=main) [![MetaCPAN Release](https://badge.fury.io/pl/kote.svg)](https://metacpan.org/release/kote)\n# NAME\n\nkote - Type::Tiny based type framework\n\n# SYNOPSIS\n\n```perl\nuse Types::Standard -types;\n\nuse kote CharacterName  =\u003e Str \u0026 sub { /^[A-Z][a-z]+$/ };\nuse kote CharacterLevel =\u003e Int \u0026 sub { $_ \u003e= 1 \u0026\u0026 $_ \u003c= 100 };\n\nuse kote Character =\u003e Dict[\n    name  =\u003e CharacterName,\n    level =\u003e CharacterLevel,\n];\n\nmy ($alice, $err) = Character-\u003ecreate({ name =\u003e 'Alice', level =\u003e 1 });\nsay $alice-\u003e{name}; # Alice\nsay $err; # undef\n\nmy ($bob, $err) = Character-\u003ecreate({ name =\u003e 'bob', level =\u003e 0 });\nsay $bob; # undef\nsay $err; # Error!\n```\n\n# DESCRIPTION\n\nKote - **means \"gauntlet\"🧤 in Japanese** - is a type framework based on Type::Tiny.\nKote aims to simplify type declarations and value checks in Perl.\n\n## FEATURES\n\n- Simplify Type Declarations\n\n    Type declarations just need to write in one place.\n\n    ```perl\n    use kote CharacterName =\u003e Str \u0026 sub { /^[A-Z][a-z]+$/ };\n    ```\n\n- Easy to Check Values\n\n    Only legal values can be created.\n\n    ```perl\n    my ($alice, $err) = CharacterName-\u003ecreate('Alice');\n    croak $err if $err; # Must handle error!\n    ```\n\n- Type::Tiny Based\n\n    The types declared by Kote are based on Type::Tiny, so we can use Type::Tiny's all features.\n\n    ```\n    CharacterName-\u003eisa('Type::Tiny'); # true\n    ```\n\n# CONCEPTS\n\nKote is inspired by the following book, [Domain Modeling Made Functional](https://pragprog.com/titles/swdddf/).\n\nThe phrase \"Make illegal states unrepresentable\" is a particularly important concept in Kote.\nThis idea works for dynamically typed languages like Perl too. By clearly stating the legal values, it make to easier to maintain codes.\n\n# DETAILS\n\n## Declare types\n\nKote provides a syntax for declaring types.\n\n```perl\nuse kote TYPE_NAME =\u003e TYPE_CONSTRAINT;\n```\n\nThe first argument is a type name, and the second argument is a type constraint.\nType name must begin with an uppercase letter and can only contain alphabetic letter, digits and underscores.\nType constraints must be a Type::Tiny object or something that can be converted to one.\n\nUsing Kote inherits [Exporter::Tiny](https://metacpan.org/pod/Exporter%3A%3ATiny) and automatically adds the declared type to `@EXPORT_OK`.\nThis means you can import types as follows:\n\n```perl\npackage main;\nuse My::Character qw(CharacterName);\n\nCharacterName-\u003echeck('Alice'); # true\n```\n\nOrder of type declarations is important, child types must be declared before parent types.\n\n```perl\n# Bad order\nuse kote Parent =\u003e Dict[ name =\u003e Child ];\nuse kote Child =\u003e Str;\n\n# Good order\nuse kote Child =\u003e Str;\nuse kote Parent =\u003e Dict[ name =\u003e Child ];\n```\n\n## Create value method\n\nThe type declared in Kote has a `create` method.\n\n```perl\nmy ($alice, $err) = Character-\u003ecreate({name =\u003e 'Alice', level =\u003e 1});\ncroak $err if $err;\n```\n\nThe `create` method returns a error message if the given value does not satisfy the type, and returns the value if it does:\n\n```\ncreate(Any $value) -\u003e (Any $value, undef) or (undef, Str $error)\n```\n\nIf the value is a reference, it will be converted to an immutable:\n\n```\n$alice-\u003e{name} = 'Bob'; # Error\n$alice-\u003e{unknown}; # Error\n```\n\nAn exception is thrown if an error is not handled. Calling the create method in scalar or void context will throw an exception:\n\n```perl\nmy $alice = Character-\u003ecreate({name =\u003e 'Alice', level =\u003e 1});\n# =\u003e Exception: Must handle error!!\n```\n\n# TIPS\n\n## Export Functions\n\nYou can export functions as well as types by pushing them to `@EXPORT_OK`.\n\n```perl\npackage My::Character {\n    our @EXPORT_OK;\n    push @EXPORT_OK, qw(is_alice);\n\n    use kote CharacterName =\u003e Str \u0026 sub { /^[A-Z][a-z]+$/ };\n\n    sub is_alice($name) { $name eq 'Alice' }\n}\n\npackage main;\nuse My::Character qw(CharacterName is_alice);\n```\n\n## Skip Check Value\n\nIf `$ENV{KOTE_STRICT}` is set to false during the BEGIN phase, the validation of the value and the conversion to make it immutable are skipped. However, be careful not to skip values that need to be validated.\n\n```perl\nBEGIN {\n    $ENV{KOTE_STRICT} = 0;\n}\n\nuse kote Name =\u003e Str \u0026 sub { /^[A-Z][a-z]+$/ };\n\nmy ($alice, $err) = Name-\u003ecreate(1234);\n$err; # No Error\n```\n\nIf `$ENV{KOTE_STRICT}` is set to false but you still want to perform validation, you should use the `strictly_create` method instead of the `create` method.\n\n```perl\nmy ($alice, $err) = Name-\u003estrictly_create(1234);\n$err; # Error!!\n```\n\n# THANKS\n\nToby Inkster, the author of [Type::Tiny](https://metacpan.org/pod/Type%3A%3ATiny).\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%2Fkote","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkfly8%2Fkote","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkfly8%2Fkote/lists"}