NAME

Config::Model::Value::UpdateFromFile - Retrieve data from external file

VERSION

version 2.158

SYNOPSIS

# in a model declaration:
element => [
    data_from_some_file => {
        type => 'leaf',
        value_type => 'uniline',
        update => {
            # handled by Config::Model::Value::Update
            when_missing => 'warn',
            files => [
                {
                    # handled by this module, Config::Model::Value::UpdateFromFile
                    type => 'ini',
                    file => "some_file.ini",
                    subpath => "foo.bar"
                },
                {
                    # ...
                }
            ]
        }
    },
],

DESCRIPTION

This class retrieves data from external file. Caller must specify the file path, the file type (e.g. JSON, Yaml...) and the path inside the file to retrieve data.

Depending on the file type configured in the model, some modules must be installed.

Supported file types and modules to be installed are:

JSON

JSON

Yaml

YAML::PP

INI file

Config::INI::Reader

Toml

TOML::Tiny

Constructor

Constructor parameters are:

file

File path from currrent directory.

type

File type in lower case, either ini, json, yaml or toml.

subpath

Path to extract data. See examples below.

location

location of the calling value element. This is used to log messages.

methods

get_info

Return file and subpath used to extract data.

get_update_value

This method open the file and return the data using subpath.

Examples

INI file

Using the dist.ini file:

[MetaResources]
homepage          = https://github.com/dod38fr/config-model/wiki
repository.url    = git://github.com/dod38fr/config-model.git

homepage can be retrieved with:

 update => [{
  type => 'ini',
  file => 'dist.ini',
  subpath => 'MetaResources.homepage'
}]

and url with:

 update => [{
  type => 'ini',
  file => 'dist.ini',
  subpath => 'MetaResources.repository\.url'
}]

YAML file

update => {
    when_missing => 'warn',
    files => [{
         type => 'yaml',
         file => 'META.yml',
         subpath => 'resources.homepage'}
    ]
}

Try several files

If may be necessary to try several files:

update => {
  when_missing => 'ignore',
  files => [
    {
       type => 'yaml',
       file => 'META.yml',
       subpath => 'abstract'
    },
    {
       type => 'json',
       file => 'package.json'
       subpath => 'description'
    }
  ]
}

SEE ALSO

Config::Model::Value, Config::Model::Value::Update

AUTHOR

Dominique Dumont

COPYRIGHT AND LICENSE

This software is Copyright (c) 2005-2022 by Dominique Dumont.

This is free software, licensed under:

The GNU Lesser General Public License, Version 2.1, February 1999