MooX::...omFile(3pm)

πŸ“¦
version 0.009 Β· 5 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu questing

MooX::ConfigFromFile πŸ’–

okay bestie so this is a User Contributed Perl Documentation page, manual section 3pm, for a lil module called MooX::ConfigFromFile. it's giving "Moo eXtension for initializing objects from config file" and honestly? iconic. πŸŽ€


✨ NAME ✨

MooX::ConfigFromFile β€” the Moo eXtension that initializes your objects straight from a config file. no cap. πŸ¦‹


πŸ’… SYNOPSIS πŸ’…

here's the whole vibe, literally copy-paste this:

package Role::Action;

use Moo::Role;

has operator => ( is => "ro" );

package Action;

use Moo;
use MooX::ConfigFromFile; # imports the MooX::ConfigFromFile::Role

with "Role::Action";

sub operate { return say shift->operator; }

package OtherAction;

use Moo;

with "Role::Action", "MooX::ConfigFromFile::Role";

sub operate { return warn shift->operator; }

package QuiteOtherOne;

use Moo;

# consumes the MooX::ConfigFromFile::Role but load config only once
use MooX::ConfigFromFile config_singleton => 1;

with "Role::Action";

sub _build_config_prefix { "die" }

sub operate { return die shift->operator; }

package main;

my $action = Action->new(); # tries to find a config file in config_dirs and loads it
my $other = OtherAction->new( config_prefix => "warn" ); # use another config file
my $quite_o = QuiteOtherOne->new(); # quite another way to have an individual config file

like… the range?? the versatility?? we love to see it. 🌸


πŸ‘‘ DESCRIPTION πŸ‘‘

so here's the tea: this module is intended to easy load initialization values for attributes on object construction from an appropriate config file. the actual building work happens over in MooX::ConfigFromFile::Role β€” and using MooX::ConfigFromFile is how you make sure that role gets applied. periodt. πŸ’…

and for easier usage (as of 0.004, bestie, we've been upgraded ✨), several options can be passed via use, which gives you default initializers for the appropriate role attributes:

  • config_prefix β€” sets the default for config_prefix in MooX::ConfigFromFile::Role. 🫢
  • config_prefixes β€” sets the default for config_prefixes in MooX::ConfigFromFile::Role. and bestie, listen: ensure that when you use this flag together with MooX::Cmd, you load MooX::ConfigFromFile before MooX::Cmd. order matters, it's giving choreography. πŸ’€
  • config_prefix_map_separator β€” sets the default for config_prefix_map_separator in MooX::ConfigFromFile::Role.
package Foo;

# apply role MooX::ConfigFromFile::Role and override default for
# attribute config_prefix_map_separator
use MooX::ConfigFromFile config_prefix_map_separator => "~";

...
  • config_extensions β€” sets the default for config_extensions in MooX::ConfigFromFile::Role. 🌈
  • config_dirs β€” sets the default for config_dirs in MooX::ConfigFromFile::Role. and the same warning about modifying this attribute applies here too: possible, but use with caution! πŸ™ˆ
package Foo;

use MooX::ConfigFromFile config_dirs => [qw(/opt/foo/etc /home/alfred/area/foo/etc)];

...
  • config_files β€” sets the default for config_files in MooX::ConfigFromFile::Role.
this one's reasonable when you want exactly one config file in development mode. but for production code? it is highly recommended to override the builder instead. fr fr. πŸ”₯
  • config_singleton β€” a flag that adds a wrapper around the builder of loaded_config in MooX::ConfigFromFile::Role, ensuring a config gets loaded only once per class. the per-class restriction comes from the applicable modifiers per class (and singletons are per class, iykyk). πŸ‘‘
  • config_identifier β€” sets the default for config_identifier in MooX::File::ConfigDir.
package Foo;

# apply role MooX::ConfigFromFile::Role and override default for
# attribute config_identifier - means to look e.g. in /etc/foo/
use MooX::ConfigFromFile config_identifier => "foo";

...
  • config_hashmergeloaded β€” consumes the role MooX::ConfigFromFile::Role::HashMergeLoaded directly after MooX::ConfigFromFile::Role has been consumed. main character energy. ✨

🌟 AUTHOR 🌟

Jens Rehsack, "<rehsack at cpan.org>" πŸ’– (yes, legend behaviour)


πŸ¦‹ BUGS πŸ¦‹

please report any bugs or feature requests to "bug-moox-configfromfile at rt.cpan.org", or slide through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooX-ConfigFromFile>. πŸ’Œ

Jens will be notified, and then you'll automatically be notified of progress on your bug as changes get made. that's the communication, bestie. 🫢


πŸŽ€ SUPPORT πŸŽ€

you can find documentation for this module with the perldoc command:

perldoc MooX::ConfigFromFile

and you can also look for information at:


πŸ’œ ACKNOWLEDGEMENTS πŸ’œ

(nothing here bestie β€” literally empty, it's giving mysterious. πŸ’€)


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.


and that's a wrap, bestie 🫢 this was MooX::...omFile(3pm), served up by perl v5.36.0, dated 2022-12-11. stay configured, stay iconic, mwah πŸ’‹πŸŒΈβœ¨

πŸ“¦ where this page comes from