{"id":24493357,"url":"https://github.com/peczenyj/moox-role-parameterized","last_synced_at":"2025-04-14T02:07:51.122Z","repository":{"id":35458263,"uuid":"39725752","full_name":"peczenyj/MooX-Role-Parameterized","owner":"peczenyj","description":"MooX::Role::Parameterized - roles with composition parameters","archived":false,"fork":false,"pushed_at":"2024-01-04T10:19:27.000Z","size":127,"stargazers_count":1,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"devel","last_synced_at":"2025-04-14T02:07:43.486Z","etag":null,"topics":["perl","perl5"],"latest_commit_sha":null,"homepage":"","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peczenyj.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog","contributing":"CONTRIBUTING.pod","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2015-07-26T13:05:11.000Z","updated_at":"2024-01-03T18:46:32.000Z","dependencies_parsed_at":"2024-06-19T10:08:41.398Z","dependency_job_id":null,"html_url":"https://github.com/peczenyj/MooX-Role-Parameterized","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/peczenyj%2FMooX-Role-Parameterized","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peczenyj%2FMooX-Role-Parameterized/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peczenyj%2FMooX-Role-Parameterized/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peczenyj%2FMooX-Role-Parameterized/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peczenyj","download_url":"https://codeload.github.com/peczenyj/MooX-Role-Parameterized/tar.gz/refs/heads/devel","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248809044,"owners_count":21164896,"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","perl5"],"created_at":"2025-01-21T19:39:24.275Z","updated_at":"2025-04-14T02:07:51.089Z","avatar_url":"https://github.com/peczenyj.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\nMooX::Role::Parameterized - roles with composition parameters\n\n[![Kwalitee](https://cpants.cpanauthors.org/dist/MooX-Role-Parameterized.svg)](https://cpants.cpanauthors.org/dist/MooX-Role-Parameterized)\n[![tests](https://github.com/peczenyj/MooX-Role-Parameterized/actions/workflows/linux.yml/badge.svg)](https://github.com/peczenyj/MooX-Role-Parameterized/actions/workflows/linux.yml)\n[![tests](https://github.com/peczenyj/MooX-Role-Parameterized/actions/workflows/windows.yml/badge.svg)](https://github.com/peczenyj/MooX-Role-Parameterized/actions/workflows/windows.yml)\n[![tests](https://github.com/peczenyj/MooX-Role-Parameterized/actions/workflows/macos.yml/badge.svg)](https://github.com/peczenyj/MooX-Role-Parameterized/actions/workflows/macos.yml)\n[![tests](https://github.com/peczenyj/MooX-Role-Parameterized/actions/workflows/perltidy.yml/badge.svg)](https://github.com/peczenyj/MooX-Role-Parameterized/actions/workflows/perltidy.yml)\n[![tests](https://github.com/peczenyj/MooX-Role-Parameterized/actions/workflows/perlcritic.yml/badge.svg)](https://github.com/peczenyj/MooX-Role-Parameterized/actions/workflows/perlcritic.yml)\n[![Coverage Status](https://coveralls.io/repos/github/peczenyj/MooX-Role-Parameterized/badge.svg?branch=master)](https://coveralls.io/github/peczenyj/MooX-Role-Parameterized?branch=master)\n[![license](https://img.shields.io/cpan/l/MooX-Role-Parameterized.svg)](https://github.com/peczenyj/MooX-Role-Parameterized/blob/master/LICENSE)\n[![cpan](https://img.shields.io/cpan/v/MooX-Role-Parameterized.svg)](https://metacpan.org/dist/MooX-Role-Parameterized)\n\n## SYNOPSIS\n\n    package Counter;\n    use Moo::Role;\n    use MooX::Role::Parameterized;\n    use Types::Standard qw( Str );\n\n    parameter name =\u003e (\n        is       =\u003e 'ro',  # this is mandatory on Moo\n        isa      =\u003e Str,   # optional type\n        required =\u003e 1,     # mark the parameter \"name\" as \"required\"\n    );\n\n    role {\n        my ( $p, $mop ) = @_;\n\n        my $name = $p-\u003ename; # $p-\u003e{name} will also work\n    \n        $mop-\u003ehas($name =\u003e (\n            is      =\u003e 'rw',\n            default =\u003e sub { 0 },\n        ));\n    \n        $mop-\u003emethod(\"increment_$name\" =\u003e sub {\n            my $self = shift;\n            $self-\u003e$name($self-\u003e$name + 1);\n        });\n    \n        $mop-\u003emethod(\"reset_$name\" =\u003e sub {\n            my $self = shift;\n            $self-\u003e$name(0);\n        });\n    };\n    \n    package MyGame::Weapon;\n    use Moo;\n    use MooX::Role::Parameterized::With;\n    \n    with Counter =\u003e {          # injects 'enchantment' attribute and\n        name =\u003e 'enchantment', # methods increment_enchantment (+1)\n    };                         # reset_enchantment (set to zero)\n    \n    package MyGame::Wand;\n    use Moo;\n    use MooX::Role::Parameterized::With;\n\n    with Counter =\u003e {         # injects 'zapped' attribute and\n        name =\u003e 'zapped',     # methods increment_zapped (+1)\n    };                        # reset_zapped (set to zerà)\n\n## DESCRIPTION\n\nIt is an **experimental** port of [MooseX::Role::Parameterized](https://metacpan.org/pod/MooseX::Role::Parameterized) to [Moo](https://metacpan.org/pod/Moo).\n\n## FUNCTIONS\n\nThis package exports the following subroutines: `parameter`, `role`, `apply_roles_to_target` and `apply`.\n\n### parameter\n\nThis function receive the same parameter as `Moo::has`. If present, the parameter hash reference will be blessed as a Moo class. This is useful to add default values or set some parameters as required.\n\n### role\n\nThis function accepts just **one** code block. Will execute this code then we apply the Role in the\ntarget class and will receive the parameter hash reference + one **mop** object.\n\nThe **params** reference will be blessed if there is some parameter defined on this role.\n\nThe **mop** object is a proxy to the target class.\n\nIt offer a better way to call `has`, `after`, `before`, `around`, `with` and `requires` without side effects.\n\nUse `method` to inject a new method and `meta` to access `TARGET_PACKAGE-\u003emeta`\n\nPlease use:\n\n    my ($p, $mop) = @_;\n    ...\n    $mop-\u003ehas($p-\u003e{attribute} =\u003e(...));\n\n    $mop-\u003emethod(name =\u003e sub { ... });\n\n    $mop-\u003emeta-\u003emake_immutable;\n\n### apply\n\nAlias to `apply_roles_to_target`.\n\n### apply_roles_to_target\n\nWhen called, will apply the `/role` on the current package. The behavior depends of the parameter list.\n\nThis will install the role in the target package. Does not need call `with`.\n\nImportant, if you want to apply the role multiple times, like to create multiple attributes, please pass an **arrayref**.\n\n    package My::Role;\n\n    use Moo::Role;\n    use MooX::Role::Parameterized;\n\n    role {\n        my ($params, $mop) = @_;\n\n        $mop-\u003ehas( $params-\u003e{attr} =\u003e ( is =\u003e 'rw' ));\n\n        $mop-\u003emethod($params-\u003e{method} =\u003e sub {\n            1024;\n        });\n    };\n\n    package My::Class;\n\n    use Moo;\n    use My::Role;\n\n    My::Role-\u003eapply_roles_to_target([{ # original way of add this role\n        attr   =\u003e 'baz',               # add attribute read-write called 'baz' \n        method =\u003e 'run'                # add method called 'run' and return 1024 \n    }\n     ,                                 # and if the apply receives one arrayref\n    {   attr   =\u003e 'bam',               # will call the role block multiple times.\n        method =\u003e 'jump'               # PLEASE CALL apply once\n    }]);\n\n## MooX::Role::Parameterized::VERBOSE\n\nBy setting `$MooX::Role::Parameterized::VERBOSE` with some true value we will carp on certain conditions\n(method override, unable to load package, etc).\n\nDefault is false.\n\n## DEPRECATED FUNCTIONS\n\n### hasp\n\nDeleted\n\n### method\n\nDeleted\n\n## MooX::Role::Parameterized::With\n\nSee [MooX::Role::Parameterized::With](https://metacpan.org/pod/MooX::Role::Parameterized::With) package to easily load and apply roles.\n\n\nAllow to do this:\n\n    package FooWith;\n\n    use Moo;\n    use MooX::Role::Parameterized::With; # overrides Moo::with\n\n    with \"Bar\" =\u003e {           # apply parameterized role Bar once\n        attr =\u003e 'baz',\n        method =\u003e 'run'\n    }, \"Other::Role\" =\u003e [     # apply parameterized role \"Other::Role\" twice\n        { ... },              # with different parameters\n        { ... },\n        ],\n        \"Some::Moo::Role\",\n        \"Some::Role::Tiny\";\n\n    has foo =\u003e ( is =\u003e 'ro'); # continue with normal Moo code\n\n## SEE ALSO\n\n[MooseX::Role::Parameterized](https://metacpan.org/pod/MooseX::Role::Parameterized) - Moose version\n\n## THANKS\n\n* FGA \u003cfabrice.gabolde@gmail.com\u003e\n* PERLANCAR \u003cperlancar@gmail.com\u003e\n* CHOROBA \u003cchoroba@cpan.org\u003e\n* Ed J \u003cmohawk2@users.noreply.github.com\u003e\n\n## LICENSE\n\nThe MIT License\n\n    Permission is hereby granted, free of charge, to any person\n    obtaining a copy of this software and associated\n    documentation files (the \"Software\"), to deal in the Software\n    without restriction, including without limitation the rights to\n    use, copy, modify, merge, publish, distribute, sublicense,\n    and/or sell copies of the Software, and to permit persons to\n    whom the Software is furnished to do so, subject to the\n    following conditions:\n     \n     The above copyright notice and this permission notice shall\n     be included in all copies or substantial portions of the\n     Software.\n      \n      THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT\n      WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,\n      INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n      MERCHANTABILITY, FITNESS FOR A PARTICULAR\n      PURPOSE AND NONINFRINGEMENT. IN NO EVENT\n      SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n      LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n      LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n      TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n      CONNECTION WITH THE SOFTWARE OR THE USE OR\n      OTHER DEALINGS IN THE SOFTWARE.\n\n## AUTHOR\n\nTiago Peczenyj \u003ctiago (dot) peczenyj (at) gmail (dot) com\u003e\n\n## BUGS\n\nPlease report any bugs or feature requests on the bugtracker website\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeczenyj%2Fmoox-role-parameterized","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeczenyj%2Fmoox-role-parameterized","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeczenyj%2Fmoox-role-parameterized/lists"}