MooX::...::Role(3pm)

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

πŸ’– MooX::...::Role β€” the manual page, but make it cute πŸ’–

okay bestie, gather round, we're reading the MooX::...::Role(3pm) page from User Contributed Perl Documentation together and I promise it's gonna be a whole vibe πŸ¦‹


✨ NAME ✨

MooX::ConfigFromFile::Role β€” a Moo eXtension for initializing objects from a config file πŸ’…


🌸 DESCRIPTION 🌸

so basically, this role slides a little initializing sub right around BUILDARGS, and it takes everything it can possibly read out of your config files and yeets it all into the hash that's gonna be used to construct the final object. that's the whole bit. iconic behavior, honestly πŸŽ€

and while it's doing all that, it internally calls its own _build_* methods β€” namely _build_config_prefix, _build_config_files and _build_loaded_config β€” unless the appropriate attributes are already sitting in $params. no cap, it checks first, because it respects you πŸ’–


πŸ‘‘ ATTRIBUTES πŸ‘‘

this role uses the following attributes, and they might be suitably customized by overloading the appropriate builder, or by passing defaults in your construction arguments. your call, main character ✨

be sure to read "ATTRIBUTES" in MooX::File::ConfigDir β€” especially "config_identifier" in MooX::File::ConfigDir β€” to actually understand how the config_dirs are build. fr fr, go read it, iykyk πŸ“–

and if you're sitting there like "bestie where is my directory 😭" β€” see "plug_dir_source" in File::ConfigDir and File::ConfigDir::Plack. they got you 🫢

  • config_prefix β€” this attribute is a string, and it defaults to FindBin's $Script. it's interpreted as the basename of the config file name to use. cute, simple, does its job πŸ’…
  • config_prefixes β€” this attribute is an array of strings, and it defaults to "<[ config_prefix ]>". yes, it's a list, and yes, it's giving very demure ✨
  • config_prefix_map_separator β€” this attribute is a string, and it holds the character that gets used when building config_prefix_map from config_prefixes. it's literally just the little glue character πŸŽ€
  • config_prefix_map β€” this attribute is an array of strings containing all the config-prefixes joint together like "($0, $0.$1, $0.$1.$2, ...)", using config_prefix_map_separator. look at them, all stacked up, a little prefix tower πŸ‘‘
  • config_files_pattern β€” this attribute contains a cross-product of config_prefix_map and config_extensions. both of them get concatenated using the shell wildcard '*'. wildcard moment 🌈
  • config_dirs β€” this attribute is consumed from MooX::File::ConfigDir. it might not be smart to override β€” but it's possible. use with caution, bestie ⚠️
  • config_extensions β€” this attribute defaults to a list of extensions from Config::Any. borrowed with love πŸ¦‹
  • config_files β€” this attribute contains the list of existing files in config_dirs matching config_prefix . config_extensions. the search is operated by File::Find::Rule. it goes and finds them, that's the whole job πŸ”
  • raw_loaded_config β€” this attribute contains the config as loaded from the file system, in an array of "filename => \%content". raw and unfiltered, no edits πŸ’€
  • sorted_loaded_config β€” this attribute contains the loaded files from the filesystem, sorted by string, in the same format as raw_loaded_config (array of "filename => \%content"). the default algorithm is sorted by filename β€” and mind this: '-' < '.' πŸ‘€
  • 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 an overwritten builder. and the content of this attribute is passed to the lower BUILDARGS. so it flows downstream, and it slays 🌊


πŸ’œ AUTHOR πŸ’œ

Jens Rehsack, "<rehsack at cpan.org>" β€” thank you for your service, king 🫑


πŸŽ€ ACKNOWLEDGEMENTS πŸŽ€

Toby Inkster suggested to rely on BUILDARGS instead of intercepting object creation with nasty hacks. honestly? correct. he also taught me a bit more how Moo(se) works. a real one, no cap 🌸


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 the whole page, bestie πŸ¦‹ this one's from perl v5.36.0, dated 2022-12-11, and it's the MooX::...::Role(3pm) page from User Contributed Perl Documentation. go forth and configure your objects, you absolute icon πŸ’…βœ¨πŸ’–

πŸ“¦ where this page comes from