{"id":50396866,"url":"https://github.com/davenonymous/perl-object-padx-enum","last_synced_at":"2026-05-30T21:30:23.190Z","repository":{"id":357699969,"uuid":"1237104272","full_name":"davenonymous/perl-object-padx-enum","owner":"davenonymous","description":"Syntactic sugar for Enum-like singleton-bearing Object::Pad classes","archived":false,"fork":false,"pushed_at":"2026-05-13T22:35:42.000Z","size":51,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-05-14T00:39:48.366Z","etag":null,"topics":["enums","object-pad","perl"],"latest_commit_sha":null,"homepage":"https://metacpan.org/pod/Object::PadX::Enum","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/davenonymous.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":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-05-12T22:01:37.000Z","updated_at":"2026-05-13T22:35:46.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/davenonymous/perl-object-padx-enum","commit_stats":null,"previous_names":["davenonymous/perl-object-padx-enum"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/davenonymous/perl-object-padx-enum","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davenonymous%2Fperl-object-padx-enum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davenonymous%2Fperl-object-padx-enum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davenonymous%2Fperl-object-padx-enum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davenonymous%2Fperl-object-padx-enum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davenonymous","download_url":"https://codeload.github.com/davenonymous/perl-object-padx-enum/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davenonymous%2Fperl-object-padx-enum/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33711018,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-30T02:00:06.278Z","response_time":92,"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":["enums","object-pad","perl"],"created_at":"2026-05-30T21:30:22.003Z","updated_at":"2026-05-30T21:30:23.186Z","avatar_url":"https://github.com/davenonymous.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\n`Object::PadX::Enum` - syntactic sugar for enum-like singleton-bearing `Object::Pad` classes\n\n# SYNOPSIS\n\n```perl\nuse Object::PadX::Enum;\n\nenum Raptor {\n   item VELOCIRAPTOR   ( max_speed_kmh =\u003e 60, max_weight_kg =\u003e  15, max_height_cm =\u003e  50 );\n   item DEINONYCHUS    ( max_speed_kmh =\u003e 50, max_weight_kg =\u003e  80, max_height_cm =\u003e  87 );\n   item UTAHRAPTOR     ( max_speed_kmh =\u003e 35, max_weight_kg =\u003e 500, max_height_cm =\u003e 150 );\n   item MICRORAPTOR    ( max_speed_kmh =\u003e 40, max_weight_kg =\u003e   1, max_height_cm =\u003e  30 );\n   item DROMAEOSAURUS  ( max_speed_kmh =\u003e 60, max_weight_kg =\u003e  15, max_height_cm =\u003e  50 );\n\n   field $max_speed_kmh  :param :reader;\n   field $max_weight_kg  :param :reader;\n   field $max_height_cm  :param :reader;\n\n   method speed_per_kg { return $max_speed_kmh / $max_weight_kg }\n   method speed_per_cm { return $max_speed_kmh / $max_height_cm }\n\n   method fastest :common {\n      my ( $top ) = sort { $b-\u003emax_speed_kmh \u003c=\u003e $a-\u003emax_speed_kmh } $class-\u003evalues;\n      return $top;\n   }\n}\n\nsay Raptor-\u003eVELOCIRAPTOR-\u003emax_speed_kmh;  # 60\nsay Raptor-\u003eDEINONYCHUS-\u003espeed_per_kg;    # 0.625\nsay Raptor-\u003efrom_ordinal(2)-\u003ename;        # UTAHRAPTOR\nsay Raptor-\u003efrom_name(\"MICRORAPTOR\")-\u003espeed_per_cm; # 1.33333333333333\nsay 'Fastest in absolute terms: ', Raptor-\u003efastest-\u003ename; # VELOCIRAPTOR or DROMAEOSAURUS (tie)\n```\n\n# DESCRIPTION\n\n`Object::PadX::Enum` adds two keywords on top of [Object::Pad](https://metacpan.org/pod/Object%3A%3APad):\n\n- `enum NAME ATTRS? { ... }`\n\n    Declares a class (using [Object::Pad](https://metacpan.org/pod/Object%3A%3APad)'s `class` machinery) and auto-injects\n    `$ordinal :reader` and `name :reader` fields. The `name` reader returns the\n    identifier under which the singleton was declared (e.g. `\"RED\"`). Inside the\n    block, all normal `Object::Pad` constructs (`field`, `method`, `ADJUST`,\n    ...) are available, plus the `item` keyword.\n\n    The following class-level attributes are accepted:\n\n    - `:isa(CLASS)`, `:isa(CLASS VERSION)`\n    - `:extends(CLASS)`, `:extends(CLASS VERSION)`\n\n        Declares a superclass; equivalent to [Object::Pad](https://metacpan.org/pod/Object%3A%3APad)'s `:isa`. The package is\n        loaded automatically. If a VERSION is given, `CLASS-\u003eVERSION(VERSION)` is\n        called to enforce it.\n\n        An `enum` may inherit from another `enum`. Fields, methods, roles and\n        `ADJUST` phasers from the parent are inherited normally. The parent's\n        **items** are _not_ inherited: the child has its own ordinal-zero-based item\n        sequence, and accessing a parent item name on the child raises an error. The\n        child's `values`, `from_ordinal` and `from_name` see only the child's\n        items. A parent enum must be finalized (i.e. its declaration must have\n        already executed at runtime) before a child enum that inherits from it; in\n        practice this is satisfied by normal source ordering and `use` ordering.\n\n    - `:does(ROLE)`, `:does(ROLE VERSION)`\n\n        Composes a role into the enum class. May be repeated for multiple roles. The\n        role package is loaded automatically.\n\n    The class attributes `:abstract`, `:strict`, `:repr` and `:lexical_new`\n    are not supported. `:abstract` is semantically incompatible with `item`\n    (singletons cannot be constructed for an abstract class); the others have no\n    public [Object::Pad::MOP::Class](https://metacpan.org/pod/Object%3A%3APad%3A%3AMOP%3A%3AClass) entry point and would require reaching into\n    private Object::Pad internals.\n\n- `item NAME ( ARGS );`\n\n    Declares a named singleton instance of the enclosing `enum`. `ARGS` is the\n    key/value list passed to the auto-generated constructor; the parentheses (and\n    the arg list) are optional, so `item FOO;` is equivalent to `item FOO();`.\n\nAfter the `enum` block closes, the following class-level methods are\ninstalled on the enum class for each declared singleton `NAME`:\n\n```perl\n$singleton = ClassName-\u003eNAME;          # the named singleton\n@all       = ClassName-\u003evalues;        # all singletons in declaration order\n$byord     = ClassName-\u003efrom_ordinal(0);\n$byname    = ClassName-\u003efrom_name(\"RED\");\n```\n\nDirect construction via `ClassName-\u003enew(...)` is blocked after the\n`enum` block closes; the only ways to obtain a singleton are the per-item\naccessor, `from_name`, and `from_ordinal`. Subclasses (whether plain\n`class` or another `enum`) may still call `new` on themselves; the block\napplies only to direct invocation on the enum class itself.\n\n# CAVEATS\n\n- User `field`s require explicit `:param` if you intend to set them via\n`item` args. `Object::PadX::Enum` does _not_ inject `:param` automatically.\n- Singletons are constructed at the runtime of the compilation unit that\ncontains the `enum` declaration, after that unit's `UNITCHECK` phase. They\nare therefore not visible from earlier `BEGIN`/`UNITCHECK` blocks of the\nsame unit. Normal runtime code (including code inside `do BLOCK` and\n`eval \"STRING\"` blocks executed during main runtime) sees them as expected.\n- `enum`-level `:abstract`, `:strict`, `:repr` and `:lexical_new` are not\nsupported. See the description of the `enum` keyword above for the rationale;\n`:isa` and `:does` _are_ supported.\n- The names `values`, `from_ordinal`, `from_name`, `ordinal` and `name` are\nreserved and must not be used as `item` names.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavenonymous%2Fperl-object-padx-enum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavenonymous%2Fperl-object-padx-enum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavenonymous%2Fperl-object-padx-enum/lists"}