|
1 | 1 | # perl-module-configurationManager
|
2 | 2 | The configuration manager perl module is used to dynamicaly load YAML configuration files with leazy load
|
| 3 | + |
| 4 | +## Define the configuration repository: |
| 5 | + |
| 6 | +To define a repository, several ways exists: |
| 7 | + |
| 8 | +#### With use statement : |
| 9 | + |
| 10 | +The repositories defined by the use statement are shared between each configuration manager. |
| 11 | + |
| 12 | +```perl |
| 13 | +use FindBin; |
| 14 | +use configurationManager ["repo=".$FindBin::Bin."/conf", "repo=/an/other/config"]; |
| 15 | +``` |
| 16 | + |
| 17 | +#### With the 'new' subroutine |
| 18 | + |
| 19 | +By instanciate a new configurationManager with repositories, you assign to this manager a self repository that is not shared with the others. |
| 20 | + |
| 21 | +```perl |
| 22 | +use configurationManager; |
| 23 | + |
| 24 | +my $altConfig = configurationManager->new({ |
| 25 | + repositories => [$FindBin::Bin."/altConf"], |
| 26 | +}); |
| 27 | +``` |
| 28 | + |
| 29 | +## Get configuration |
| 30 | + |
| 31 | +The configurationManager offer access to the configuration behind the 'get' subroutine. The parameter to give as argument is the configuration filename without extension. If the file is into a recursive repository, give the relative path to it. |
| 32 | + |
| 33 | +### Example: |
| 34 | +``` |
| 35 | +/path/to/the/repository: |
| 36 | + -> myConfig.yaml |
| 37 | + -> mySecondConfig.yaml |
| 38 | + -> aDirectory: |
| 39 | + -> anotherConfig.yaml |
| 40 | +``` |
| 41 | +##### content of /path/to/the/repository/myConfig.yaml : |
| 42 | +```yaml |
| 43 | +hello: "world" |
| 44 | +my: "name" |
| 45 | +``` |
| 46 | +
|
| 47 | +##### content of /path/to/the/repository/aDirectory/anotherConfig.yaml : |
| 48 | +```yaml |
| 49 | +hello: "state" |
| 50 | +my: "purpose" |
| 51 | +``` |
| 52 | +
|
| 53 | +##### code : |
| 54 | +```perl |
| 55 | +use configurationManager; |
| 56 | +use Data::Dumper; |
| 57 | + |
| 58 | +my $manager = configurationManager->new({ |
| 59 | + repositories => ["/path/to/the/repository"], |
| 60 | +}); |
| 61 | + |
| 62 | +print Dumper $manager->get("myConfig"); |
| 63 | +# $VAR1 = { |
| 64 | +# 'hello' => 'world', |
| 65 | +# 'my' => 'name' |
| 66 | +# }; |
| 67 | + |
| 68 | +print Dumper $manager->get("aDirectory/anotherConfig"); |
| 69 | +# $VAR2 = { |
| 70 | +# 'hello' => 'state', |
| 71 | +# 'my' => 'purpose' |
| 72 | +# }; |
| 73 | +``` |
| 74 | + |
| 75 | +## Reserved keys : |
| 76 | + |
| 77 | +name | purpose | content |
| 78 | +---- | ------- | ------- |
| 79 | +import | Import another configuration | scalar OR array |
| 80 | + |
| 81 | +### Import |
| 82 | + |
| 83 | +The import key is used to automatically load another configuration into the current one. Note, the importation is done by first level key, and the imported configuration never override the current. |
| 84 | + |
| 85 | +##### example: |
| 86 | +``` |
| 87 | +/path/to/the/repository: |
| 88 | + -> myConfig.yaml |
| 89 | + -> mySecondConfig.yaml |
| 90 | +``` |
| 91 | +##### content of /path/to/the/repository/myConfig.yaml : |
| 92 | +```yaml |
| 93 | +hello: "world" |
| 94 | +my: "name" |
| 95 | +import: "mySecondConfig" |
| 96 | +``` |
| 97 | +##### content of /path/to/the/repository/mySecondConfig.yaml : |
| 98 | +```yaml |
| 99 | +is: "bergamote" |
| 100 | +and: 'I' |
| 101 | +eat: "strudle" |
| 102 | +``` |
| 103 | +
|
| 104 | +##### code : |
| 105 | +```perl |
| 106 | +use configurationManager; |
| 107 | +use Data::Dumper; |
| 108 | + |
| 109 | +my $manager = configurationManager->new({ |
| 110 | + repositories => ["/path/to/the/repository"], |
| 111 | +}); |
| 112 | + |
| 113 | +print Dumper $manager->get("myConfig"); |
| 114 | +# $VAR1 = { |
| 115 | +# 'hello' => 'world', |
| 116 | +# 'my' => 'name', |
| 117 | +# 'is' => 'bergamote', |
| 118 | +# 'and' => 'I', |
| 119 | +# 'eat' => 'strudle' |
| 120 | +# }; |
| 121 | +``` |
0 commit comments