{"id":16315156,"url":"https://github.com/robrwo/perl-data-enum","last_synced_at":"2026-06-09T04:07:23.838Z","repository":{"id":56838227,"uuid":"362572363","full_name":"robrwo/perl-Data-Enum","owner":"robrwo","description":"A perl library for generating fast, immutable enumeration classes.","archived":false,"fork":false,"pushed_at":"2024-12-18T14:32:18.000Z","size":132,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-31T09:22:30.408Z","etag":null,"topics":["enum","enumeration","enums","perl","perl-module","perl5"],"latest_commit_sha":null,"homepage":"","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robrwo.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-28T18:39:58.000Z","updated_at":"2024-12-18T14:33:03.000Z","dependencies_parsed_at":"2024-06-27T20:10:54.925Z","dependency_job_id":null,"html_url":"https://github.com/robrwo/perl-Data-Enum","commit_stats":{"total_commits":68,"total_committers":1,"mean_commits":68.0,"dds":0.0,"last_synced_commit":"579be43b972f9dd4871defa684d2944d34a25246"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrwo%2Fperl-Data-Enum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrwo%2Fperl-Data-Enum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrwo%2Fperl-Data-Enum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrwo%2Fperl-Data-Enum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robrwo","download_url":"https://codeload.github.com/robrwo/perl-Data-Enum/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238183506,"owners_count":19430131,"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":["enum","enumeration","enums","perl","perl-module","perl5"],"created_at":"2024-10-10T21:56:21.646Z","updated_at":"2026-06-09T04:07:23.831Z","avatar_url":"https://github.com/robrwo.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\nData::Enum - immutable enumeration classes\n\n# VERSION\n\nversion v0.7.0\n\n# SYNOPSIS\n\n```perl\nuse Data::Enum;\n\nmy $color = Data::Enum-\u003enew( qw[ red yellow blue green ] );\n\nmy $red = $color-\u003enew(\"red\");\n\n$red-\u003eis_red;    # \"1\"\n$red-\u003eis_yellow; # \"0\" (false)\n$red-\u003eis_blue;   # \"0\" (false)\n$red-\u003eis_green;  # \"0\" (false)\n\nsay $red;        # outputs \"red\"\n\n$red eq $color-\u003enew(\"red\"); # true\n\n$red eq \"red\"; # true\n```\n\n# DESCRIPTION\n\nThis module will create enumerated constant classes with the following\nproperties:\n\n- Any two classes with the same elements are equivalent.\n\n    The following two classes are the _same_:\n\n    ```perl\n    my $one = Data::Enum-\u003enew( qw[ foo bar baz ] );\n    my $two = Data::Enum-\u003enew( qw[ baz bar foo ] );\n    ```\n\n- All class instances are singletons.\n\n    ```perl\n    my $one = Data::Enum-\u003enew( qw[ foo bar baz ] );\n\n    my $a = $one-\u003enew(\"foo\")\n    my $b = $one-\u003enew(\"foo\");\n\n    refaddr($a) == refaddr($b); # they are the same thing\n    ```\n\n- Methods for checking values are fast.\n\n    ```\n    $a-\u003eis_foo; # constant time\n\n    $a eq $b;   # compares refaddr\n    ```\n\n- Values are immutable (read-only).\n\nThis is done by creating a unique internal class name based on the\npossible values.  Each value is actually a subclass of that class,\nwith the appropriate predicate method returning a constant.\n\n# METHODS\n\n## new\n\n```perl\nmy $class = Data::Enum-\u003enew( @values );\n```\n\nThis creates a new anonymous class. Values can be instantiated with a\nconstructor:\n\n```perl\nmy $instance = $class-\u003enew( $value );\n```\n\nCalling the constructor with an invalid value will throw an exception.\n\nEach instance will have a predicate `is_` method for each value.\n\nThe values are case sensitive.\n\nEach instance stringifies to its value.\n\nSince v0.3.0 you can change the specify options in the class generator:\n\n```perl\nmy $class = Data::Enum-\u003enew( \\%options, @values );\n```\n\nThe following options are supported:\n\n- prefix\n\n    Change prefix of the predicate methods to something other than `is_`. For example,\n\n    ```perl\n    my $class = Data::Enum-\u003enew( { prefix =\u003e \"from_\" }, \"home\", \"work\" );\n    my $place = $class-\u003enew(\"work\");\n\n    $place-\u003efrom_home;\n    ```\n\n    This was added in v0.3.0.\n\n- name\n\n    This assigns a name to the class, so instances can be constructed by name:\n\n    ```perl\n    my $class = Data::Enum-\u003enew( { name =\u003e \"Colours\" }, \"red\", \"orange\", \"yellow\", \"green\" );\n\n    my $color = Colours-\u003enew(\"yellow\");\n    ```\n\n    This was added in v0.5.0.\n\n## values\n\n```perl\nmy @values = $class-\u003evalues;\n```\n\nReturns a list of valid values, stringified and sorted with duplicates\nremoved.\n\nThis was added in v0.2.0.\n\n## predicates\n\n```perl\nmy @predicates = $class-\u003epredicates;\n```\n\nReturns a list of predicate methods for each value.\n\nA hash of predicates to values is roughly\n\n```perl\nuse List::Util 1.56 'mesh';\n\nmy %handlers = mesh [ $class-\u003evalues ], [ $class-\u003epredicates ];\n```\n\nThis was added in v0.2.1.\n\n## prefix\n\nThis returns the prefix.\n\nThis was added in v0.3.0.\n\n## MATCH\n\nThis method adds support for [match::simple](https://metacpan.org/pod/match%3A%3Asimple).\n\n## as\\_string\n\nThis stringifies the the object.\n\nThis was added in v0.4.0.\n\n# CAVEATS\n\nThe overheard of creating a new class instance and resolving methods may actually take more time than comparing simple\nstrings.  When using this in production code, you may want to benchmark performance.\n\n# SUPPORT FOR OLDER PERL VERSIONS\n\nThis module requires Perl v5.24 or later.\nFuture releases may only support Perl versions released in the last ten (10) years.\n\n# SEE ALSO\n\n[Class::Enum](https://metacpan.org/pod/Class%3A%3AEnum)\n\n[Object::Enum](https://metacpan.org/pod/Object%3A%3AEnum)\n\n[MooX::Enumeration](https://metacpan.org/pod/MooX%3A%3AEnumeration)\n\n[MooseX::Enumeration](https://metacpan.org/pod/MooseX%3A%3AEnumeration)\n\n[Type::Tiny::Enum](https://metacpan.org/pod/Type%3A%3ATiny%3A%3AEnum)\n\n# SOURCE\n\nThe development version is on github at [https://github.com/robrwo/perl-Data-Enum](https://github.com/robrwo/perl-Data-Enum)\nand may be cloned from [https://github.com/robrwo/perl-Data-Enum.git](https://github.com/robrwo/perl-Data-Enum.git)\n\n# BUGS\n\nPlease report any bugs or feature requests on the bugtracker website\n[https://github.com/robrwo/perl-Data-Enum/issues](https://github.com/robrwo/perl-Data-Enum/issues)\n\nWhen submitting a bug or request, please include a test-file or a\npatch to an existing test-file that illustrates the bug or desired\nfeature.\n\n## Reporting Security Vulnerabilities\n\nSecurity issues should not be reported on the bugtracker website. Please see `SECURITY.md` for instructions how to\nreport security vulnerabilities.\n\n# AUTHOR\n\nRobert Rothenberg \u003crrwo@cpan.org\u003e\n\n# COPYRIGHT AND LICENSE\n\nThis software is Copyright (c) 2021-2026 by Robert Rothenberg.\n\nThis is free software, licensed under:\n\n```\nThe Artistic License 2.0 (GPL Compatible)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobrwo%2Fperl-data-enum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobrwo%2Fperl-data-enum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobrwo%2Fperl-data-enum/lists"}