{"id":16315163,"url":"https://github.com/robrwo/const-exporter","last_synced_at":"2026-02-24T12:05:02.464Z","repository":{"id":14364128,"uuid":"17073943","full_name":"robrwo/Const-Exporter","owner":"robrwo","description":"Declare constants to export in a declarative manner","archived":false,"fork":false,"pushed_at":"2024-12-31T11:01:18.000Z","size":202,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-16T17:56:48.709Z","etag":null,"topics":["constants","perl-module"],"latest_commit_sha":null,"homepage":null,"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":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-02-21T23:56:28.000Z","updated_at":"2024-12-31T11:01:22.000Z","dependencies_parsed_at":"2024-06-19T02:07:37.078Z","dependency_job_id":null,"html_url":"https://github.com/robrwo/Const-Exporter","commit_stats":{"total_commits":204,"total_committers":2,"mean_commits":102.0,"dds":0.004901960784313708,"last_synced_commit":"3dddf69f665d629679bbf97c373b9a4fc4787e80"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrwo%2FConst-Exporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrwo%2FConst-Exporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrwo%2FConst-Exporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrwo%2FConst-Exporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robrwo","download_url":"https://codeload.github.com/robrwo/Const-Exporter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252565952,"owners_count":21768958,"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":["constants","perl-module"],"created_at":"2024-10-10T21:56:23.381Z","updated_at":"2025-10-29T04:04:57.620Z","avatar_url":"https://github.com/robrwo.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\nConst::Exporter - Declare constants for export.\n\n# VERSION\n\nversion v1.3.0\n\n# SYNOPSIS\n\nDefine a constants module:\n\n```perl\npackage MyApp::Constants;\n\nour $zoo =\u003e 1234;\n\nuse Const::Exporter\n\n   tag_a =\u003e [                  # use MyApp::Constants /:tag_a/;\n      'foo'  =\u003e 1,             # exports \"foo\"\n      '$bar' =\u003e 2,             # exports \"$bar\"\n      '@baz' =\u003e [qw/ a b c /], # exports \"@baz\"\n      '%bo'  =\u003e { a =\u003e 1 },    # exports \"%bo\"\n   ],\n\n   tag_b =\u003e [                  # use MyApp::Constants /:tag_b/;\n      'foo',                   # exports \"foo\" (same as from \":tag_a\")\n      '$zoo',                  # exports \"$zoo\" (as defined above)\n   ];\n\n# `use Const::Exporter` can be specified multiple times\n\nuse Const::Exporter\n\n   tag_b =\u003e [                 # we can add symbols to \":tab_b\"\n      'moo' =\u003e $bar,          # exports \"moo\" (same value as \"$bar\")\n   ],\n\n   enums =\u003e [\n\n     [qw/ goo gab gub /] =\u003e 0, # exports enumerated symbols, from 0..2\n\n   ],\n\n   default =\u003e [qw/ foo $bar /]; # exported by default\n```\n\nand use that module:\n\n```perl\npackage MyApp;\n\nuse MyApp::Constants qw/ $zoo :tag_a /;\n\n...\n```\n\n## Dynamically Creating Constants\n\nYou may also import a predefined hash of constants for exporting dynamically:\n\n```perl\nuse Const::Exporter;\n\nmy %myconstants = (\n       'foo'  =\u003e 1,\n       '$bar' =\u003e 2,\n       '@baz' =\u003e [qw/ a b c /],\n       '%bo'  =\u003e { a =\u003e 1 },\n);\n\n# ... do stuff\n\nConst::Exporter-\u003eimport(\n     constants =\u003e [%myconstants],        # define constants for exporting\n     default   =\u003e [ keys %myconstants ], # export everything in %myconstants by default\n);\n```\n\n# DESCRIPTION\n\nThis module allows you to declare constants that can be exported to\nother modules.\n\nTo declare constants, simply group then into export tags:\n\n```perl\npackage MyApp::Constants;\n\nuse Const::Exporter\n\n  tag_a =\u003e [\n     'foo' =\u003e 1,\n     'bar' =\u003e 2,\n  ],\n\n  tag_b =\u003e [\n     'baz' =\u003e 3,\n     'bar',\n  ],\n\n  default =\u003e [\n     'foo',\n  ];\n```\n\nConstants in the `default` tag are exported by default (that is, they\nare added to the `@EXPORTS` array).\n\nWhen a constant is already defined in a previous tag, then no value is\nspecified for it. (For example, `bar` in `tab_b` above.)  If you do\ngive a value, [Const::Exporter](https://metacpan.org/pod/Const%3A%3AExporter) will assume it's another symbol.\n\nYour module can include multiple calls to `use Const::Exporter`, so\nthat you can reference constants in other expressions, e.g.\n\n```perl\nuse Const::Exporter\n\n  tag =\u003e [\n      '$zero' =\u003e 0,\n  ];\n\nuse Const::Exporter\n\n  tag =\u003e [\n      '$one' =\u003e 1 + $zero,\n  ];\n```\n\nor even something more complex:\n\n```perl\nuse Const::Exporter\n\n   http_ports =\u003e [\n      'HTTP'     =\u003e 80,\n      'HTTP_ALT' =\u003e 8080,\n      'HTTPS'    =\u003e 443,\n   ];\n\nuse Const::Exporter\n\n   http_ports =\u003e [\n      '@HTTP_PORTS' =\u003e [ HTTP, HTTP_ALT, HTTPS ],\n   ];\n```\n\nConstants can include traditional [constant](https://metacpan.org/pod/constant) symbols, as well as\nscalars, arrays or hashes.\n\nConstants can include values defined elsewhere in the code, e.g.\n\n```perl\nour $foo;\n\nBEGIN {\n   $foo = calculate_value_for_constant();\n}\n\nuse Const::Exporter\n\n  tag =\u003e [ '$foo' ];\n```\n\nNote that this will make the symbol read-only. You don't need to\nexplicitly declare it as such.\n\nEnumerated constants are also supported:\n\n```perl\nuse Const::Exporter\n\n  tag =\u003e [\n\n    [qw/ foo bar baz /] =\u003e 1,\n\n  ];\n```\n\nwill define the symbols `foo` (1), `bar` (2) and `baz` (3).\n\nYou can also specify a list of numbers, if you want to skip values:\n\n```perl\nuse Const::Exporter\n\n  tag =\u003e [\n\n    [qw/ foo bar baz /] =\u003e [1, 4],\n\n  ];\n```\n\nwill define the symbols `foo` (1), `bar` (4) and `baz` (5).\n\nYou can even specify string values:\n\n```perl\nuse Const::Exporter\n\n  tag =\u003e [\n\n    [qw/ foo bar baz /] =\u003e [qw/ feh meh neh /],\n\n  ];\n```\n\nhowever, this is equivalent to\n\n```perl\nuse Const::Exporter\n\n  tag =\u003e [\n    'foo' =\u003e 'feh',\n    'bar' =\u003e 'meh',\n    'baz' =\u003e 'neh',\n  ];\n```\n\nObjects are also supported,\n\n```perl\nuse Const::Exporter\n\n tag =\u003e [\n   '$foo' =\u003e Something-\u003enew( 123 ),\n ];\n```\n\n## Export Tags\n\nBy default, all symbols are exportable (in `@EXPORT_OK`.)\n\nThe `:default` tag is the same as not specifying any exports.\n\nThe `:all` tag exports all symbols.\n\n# KNOWN ISSUES\n\n## Support for older Perl versions\n\nThis module requires Perl v5.14 or newer.\n\nPull requests to support older versions of Perl are welcome. See\n[\"SOURCE\"](#source).\n\n## Exporting Functions\n\n[Const::Exporter](https://metacpan.org/pod/Const%3A%3AExporter) is not intended for use with modules that also\nexport functions.\n\nThere are workarounds that you can use, such as getting\n[Const::Exporter](https://metacpan.org/pod/Const%3A%3AExporter) to export your functions, or munging `@EXPORT`\netc. separately, but these are not supported and changes in the\nfuture my break our code.\n\n## Mixing POD with Tags\n\nThe following code is a syntax error, at least with some versions of\nPerl:\n\n```perl\nuse Const::Exporter\n\n=head2 a\n\n=cut\n\n  a =\u003e [ foo =\u003e 1 ],\n\n=head2 b\n\n=cut\n\n  b =\u003e [ bar =\u003e 2 ];\n```\n\nIf you want to mix POD with your declarations, use multiple use lines,\ne.g.\n\n```perl\n=head2 a\n\n=cut\n\nuse Const::Exporter\n  a =\u003e [ foo =\u003e 1 ];\n\n=head2 b\n\n=cut\n\nuse Const::Exporter\n  b =\u003e [ bar =\u003e 2 ];\n```\n\n# SUPPORT FOR OLDER PERL VERSIONS\n\nThis module requires Perl v5.10.1 or later.\n\nFuture releases may only support Perl versions released in the last ten years.\n\n# SEE ALSO\n\nSee [Exporter](https://metacpan.org/pod/Exporter) for a discussion of export tags.\n\n## Similar Modules\n\n- [Exporter::Constants](https://metacpan.org/pod/Exporter%3A%3AConstants)\n\n    This module only allows you to declare function symbol constants, akin\n    to the [constant](https://metacpan.org/pod/constant) module, without tags.\n\n- [Constant::Exporter](https://metacpan.org/pod/Constant%3A%3AExporter)\n\n    This module only allows you to declare function symbol constants, akin\n    to the [constant](https://metacpan.org/pod/constant) module, although you can specify tags.\n\n- [Constant::Export::Lazy](https://metacpan.org/pod/Constant%3A%3AExport%3A%3ALazy)\n\n    This module only allows you to declare function symbol constants, akin\n    to the [constant](https://metacpan.org/pod/constant) module by defining functions that are only called\n    as needed.  The interface is rather complex.\n\n- [Const::Fast::Exporter](https://metacpan.org/pod/Const%3A%3AFast%3A%3AExporter)\n\n    This module will export all constants declared in the package's\n    namespace.\n\n# SOURCE\n\nThe development version is on github at [https://github.com/robrwo/Const-Exporter](https://github.com/robrwo/Const-Exporter)\nand may be cloned from [git://github.com/robrwo/Const-Exporter.git](git://github.com/robrwo/Const-Exporter.git)\n\n# BUGS\n\nPlease report any bugs or feature requests on the bugtracker website\n[https://github.com/robrwo/Const-Exporter/issues](https://github.com/robrwo/Const-Exporter/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# CONTRIBUTORS\n\n- Slaven Rezić \u003cslaven@rezic.de\u003e\n- B. Estrade \u003cestrabd@cpan.org\u003e\n\n# COPYRIGHT AND LICENSE\n\nThis software is Copyright (c) 2014-2024 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%2Fconst-exporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobrwo%2Fconst-exporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobrwo%2Fconst-exporter/lists"}