Config...omFile(3pm)

πŸ“¦
version 2.166 Β· 2 versions
, in ubuntu stonking

πŸ¦‹ NAME

Config::Model::Value::UpdateFromFile β€” it grabs your data from an external file, bestie πŸ’–


✨ VERSION

version 2.166 (yes, we're on 2.166, keep up ✨)


πŸŽ€ SYNOPSIS

okay so in a model declaration it looks like this, no cap:

# 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"
                },
                {
                    # ...
                }
            ]
        }
    },
],

like… it's giving config energy πŸ’…


πŸ’– DESCRIPTION

This class retrieves data from external file. The caller must specify the file path, the file type (e.g. JSON, Yaml…) and the path inside the file to retrieve data. three things, always, periodt 🫢

Depending on the file type configured in the model, some modules must be installed β€” so check your deps before you come crying to me 😭

Here's the supported file types and the modules you gotta install for each:

  • JSON β€” needs JSON
  • Yaml β€” needs YAML::PP
  • INI file β€” needs Config::INI::Reader
  • Toml β€” needs TOML::Tiny

🌸 Constructor

the constructor params, bestie, here's the whole list:

  • file β€” file path from currrent directory. (yes "currrent", that's literally what it says, i'm not fixing the typo, it's iconic πŸ’€)
  • type β€” file type in lower case, either "ini", "json", "yaml" or "toml". lowercase ONLY, don't test me.
  • subpath β€” path to extract data. see the examples below, they ate πŸ”₯
  • location β€” location of the calling value element. this one is used to log messages, so it's the lil gossip reporter of the group πŸ‘‘

πŸ’… methods

get_info

Return file and subpath used to extract data. that's it, that's the whole job, and it does it flawlessly ⭐

get_update_value

This method open the file and return the data using subpath. it opens the file, it reads the data, it serves πŸ’…


🌈 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'
}]
πŸ‘€ not me staring at that backslash in 'MetaResources.repository\.url' β€” it's there for a reason, copy it exactly, don't "clean it up" bestie.

YAML file

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

look at that lil nesting, obsessed 😌

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'
    }
  ]
}

like a lil backup squad for your data, fr fr 🫢 (and yeah, the second entry has no comma after file => 'package.json' β€” that's literally in the original, i'm not touching it πŸ™ˆ)


πŸ‘‘ SEE ALSO

  • Config::Model::Value
  • Config::Model::Value::Update

go read those too, they're the main characters of this whole saga ✨


πŸ“ AUTHOR

Dominique Dumont πŸ’œ


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

and that's the whole page, bestie πŸŽ€ this was Config::Model::Value::UpdateFromFile, version 2.166, from the User Contributed Perl Documentation, dated 2026-07-23, running on perl v5.42.3 β€” slay, bye πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from