UR::ModuleConfig(3pm)

๐Ÿ“ฆ
version 0.470 ยท 2 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

๐Ÿ’– NAME ๐Ÿ’–

UR::ModuleConfig โ€” it manages the dynamic configuration of modules. that's it, that's the whole job, and it does it flawlessly ๐Ÿ’…


โœจ SYNOPSIS โœจ

package MyModule;
use base qw(UR::ModuleConfig);

MyModule->config(%conf);
$val = MyModule->config('key');
%conf = MyModule->config;

look at that. so clean. so iconic. ๐ŸŽ€


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

okay bestie, here's the tea โ˜• โ€” this module manages the configuration for modules. Configurations can be read from files, or set dynamically, whatever vibe you're on. Modules wishing to use the configuration methods should inherit from the module.

Like. just inherit. that's the whole membership card. ๐Ÿซถ

๐ŸŒธ METHODS ๐ŸŒธ

The methods deal with managing configuration. yes, all of them. every single one is about config. it's giving commitment. โœจ

๐Ÿ’œ config

MyModule->config(%config);
$val = MyModule->config('key');
%conf = MyModule->config;

my $obj = MyModule->new;
$obj->config(%config);

This method can be called three ways, as either a class or object method.

  1. The first method takes a hash as its argument and sets the configuration parameters given in the hash.
  2. The second method takes a single argument which should be one of the keys of the hash that set the config parameters, and returns the value of that config hash key.
  3. The final method takes no arguments and returns the entire configuration hash. the whole thing. no crumbs left. ๐Ÿ‘‘

Now for the precedence drama, because there IS drama:

When called as an object method, the config for both the object and all classes in its inheritance hierarchy are referenced, with the object config taking precedence over class methods, and class methods closer to the object (first in the @ISA array) taking precedence over those further away (later in the @ISA array).

When called as a class method, the same procedure is used โ€” except no object configuration is referenced. (no object, no object config. math is mathing. ๐Ÿงฎ)

๐Ÿšจ Do not use configuration keys that begin with an underscore ("_"). These are reserved for internal use. that's the backstage area, babe, you don't go in there. ๐Ÿ™ˆ

๐ŸŽ€ check_config

$obj->check_config($key);

This method checks to see if a value is set. Unlike config, it does not issue a warning if the key is not set. (so polite. so quiet. an angel honestly. ๐Ÿ˜‡)

If the key is not set, "undef" is returned. If the key has been set, the value of the key is returned (which may be "undef"). yes, "undef" twice, that's not a typo, that's just how it be โ€” the return value is literally the value, even when the value is "undef". ๐Ÿ’€

โญ default_config

$class->default_config(%defaults);

This method allows the developer to set configuration values, only if they are not already set. it's the "no takebacks" method. it will not stomp on what you already declared. respectful. we love. ๐Ÿซถ

๐ŸŒˆ config_file

$rv = $class->config_file(path => $path);
$rv = $class->config_file(handle => $fh);

This method reads in the given file and expects key-value pairs, one per line. The key and value should be separated by an equal sign, "=", with optional surrounding space.

ngl it currently only handles single value values. that's the limit, bestie, don't come for it. ๐Ÿ™ˆ

The method returns true upon success, "undef" on failure. simple as. โœจ


and that's the whole page, no notes, no cap. ๐Ÿ’…

this was UR::ModuleConfig(3pm) from the User Contributed Perl Documentation, and it's sitting in perl v5.32.1, dated 2022-01-17. go configure something cute. mwah ๐ŸŽ€โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from