{"id":25812141,"url":"https://github.com/nigelhorne/params-get","last_synced_at":"2026-06-08T13:32:09.270Z","repository":{"id":279826198,"uuid":"940113424","full_name":"nigelhorne/Params-Get","owner":"nigelhorne","description":"Get the parameters to a subroutine in any way you want","archived":false,"fork":false,"pushed_at":"2025-02-27T22:04:45.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-27T23:36:15.632Z","etag":null,"topics":["cpan","cpan-module","parameters","perl","perl-module","perl5","perl5-module"],"latest_commit_sha":null,"homepage":"","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nigelhorne.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":"2025-02-27T16:28:47.000Z","updated_at":"2025-02-27T22:04:48.000Z","dependencies_parsed_at":"2025-02-27T23:49:27.028Z","dependency_job_id":null,"html_url":"https://github.com/nigelhorne/Params-Get","commit_stats":null,"previous_names":["nigelhorne/params-get"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nigelhorne%2FParams-Get","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nigelhorne%2FParams-Get/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nigelhorne%2FParams-Get/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nigelhorne%2FParams-Get/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nigelhorne","download_url":"https://codeload.github.com/nigelhorne/Params-Get/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241084691,"owners_count":19907171,"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":["cpan","cpan-module","parameters","perl","perl-module","perl5","perl5-module"],"created_at":"2025-02-28T01:24:45.859Z","updated_at":"2026-06-08T13:32:09.265Z","avatar_url":"https://github.com/nigelhorne.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\nParams::Get - Get the parameters to a subroutine in any way you want\n\n# VERSION\n\nVersion 0.14\n\n# DESCRIPTION\n\nExports a single function, `get_params`, which returns a given value.\n\nWhen used hand-in-hand with [Params::Validate::Strict](https://metacpan.org/pod/Params%3A%3AValidate%3A%3AStrict) and [Return::Set](https://metacpan.org/pod/Return%3A%3ASet),\nyou should be able to formally specify the input and output sets for a method.\n\n# SYNOPSIS\n\n    use Params::Get;\n    use Params::Validate::Strict;\n\n    sub where_am_i\n    {\n        my $params = Params::Validate::Strict::validate_strict({\n            args =\u003e Params::Get::get_params(undef, \\@_),\n            schema =\u003e {\n                'latitude' =\u003e {\n                    type =\u003e 'number',\n                    min =\u003e -90,\n                    max =\u003e 90\n                }, 'longitude' =\u003e {\n                    type =\u003e 'number',\n                    min =\u003e -180,\n                    max =\u003e 180\n                }\n            }\n        });\n\n        print 'You are at ', $params-\u003e{'latitude'}, ', ', $params-\u003e{'longitude'}, \"\\n\";\n    }\n\n    where_am_i(latitude =\u003e 0.3, longitude =\u003e 124);\n    where_am_i({ latitude =\u003e 3.14, longitude =\u003e -155 });\n\n# METHODS\n\n## get\\_params\n\nParse the arguments given to a function.\nProcesses arguments passed to methods and ensures they are in a usable format,\nallowing the caller to call the function in any way that they want\ne.g. \\`foo('bar')\\`, \\`foo(arg =\u003e 'bar')\\`, \\`foo({ arg =\u003e 'bar' })\\` all mean the same\nwhen called with\n\n    get_params('arg', @_);\n\nor\n\n    get_params('arg', \\@_);\n\nSome people like this sort of model, which is also supported.\n\n    use MyClass;\n\n    my $str = 'hello world';\n    my $obj = MyClass-\u003enew($str, { type =\u003e 'string' });\n\n    package MyClass;\n\n    use Params::Get;\n\n    sub new {\n        my $class = shift;\n        my $rc = Params::Get::get_params('value', \\@_);\n\n        return bless $rc, $class;\n    }\n\n## The `$default` Parameter\n\nThe first argument is the `$default` parameter controls how single-argument calls are interpreted and provides\na default key name for parameter extraction in those cases.\n\nWhen no arguments are provided with a defined `$default`:\n\n    get_params('required'); # Throws usage error\n\nThe function requires either arguments or an undefined `$default`.\n\n### Usage Examples\n\n- Simple scalar parameter:\n\n        sub set_country {\n            my $params = get_params('country', @_);\n            # Accepts: set_country('US')\n            # Returns: { country =\u003e 'US' }\n        }\n\n- Object constructor with options:\n\n        sub new {\n            my $class = shift;\n            my $params = get_params('value', @_);\n            # Accepts: MyClass-\u003enew($object)\n            # Accepts: MyClass-\u003enew($object, { option =\u003e 'value' })\n            # Returns: { value =\u003e $object } or { value =\u003e $object, option =\u003e 'value' }\n        }\n\n- Hash parameter:\n\n        sub configure {\n            my $params = get_params('config', @_);\n            # Accepts: configure({ db =\u003e 'mysql', host =\u003e 'localhost' })\n            # Returns: { config =\u003e { db =\u003e 'mysql', host =\u003e 'localhost' } }\n        }\n\n- Without default (named parameters only):\n\n        sub process {\n            my $params = get_params(undef, @_);\n            # Accepts: process(name =\u003e 'John', age =\u003e 30)\n            # Returns: { name =\u003e 'John', age =\u003e 30 }\n        }\n\n### Caveats\n\n- When `$default` is defined and no arguments are provided, an error is thrown\n- There's no way to specify that a default parameter is optional\n- Single hash references always bypass the default parameter naming\n\n# AUTHOR\n\nNigel Horne, `\u003cnjh at nigelhorne.com\u003e`\n\n# BUGS\n\nSometimes giving an array ref rather than array fails.\n\n# SEE ALSO\n\n- [Params::Smart](https://metacpan.org/pod/Params%3A%3ASmart)\n- [Params::Validate::Strict](https://metacpan.org/pod/Params%3A%3AValidate%3A%3AStrict)\n- [Return::Set](https://metacpan.org/pod/Return%3A%3ASet)\n- [Test Dashboard](https://nigelhorne.github.io/Params-Get/coverage/)\n\n# SUPPORT\n\nThis module is provided as-is without any warranty.\n\nPlease report any bugs or feature requests to `bug-params-get at rt.cpan.org`,\nor through the web interface at\n[http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Params-Get](http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Params-Get).\nI will be notified, and then you'll\nautomatically be notified of progress on your bug as I make changes.\n\nYou can find documentation for this module with the perldoc command.\n\n    perldoc Params::Get\n\nYou can also look for information at:\n\n- MetaCPAN\n\n    [https://metacpan.org/dist/Params-Get](https://metacpan.org/dist/Params-Get)\n\n- RT: CPAN's request tracker\n\n    [https://rt.cpan.org/NoAuth/Bugs.html?Dist=Params-Get](https://rt.cpan.org/NoAuth/Bugs.html?Dist=Params-Get)\n\n- CPAN Testers' Matrix\n\n    [http://matrix.cpantesters.org/?dist=Params-Get](http://matrix.cpantesters.org/?dist=Params-Get)\n\n- CPAN Testers Dependencies\n\n    [http://deps.cpantesters.org/?module=Params::Get](http://deps.cpantesters.org/?module=Params::Get)\n\n# LICENCE AND COPYRIGHT\n\nCopyright 2025-2026 Nigel Horne.\n\nUsage is subject to the GPL2 licence terms.\nIf you use it,\nplease let me know.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnigelhorne%2Fparams-get","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnigelhorne%2Fparams-get","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnigelhorne%2Fparams-get/lists"}