⬆️ ⬇️

Config :: YAML :: Modern - working with .yaml configuration files on steroids

Today, a fresh module is released to work with .yaml configuration files. As usual, it is available to the public on github Config :: YAML :: Modern , Config :: YAML :: Modern will be added to CPAN a little later .

Why this module may be of interest to you? He does some cool tricks, for example:



Areas of use? Offhand - the configuration of the project for collective work!

Interesting? Details under the cut.



So, YAML is the most convenient markup format for configuration files. It is at least man-readable and allows you to make comments (a stone towards json ). It is platform independent ( platform = language used ). He's cool. Use YAML or die!



Persuaded? Moving on.

The most convenient form of the type of project configuration for collective work looks something like this





')

WTF !! ??

All right, everything is damn clear - there is main_config aka the main configuration of the project and two folders of developers in which the state of the main system is different .

The first, meettya, seems to be doing something with another muscle.

Second, nic - screwed another pg server and does something with the system of sending messages to clients.



Diff is sexy! At any time, you can understand how your environment is different from the general config.



An example of how to use this beauty:



use Config::YAML::Modern; my $directory_main = '/etc/main_config/'; # you are set before in bash "export DEVELOP_CONFIG_DIR=/etc/meettya_config/" my $directory_develop = $ENV{'DEVELOP_CONFIG_DIR'}; my $config = Config::YAML::Modern->new( key_conversion => 'ucfirst' ); $config->dir_load($directory_main); if ( defined $directory_develop ){ $config->dir_add( $directory_develop, 'RIGHT_PRECEDENT' ); } my $db_mysql_config = $config->dive(qw/Db Mysql/); 




Everything! That's all you need to do in order to get a hash with the database parameters in $ db_mysql_config, well, what do you usually write there?

The given example is the simplest, the module has some more tasty buns in stock, which I clumsily tried to highlight in the documentation.

Use with pleasure and health!



Ps. Comments, wishes - send in patches on github! :)

Source: https://habr.com/ru/post/122818/



All Articles