---
name: "MooX::ConfigFromFile::Role"
section: "3pm"
platform: "linux"
package: "libmoox-configfromfile-perl"
version: "0.009-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/MooX::ConfigFromFile::Role"
---

# MooX::ConfigFromFile::Role(3pm)

Moo eXtension for initializing objects from config file

## NAME

MooX::ConfigFromFile::Role - Moo eXtension for initializing objects from config file

## DESCRIPTION

This role adds a initializing sub around BUILDARGS and puts all what could read from config files into the hash which will be used to construct the final object.

While it does that, it internally calls it's own \_build\_\* methods (*\_build\_config\_prefix*, *\_build\_config\_files* and *\_build\_loaded\_config*) unless the appropriate attributes are already in `$params`.

## ATTRIBUTES

This role uses following attributes which might be suitable customized by overloading the appropriate builder or pass defaults in construction arguments.

Be sure to read "ATTRIBUTES" in MooX::File::ConfigDir, especially "config\_identifier" in MooX::File::ConfigDir to understand how the "config\_dirs" are build.

When you miss a directory - see "plug\_dir\_source" in File::ConfigDir and File::ConfigDir::Plack.

### config\_prefix

This attribute is a string and defaults to FindBin's `$Script`. It's interpreted as the basename of the config file name to use.

### config\_prefixes

This attribute is an array of strings and defaults to `"<[ config_prefix ]"`\>.

### config\_prefix\_map\_separator

This attribute is a string and contains the character which is used building *config\_prefix\_map* from *config\_prefixes*.

### config\_prefix\_map

This attribute is an array of strings containing all config-prefixes joint together `"($0, $0.$1, $0.$1.$2, ...)"` using *config\_prefix\_map\_separator*.

### config\_files\_pattern

This attribute contains a cross-product of *config\_prefix\_map* and *config\_extensions*. Both are concatenated using the shell wildcard '\*'.

### config\_dirs

This attribute is consumed from MooX::File::ConfigDir. It might not be smart to override - but possible. Use with caution.

### config\_extensions

This attribute defaults to list of extensions from Config::Any.

### config\_files

This attribute contains the list of existing files in *config\_dirs* matching *config\_prefix* . *config\_extensions*.  Search is operated by File::Find::Rule.

### raw\_loaded\_config

This attribute contains the config as loaded from file system in an array of `"filename => \%content"`.

### sorted\_loaded\_config

This attribute contains the loaded files from filesystem sorted by string in the same format as raw\_loaded\_config (array of `"filename => \%content"`).

The default algorithm is sorted by filename (**mind**: `'-' < '.'`).

### loaded\_config

This attribute contains the config loaded and transformed while constructing the instance. Construction is done from *sorted\_loaded\_config*, ignoring the filename part.

For classes set up using

```
  use MooX::ConfigFromFile config_singleton = 1;
```

this attribute is cached from the very first construction and fed by overwritten *builder*. The content of this attribute is passed to lower *BUILDARGS*.

## AUTHOR

Jens Rehsack, `"<rehsack at cpan.org>"`

## ACKNOWLEDGEMENTS

Toby Inkster suggested to rely on BUILDARGS instead of intercepting object creation with nasty hacks. He also taught me a bit more how Moo(se) works.

## LICENSE AND COPYRIGHT

Copyright 2013-2018 Jens Rehsack.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See \<http://dev.perl.org/licenses/\> for more information.
