SReview::Config(3pm)

✨ SReview::Config ✨

okay bestie, welcome to SReview::Config πŸ’– β€” she's a Perl module (a User Contributed one, no less, so she's out here doing charity work for the community) and she is literally a self-reproducing and self-documenting configuration file system. no cap. she writes her own docs, she remembers her own defaults, she's the main character of your /etc πŸŽ€


🌸 NAME 🌸

SReview::Config β€” self-reproducing and self-documenting configuration file system πŸ¦‹

like, she configures and she documents herself. iconique. she's giving both at once.


✨ SYNOPSIS ✨

here's the vibe, fr fr:

use SReview::Config;

my $config = SReview::Config->new('/etc/sreview/config.pm');
$config->define('name', 'The name of this element', 'default');
...
print "You configured " . $config->get('name') . " as the name\n";
print "Full configuration: \n" . $config->dump;

see how she just… knows her own name and default? yeah. she's built different πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

SReview::Config is a class for managing configuration that reproduces itself and documents itself. the whole ritual is three steps, bestie:

  1. you create an SReview::Config object 🌱
  2. you populate it with all the possible configuration values you might want 🌷
  3. you retrieve them πŸ’«

that's it. that's the whole thing. lowkey elegant, highkey slay.


πŸ‘‘ METHODS πŸ‘‘

🫢 SReview::Config->new('path/to/filename');

makes you a brand new SReview::Config object. fresh out the box. she's born ✨


🫢 $config->define(name, doc, default)

defines a new configuration value. heads up though β€” this is not legal once get has already been called πŸ™ˆ once you've started reading the config, the definitions are locked in, periodt.

name should be the name of the configuration value. apart from the fact that it should not have a sigil (no $ bestie, we're not doing that here), it should be a valid name for a perl scalar variable.


🫢 $config->define_deprecated(oldname, newname, conversion_sub)

defines a name as a deprecated way of configuring things 😭 when this value gets set, SReview::Config will issue a warning that this option is now deprecated, and that the user should use some other option instead. she's not mad, she's just disappointed.

the conversion_sub is an optional argument that should mangle the value given to oldname into the value expected by newname πŸ”„ if it returns nonzero, then SReview::Config will croak. πŸ’€

it will receive:

  • a reference to the config object
  • the value that is trying to be set
  • the name of the new parameter

the default conversion sub just sets the value of the newname configuration without any conversion. no thoughts, head empty, just vibes 🌈


🫢 $config->define_computed('name')

defines a default value for a particular configuration parameter through a subroutine 🧚

if the subroutine returns undef, that value will be ignored (and the normal logic for defining a default will be used). no harm no foul πŸ’–

should be used on a parameter that has already been defined through

$config->define

so like, define first, then get fancy with it. order matters, bestie πŸŽ€


🫢 $config->get('name')

returns the value of the given configuration item. it also finalizes the definitions of this configuration file β€” that is, once this method has been called, the define method above will croak πŸ”₯ so yeah, after this, the door is closed.

the returned value will be one of these three, depending on what's available:

  • the default value configured at define time
  • the value configured in the configuration file
  • the value set (in JSON format) in the environment variable SREVIEW_name , where name is the upper-case version of the name of the configuration item

(yes, there really is a space in there before the closing backtick in the original. we don't question it. we respect it πŸ™ˆ)


🫢 $config->set('name', value);

changes the current value of the given configuration item ✨

note: this does not change the defaults, only the configured value. the default stays exactly where it is, minding its own business πŸ’…

🫢 $config->describe('name');

returns the documentation string for the given name πŸ“– she's self-documenting, remember? this is her reading her own diary out loud.


🫢 $config->dump

returns a string describing the whole configuration 🎁

each configuration item will produce one of the following two formats:

  • for an item that only has a default set:
# Documentation value given to define
#$name = "default value";
  • for an item that has a different value configured (either through the configuration file, or through set):
# Documentation value given to define
$name = "current value";

see the difference? the commented-out one is the shy default that nobody touched. the uncommented one is the one that got configured. πŸ”₯


🫢 $config->dump_item("item")

prints a JSON value for the given configuration item. prints the default item if this item hasn't been set a value. she always has a fallback, she's prepared πŸ’–


🫢 $config->is_default("item")

returns a truthy value if the given configuration item is still at its default value βœ… so you can vibe check whether anybody actually changed anything.


🫢 $config->keys

returns a list (unsorted) of all the known configuration names πŸ—οΈ note: unsorted. don't come for her about the order, she didn't promise you one.


πŸ’€ BUGS πŸ’€

it is currently not possible to load more than one configuration file in the same process space 😭 this will be fixed at some point in the future. (we've all been there bestie, one config file per situationship.)


and that's the whole page!! she's a User Contributed Perl Documentation queen, she's running on perl v5.40.1, and she was last touched on 2026-02-15 🌸 mwah, go configure something cute πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from