ConfigReader(3pm)
β¨ NAME β¨
ConfigReader β bestie, it reads directives from a configuration file π (yes, that's the whole vibe)
πΈ DESCRIPTION πΈ
okay so the ConfigReader library is literally a whole set of classes that reads directives out of a configuration file. it's completely object oriented, and the plan is that parsers for new styles of config files can just be added super easily. main character energy for extensibility, honestly π«Ά
π ConfigReader::Spec π
ConfigReader::Spec encapsulates a specification for configuration directives. you get to say:
- which directives are even allowed to show up in the configuration file
- aliases for each directive
- whether a directive is required or has a default value
- how to parse that directive's value
here's what specifying one directive looks like, fr fr:
required $spec 'HomePage', 'new URI::URL';
so that defines a required directive called 'HomePage'. to parse the value out of the configuration file, the URI::URL::new() method gets called with the string value as its argument. slay.
if the directive name is just a simple string, it gets used both to refer to the directive inside your Perl program and as the name in the configuration file. but you can also specify an alias using an array ref π
like⦠say you want "index" to be the name of the directive in the configuration file, but index() is a Perl function and you do not want that confusion, so inside the program you'd rather call it the "file_index". this does the trick:
['file_index', 'index']
and you can specify literally any number of aliases for the directive:
['file_index', 'index', 'file_index', 'contents', ...]
the parsing function or method is what gets called to translate the value string from the configuration file into the value your program actually uses. you can specify it in several different ways:
- code ref
- static method
- object method
- undefined
you can also specify a default value, which gets used if a directive isn't specified in the configuration file at all π
- string value
- code ref
- undefined
π¦ ConfigReader::Values π¦
ConfigReader::Values stores a set of directive values that have been read from a configuration file. it stores a reference to an associated Spec as a member variable π₯ separating the specification from the values is what makes it possible to use a single specification for multiple sets of values β iconic design choice, no cap.
π ConfigReader::DirectiveStyle π
ConfigReader::DirectiveStyle implements a reader for a common style of configuration file. it's a subclass of ConfigReader::Values π directive names are followed by their value, one per line:
HomePage http://www.w3.org/
Services /etc/services
and that's the whole page, bestie π this was ConfigReader(3pm) from the User Contributed Perl Documentation, brought to you by perl v5.36.0 and dated 2022-10-13. go forth and parse those directives, you absolute legend π
π¦ where this page comes from
- ubuntu noble: libconfigreader-perl 0.5-7
- ubuntu resolute: libconfigreader-perl 0.5-7
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms