From 4f5a70e700623da0b799d6f861bd7fb1a6dbbc85 Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Mon, 24 Apr 2017 01:13:57 +0200 Subject: Extend the readme --- README.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index f74be3e..5297220 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,63 @@ # Config A perl 6 library for reading and writing configuration files. +## Installation +This module can be installed using `zef`: + +``` +zef install Config +``` + +Depending on the type of configuration file you want to work on, you will need a +`Config::Parser::` module as well. If you just want an easy-to-use configuration +object without reading/writing a file, no parser is needed. + +## Usage +Include the `Config` module in your script, instantiate it and use it as you +please. + +```perl6 +use Config; + +my $config = Config.new(); + +# loading a simple configuration hash +$config.read({ + keyOne => "value", + keyTwo => { + NestedKey => "other value" + } +}); + +# loading a configuration files +$config.read("/etc/config.yaml"); + +# retrieving a simple key +$config.get("keyOne"); + +# retrieving a nested key +$config.get("keyTwo.NestedKey"); +``` + +### Available parsers +Because there's so many ways to structure your configuration files, the parsers +for these are their own modules. This allows for easy implementing new parsers, +or providing a custom parser for your project's configuration file. + +The parser will be loaded during runtime, but you have to make sure it is +installed yourself. + +The following parsers are available: + +- [`Config::Parser::yaml`](https://github.com/scriptkitties/p6-Config-Parser-yaml) + +### Writing your own parser +If you want to make your own parser, simply make a new class in the +`Config::Parser` namespace. This class should extend the `Config::Parser` class, +and implement the `read` and `write` methods. The `read` method *must* return a +`Hash`. The `write` method *must* return a `Bool`, `True` when writing was +successful, `False` if not. + ## License This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software -- cgit v1.1 From 940c920c6ca61e0690ad5a8c8e1aaa65e06bc46f Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Mon, 24 Apr 2017 01:22:57 +0200 Subject: Add build status icon --- README.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index 5297220..6b9c52b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # Config A perl 6 library for reading and writing configuration files. +[![Build Status](https://travis-ci.org/scriptkitties/p6-Config.svg?branch=master)](https://travis-ci.org/scriptkitties/p6-Config) + ## Installation This module can be installed using `zef`: -- cgit v1.1 From ede6b8c4cfac8c5eed668ba8357f9e8b11ccbc43 Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Mon, 24 Apr 2017 08:50:55 +0200 Subject: Extend the examples --- README.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 6b9c52b..94daa4c 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ use Config; my $config = Config.new(); -# loading a simple configuration hash +# load a simple configuration hash $config.read({ keyOne => "value", keyTwo => { @@ -31,14 +31,23 @@ $config.read({ } }); -# loading a configuration files +# load a configuration files $config.read("/etc/config.yaml"); -# retrieving a simple key +# load a configuration file with a specific parser +$config.read("/etc/config", "Config::Parser::ini"); + +# retrieve a simple key $config.get("keyOne"); -# retrieving a nested key +# retrieve a nested key $config.get("keyTwo.NestedKey"); + +# write out the configuration file +$config.write("/etc/config.yaml"); + +# write out the configuration in another format +$config.write("/etc/config.json", "Config::Parser::json"); ``` ### Available parsers -- cgit v1.1