{"id":14966183,"url":"https://github.com/scriptkitties/p6-config","last_synced_at":"2025-10-25T16:30:36.897Z","repository":{"id":80058622,"uuid":"89166333","full_name":"scriptkitties/p6-Config","owner":"scriptkitties","description":"A perl 6 library for reading and writing configuration files.","archived":false,"fork":false,"pushed_at":"2024-01-22T15:53:23.000Z","size":175,"stargazers_count":4,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-31T07:51:28.111Z","etag":null,"topics":["configuration","perl","perl6"],"latest_commit_sha":null,"homepage":"","language":"Raku","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scriptkitties.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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":"2017-04-23T19:20:52.000Z","updated_at":"2021-03-18T22:56:00.000Z","dependencies_parsed_at":"2024-09-04T19:41:02.259Z","dependency_job_id":"86d14949-13a6-46dc-8776-9a98921e6e4d","html_url":"https://github.com/scriptkitties/p6-Config","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scriptkitties%2Fp6-Config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scriptkitties%2Fp6-Config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scriptkitties%2Fp6-Config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scriptkitties%2Fp6-Config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scriptkitties","download_url":"https://codeload.github.com/scriptkitties/p6-Config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238174109,"owners_count":19428626,"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":["configuration","perl","perl6"],"created_at":"2024-09-24T13:35:58.314Z","updated_at":"2025-10-25T16:30:36.617Z","avatar_url":"https://github.com/scriptkitties.png","language":"Raku","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Config\n\nExtensible configuration class for the Raku programming language.\n\n## Installation\n\nThis module can be installed using `zef`:\n\n```\nzef install Config\n```\n\nDepending on the type of configuration file you want to work on, you will need a\n`Config::Parser::` module as well. If you just want an easy-to-use configuration\nobject without reading/writing a file, no parser is needed.\n\n## Usage\n\nTo start off, specify a *template* of your configuration. `Config` will check\na couple of directories for a configuration file (based on the XDG base\ndirectory spec), and will also automatically try to see if there's any\nconfiguration specified in environment variables.\n\nTo specify a template, pass it as an argument to `new`.\n\n```raku\nmy $config = Config.new({\n\tkeyOne =\u003e Str,\n\tkeyTwo =\u003e {\n\t\tNestedKey =\u003e \"default value\",\n\t},\n\tkeyThree =\u003e Int,\n}, :name\u003cfoobar\u003e);\n```\n\nImportant to note here is the `name` attribute which is being set. This name\nis used to look up configuration files in default locations and the\nenvironment. For this particular example, it will check any directory specified\nin `$XDG_CONFIG_DIRS` for files matching `foobar.*` and `foobar/config.*`.\nAfterwards, it will check `$XDG_CONFIG_HOME` for the same files. If these\nvariables are not set, it will just check `$HOME/.config` for those files.\n\nAdditionally, the environment will be checked for `$FOOBAR_KEYONE`,\n`$FOOBAR_KEYTWO_NESTEDKEY`, and `$FOOBAR_KEYTHREE`. The former two will be cast\nto `Str` appropriately, with `$FOOBAR_KEYTHREE` being cast to an `Int`. This\nensures that the values are of the correct type, even if they're pulled from a\nshell environment. This also works for `IO::Path`!\n\n*If you're using the Raku `Log` module, you can set `RAKU_LOG_LEVEL` to `7` to\nsee which places it actually checks and reads for values.*\n\nYou can also manually read configuration files or hashes of values.\n\n```raku\n# Load a simple configuration hash\n$config.=read({\n    keyOne =\u003e 'value',\n    keyTwo =\u003e {\n        NestedKey =\u003e 'other value'\n    }\n});\n\n# Load a configuration files\n$config.=read('/etc/config.yaml');\n\n# Load a configuration file with a specific parser\n$config.=read('/etc/config', Config::Parser::ini);\n```\n\nDo note the use of `.=` here. `Config` returns a new `Config` object if you\nchange its values, it is an immutable object. The `.=` operator provided by\nRaku is a shorthand for `$config = $config.read(...)`.\n\nTo read values from the `Config` object, you can use the `get` method, or treat\nit as a `Hash`.\n\n```raku\n# Retrieve a value\n$config.get('keyOne');\n\n# Same as above, but treating it as a Hash\n$config\u003ckeyOne\u003e;\n\n# Retrieve a value by nested key\n$config.get('keyTwo.NestedKey');\n```\n\nThe `Config` object can also write it's current configuration back to a file.\nYou must specify a particular `Config::Parser` implementation as well.\n\n```raku\n# Write out the configuration using the json parser\n$config.write($*HOME.add('.config/foobar/config.json', Config::Parser::json);\n```\n\n### Available parsers\n\nBecause there's so many ways to structure your configuration files, the parsers\nfor these are their own modules. This allows for easy implementing new parsers,\nor providing a custom parser for your project's configuration file.\n\nThe parser will be loaded during runtime, but you have to make sure it is\ninstalled yourself.\n\nThe following parsers are available:\n\n- json:\n  - [`Config::Parser::json`](https://github.com/arjancwidlak/p6-Config-Parser-json)\n  - [`Config::Parser::json`](https://github.com/robertlemmen/perl6-config-json)\n- [`Config::Parser::toml`](https://github.com/scriptkitties/p6-Config-Parser-toml)\n- [`Config::Parser::yaml`](https://github.com/scriptkitties/p6-Config-Parser-yaml)\n\n### Writing your own parser\n\nIf you want to make your own parser, simply make a new class which extends the\n`Config::Parser` class, and implements the `read` and `write` methods. The\n`read` method *must* return a `Hash`. The `write` method *must* return a\n`Bool`, `True` when writing was successful, `False` if not. Throwing\n`Exception`s to indicate the kind of failure is recommended.\n\n## Contributing\n\nIf you want to contribute to `Config`, you can do so by mailing your patches to\n`~tyil/raku-devel@lists.sr.ht`. Any questions or other forms of feedback are\nwelcome too!\n\n## License\n\nThis program is free software: you can redistribute it and/or modify it under\nthe terms of the GNU Lesser General Public License version 3, as published by\nthe Free Software Foundation.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY\nWARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A\nPARTICULAR PURPOSE.  See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with\nthis program.  If not, see \u003chttp://www.gnu.org/licenses/\u003e.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscriptkitties%2Fp6-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscriptkitties%2Fp6-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscriptkitties%2Fp6-config/lists"}