{"id":15019529,"url":"https://github.com/cxw42/class-tiny-constrainedaccessor","last_synced_at":"2026-03-14T20:14:05.200Z","repository":{"id":56837290,"uuid":"175229388","full_name":"cxw42/Class-Tiny-ConstrainedAccessor","owner":"cxw42","description":"Apply type constraints to your Class::Tiny attributes","archived":false,"fork":false,"pushed_at":"2019-11-24T00:22:47.000Z","size":90,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-13T00:42:38.967Z","etag":null,"topics":["accessor","class-tiny","oop","perl","perl5"],"latest_commit_sha":null,"homepage":"https://metacpan.org/pod/Class::Tiny::ConstrainedAccessor","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cxw42.png","metadata":{"files":{"readme":"README","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}},"created_at":"2019-03-12T14:29:47.000Z","updated_at":"2019-11-24T00:08:28.000Z","dependencies_parsed_at":"2022-09-09T23:20:10.668Z","dependency_job_id":null,"html_url":"https://github.com/cxw42/Class-Tiny-ConstrainedAccessor","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxw42%2FClass-Tiny-ConstrainedAccessor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxw42%2FClass-Tiny-ConstrainedAccessor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxw42%2FClass-Tiny-ConstrainedAccessor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxw42%2FClass-Tiny-ConstrainedAccessor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cxw42","download_url":"https://codeload.github.com/cxw42/Class-Tiny-ConstrainedAccessor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243318747,"owners_count":20272137,"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":["accessor","class-tiny","oop","perl","perl5"],"created_at":"2024-09-24T19:53:39.271Z","updated_at":"2025-12-25T20:49:09.598Z","avatar_url":"https://github.com/cxw42.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"NAME\n    Class::Tiny::ConstrainedAccessor - Generate Class::Tiny accessors that\n    apply type constraints\n\n    Class::Tiny uses custom accessors if they are defined before the \"use\n    Class::Tiny\" statement in a package.  This module creates custom accessors\n    that behave as standard \"Class::Tiny\" accessors except that they apply\n    type constraints (\"isa\" relationships).  Type constraints can come from\n    Type::Tiny, MooseX::Types, MooX::Types::MooseLike, MouseX::Types, or\n    Specio.  Alternatively, constraints can be applied using the technique\n    described in \"Constraints without a type system\".\n\n    Example of a class using this package:\n\n        package SampleClass;\n        use Scalar::Util qw(looks_like_number);\n\n        use Type::Tiny;\n\n        # Create the type constraint\n        use vars::i '$MediumInteger' = Type::Tiny-\u003enew(\n            name =\u003e 'MediumInteger',\n            constraint =\u003e sub { looks_like_number($_) and $_ \u003e= 10 and $_ \u003c 20 }\n        );\n\n        use Class::Tiny::ConstrainedAccessor {\n            medint =\u003e $MediumInteger,           # create accessor sub medint()\n            med_with_default =\u003e $MediumInteger,\n        };\n\n        # After using ConstrainedAccessor, actually define the class attributes.\n        use Class::Tiny qw(medint regular), {\n            med_with_default =\u003e 12,\n        };\n\nCONSTRAINTS WITHOUT A TYPE SYSTEM\n    If you don't want to use Type::Tiny or one of the other type systems\n    listed above, you can create your own constraints as two-element\n    arrayrefs.  Example:\n\n        use Class::Tiny::ConstrainedAccessor\n            'field' =\u003e [ \\\u0026checker_sub, \\\u0026message_sub ];\n\n    \"checker_sub\" and \"message_sub\" are used as follows to check $value:\n\n        checker_sub($value) or die get_message($value);\n\n    Therefore, \"checker_sub\" must return truthy if $_[0] passes the\n    constraint, or else falsy.  \"get_message\" must return something that can\n    be passed to \"die()\", when given a $_[0] that has failed the constraint.\n\n    If your profile ever tells you that constraint-checks are on the critical\n    path, try custom constraints.  They may give you more control or\n    opportunity for optimization than general-purpose type systems.\n\nSUBROUTINES\n  import\n    Creates the accessors you have requested.  Constraints can be passed as a\n    list or hashref of variable/constraint pairs.  Basic usage:\n\n        # Constraints are passed as a list of pairs\n        use Class::Tiny::ConstrainedAccessor\n            name =\u003e constraint\n            [, name2 =\u003e constraint ...]; # ... any number of name=\u003econstraint pairs\n\n        # Constraints are passed as a hashref\n        use Class::Tiny::ConstrainedAccessor {\n            name =\u003e constraint,\n            [, name2 =\u003e constraint ...]; # ... any number of name=\u003econstraint pairs\n        };\n\n    This also creates a BUILD() subroutine to check the constructor\n    parameters, if a \"BUILD()\" doesn't already exist.\n\n    If a \"BUILD()\" does exist (e.g., you said \"use subs 'BUILD';\"), this\n    package will create the same function, taking the same parameters as\n    \"BUILD()\" would, but call it \"_check_all_constraints()\".  You can call\n    this checker from your own \"BUILD()\" if you want to.\n\nOPTIONS\n    To specify options, pass an arrayref as the first argument on the `use`\n    line.  This is because a hashref carries attributes and constraints.  For\n    example:\n\n        use Class::Tiny::ConstrainedAccessor [ OPTION=\u003evalue ],\n            name =\u003e constraint ...;\n\n    Valid options are:\n\n    NOBUILD\n        If \"NOBUILD =\u003e 1\" is given, the constructor-parameter-checker is\n        created as \"_check_all_constraints\" regardless of whether \"BUILD()\"\n        exists or not.  Example:\n\n            package MyClass;\n            use Class::Tiny::ConstrainedAccessor\n                [NOBUILD =\u003e 1],\n                foo =\u003e SomeConstraint;\n            # Now $object-\u003e_check_all_constraints($args) exists, but not BUILD().\n\nAUTHORS\n    Created by Christopher White, \"\u003ccxwembedded at gmail.com\u003e\".  Thanks to\n    Toby Inkster (TOBYINK) and Ivan Butorin (FISHBONE) for code contributions.\n\nBUGS\n    Please report any bugs or feature requests through the GitHub Issues\n    interface at\n    \u003chttps://github.com/cxw42/Class-Tiny-ConstrainedAccessor/issues\u003e.  I will\n    be notified, and then you'll automatically be notified of progress on your\n    bug as I make changes.\n\nSUPPORT\n    You can find documentation for this module with the perldoc command.\n\n        perldoc Class::Tiny::ConstrainedAccessor\n\n    You can also look for information at:\n\n    *   GitHub (report bugs here)\n\n        \u003chttps://github.com/cxw42/Class-Tiny-ConstrainedAccessor\u003e\n\n    *   MetaCPAN\n\n        \u003chttps://metacpan.org/pod/Class::Tiny::ConstrainedAccessor\u003e\n\nLICENSE\n    Copyright 2019 Christopher White and contributors.\n\n    This program is free software; you can redistribute it and/or modify it\n    under the terms of the the Apache License (2.0). You may obtain a copy of\n    the full license at:\n\n    \u003chttps://www.apache.org/licenses/LICENSE-2.0\u003e\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the\n    License for the specific language governing permissions and limitations\n    under the License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcxw42%2Fclass-tiny-constrainedaccessor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcxw42%2Fclass-tiny-constrainedaccessor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcxw42%2Fclass-tiny-constrainedaccessor/lists"}