{"id":15286210,"url":"https://github.com/cxw42/sub-multi-tiny","last_synced_at":"2026-02-07T10:02:27.225Z","repository":{"id":56835970,"uuid":"205061180","full_name":"cxw42/Sub-Multi-Tiny","owner":"cxw42","description":"Multisub/multimethod (multiple-dispatch subroutine) implementation for Perl","archived":false,"fork":false,"pushed_at":"2022-10-30T01:16:17.000Z","size":102,"stargazers_count":0,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-29T04:42:50.908Z","etag":null,"topics":["multimethod","multimethods","multiple-dispatch","multisub","multisubs","perl","perl5","perl5-module"],"latest_commit_sha":null,"homepage":"https://metacpan.org/pod/Sub::Multi::Tiny","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cxw42.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}},"created_at":"2019-08-29T02:10:52.000Z","updated_at":"2022-10-30T01:16:20.000Z","dependencies_parsed_at":"2022-09-07T07:10:35.332Z","dependency_job_id":null,"html_url":"https://github.com/cxw42/Sub-Multi-Tiny","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%2FSub-Multi-Tiny","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxw42%2FSub-Multi-Tiny/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxw42%2FSub-Multi-Tiny/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxw42%2FSub-Multi-Tiny/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cxw42","download_url":"https://codeload.github.com/cxw42/Sub-Multi-Tiny/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245169958,"owners_count":20571982,"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":["multimethod","multimethods","multiple-dispatch","multisub","multisubs","perl","perl5","perl5-module"],"created_at":"2024-09-30T15:10:59.390Z","updated_at":"2026-02-07T10:02:27.179Z","avatar_url":"https://github.com/cxw42.png","language":"Perl","readme":"[![Build Status](https://travis-ci.org/cxw42/Sub-Multi-Tiny.svg?branch=master)](https://travis-ci.org/cxw42/Sub-Multi-Tiny)\n# NAME\n\nSub::Multi::Tiny - Multisubs/multimethods (multiple dispatch) yet another way!\n\n# SYNOPSIS\n\n    {\n        package main::my_multi;     # We're making main::my_multi()\n        use Sub::Multi::Tiny qw($foo $bar);     # All possible params\n\n        sub first :M($foo, $bar) {  # sub's name will be ignored,\n            return $foo ** $bar;    # but can't match the one we're making\n        }\n\n        sub second :M($foo) {\n            return $foo + 42;\n        }\n\n    }\n\n    # Back in package main, my_multi() is created just before the run phase.\n    say my_multi(2, 5);     # -\u003e 32\n    say my_multi(1295);     # -\u003e 1337\n\nThe default dispatcher dispatches solely by arity, and only one\ncandidate can have each arity.  For more flexible dispatching, see\n[Sub::Multi::Tiny::Dispatcher::TypeParams](https://metacpan.org/pod/Sub%3A%3AMulti%3A%3ATiny%3A%3ADispatcher%3A%3ATypeParams).\n\n# DESCRIPTION\n\nSub::Multi::Tiny is a library for making multisubs, aka multimethods,\naka multiple-dispatch subroutines.  Each multisub is defined in a\nsingle package.  Within that package, the individual implementations (\"impls\")\nare `sub`s tagged with the `:M` attribute.  The names of the impls are\npreserved but not used specifically by Sub::Multi::Tiny.\n\nWithin a multisub package, the name of the sub being defined is available\nfor recursion.  For example (using `where`, supported by\n[Sub::Multi::Tiny::Dispatcher::TypeParams](https://metacpan.org/pod/Sub%3A%3AMulti%3A%3ATiny%3A%3ADispatcher%3A%3ATypeParams)):\n\n    {\n        package main::fib;\n        use Sub::Multi::Tiny qw(D:TypeParams $n);\n        sub base  :M($n where { $_ \u003c= 1 })  { 1 }\n        sub other :M($n)                    { $n * fib($n-1) }\n    }\n\nThis code creates function `fib()` in package `main`.  Within package\n`main::fib`, function `fib()` is an alias for `main::fib()`.  It's easier\nto use than to explain!\n\n# FUNCTIONS\n\n## import\n\nSets up the package that uses it to define a multisub.  The parameters\nare all the parameter variables that the multisubs will use.  `import`\ncreates these as package variables so that they can be used unqualified\nin the multisub implementations.\n\nA parameter `D:Dispatcher` can also be given to specify the dispatcher to\nuse --- see [\"CUSTOM DISPATCH\"](#custom-dispatch).\n\nAlso sets [\"$VERBOSE\" in Sub::Multi::Tiny::Util](https://metacpan.org/pod/Sub%3A%3AMulti%3A%3ATiny%3A%3AUtil#VERBOSE) if the environment variable\n`SUB_MULTI_TINY_VERBOSE` has a truthy value.  If the `SUB_MULTI_TINY_VERBOSE`\nvalue is numeric, `$VERBOSE` is set to that value; otherwise, `$VERBOSE` is\nset to 1.\n\n# CUSTOM DISPATCH\n\nThis module includes a default dispatcher (implemented in\n[Sub::Multi::Tiny::Dispatcher::Default](https://metacpan.org/pod/Sub%3A%3AMulti%3A%3ATiny%3A%3ADispatcher%3A%3ADefault).  To use a different dispatcher,\ndefine or import a sub `MakeDispatcher()` into the package before\ncompilation ends.  That sub will be called to create the dispatcher.\nFor example:\n\n    {\n        package main::foo;\n        use Sub::Multi::Tiny;\n        sub MakeDispatcher { return sub { ... } }\n    }\n\nor\n\n    {\n        package main::foo;\n        use Sub::Multi::Tiny;\n        use APackageThatImportsMakeDispatcherIntoMainFoo;\n    }\n\nAs a shortcut, you can specify a dispatcher on the `use` line.  For example:\n\n    use Sub::Multi::Tiny qw(D:Foo $var);\n\nwill use dispatcher `Sub::Multi::Tiny::Dispatcher::Foo`.  Any name with a\ndouble-colon will be used as a full package name.  E.g., `D:Bar::Quux` will\nuse dispatcher `Bar::Quux`.  If `Foo` does not include a double-colon,\n`Sub::Multi::Tiny::Dispatcher::` will be prepended.\n\n# DEBUGGING\n\nFor extra debug output, set [\"$VERBOSE\" in Sub::Multi::Tiny::Util](https://metacpan.org/pod/Sub%3A%3AMulti%3A%3ATiny%3A%3AUtil#VERBOSE) to a positive\ninteger.  This has to be set at compile time to have any effect.  For example,\nbefore creating any multisubs, do:\n\n    use Sub::Multi::Tiny::Util '*VERBOSE';\n    BEGIN { $VERBOSE = 2; }\n\n# RATIONALE\n\n- To be able to use multisubs in pre-5.14 Perls with only built-in\nlanguage facilities.  This will help me make my own modules backward\ncompatible with those Perls.\n- To learn how it's done! :)\n\n# SEE ALSO\n\nI looked at these but decided not to use them for the following reasons:\n\n- [Class::Multimethods](https://metacpan.org/pod/Class%3A%3AMultimethods)\n\n    I wanted a syntax that used normal `sub` definitions as much as possible.\n    Also, I was a bit concerned by LPALMER's experience that it \"does what you\n    don't want sometimes without saying a word\"\n    ([\"Semantics\" in Class::Multimethods::Pure](https://metacpan.org/pod/Class%3A%3AMultimethods%3A%3APure#Semantics)).\n\n    Other than that, I think this looks pretty decent (but haven't tried it).\n\n- [Class::Multimethods::Pure](https://metacpan.org/pod/Class%3A%3AMultimethods%3A%3APure)\n\n    Same desire for `sub` syntax.  Additionally, the last update was in 2007,\n    and the maintainer hasn't uploaded anything since.  Other than that, I think\n    this also looks like a decent option (but haven't tried it).\n\n- [Dios](https://metacpan.org/pod/Dios)\n\n    This is a full object system, which I do not need in my use case.\n\n- [Logic](https://metacpan.org/pod/Logic)\n\n    This one is fairly clean, but uses a source filter.  I have not had much\n    experience with source filters, so am reluctant.\n\n- [Kavorka::Manual::MultiSubs](https://metacpan.org/pod/Kavorka%3A%3AManual%3A%3AMultiSubs) (and [Moops](https://metacpan.org/pod/Moops))\n\n    Requires Perl 5.14+.\n\n- [MooseX::MultiMethods](https://metacpan.org/pod/MooseX%3A%3AMultiMethods)\n\n    I am not ready to move to full [Moose](https://metacpan.org/pod/Moose)!\n\n- [MooseX::Params](https://metacpan.org/pod/MooseX%3A%3AParams)\n\n    As above.\n\n- [Sub::Multi](https://metacpan.org/pod/Sub%3A%3AMulti)\n\n    The original inspiration for this module, whence this module's name.\n    `Sub::Multi` uses coderefs, and I wanted a syntax that used normal\n    `sub` definitions as much as possible.\n\n- [Sub::SmartMatch](https://metacpan.org/pod/Sub%3A%3ASmartMatch)\n\n    This one looks very interesting, but I haven't used smartmatch enough\n    to be fully comfortable with it.\n\n# SUPPORT\n\nYou can find documentation for this module with the perldoc command.\n\n    perldoc Sub::Multi::Tiny\n\nYou can also look for information at:\n\n- GitHub: The project's main repository and issue tracker\n\n    [https://github.com/cxw42/Sub-Multi-Tiny](https://github.com/cxw42/Sub-Multi-Tiny)\n\n- MetaCPAN\n\n    [Sub::Multi::Tiny](https://metacpan.org/pod/Sub%3A%3AMulti%3A%3ATiny)\n\n- This distribution\n\n    See the tests in the `t/` directory distributed with this software\n    for usage examples.\n\n# BUGS\n\n- It's not as tiny as I thought it would be!\n- This isn't Damian code ;) .\n\n# AUTHOR\n\nChris White \u003ccxw@cpan.org\u003e\n\n# LICENSE\n\nCopyright (C) 2019 Chris White \u003ccxw@cpan.org\u003e\n\nThis library is free software; you can redistribute it and/or modify\nit under the same terms as Perl itself.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcxw42%2Fsub-multi-tiny","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcxw42%2Fsub-multi-tiny","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcxw42%2Fsub-multi-tiny/lists"}