Object-Configure
view release on metacpan or search on metacpan
### USING A CONFIGURATION FILE
To control behavior at runtime, `Object::Configure` supports loading settings from a configuration file via [Config::Abstraction](https://metacpan.org/pod/Config%3A%3AAbstraction).
A minimal example of a config file (`~/.conf/local.conf`) might look like:
[My__Module]
logger.file = /var/log/mymodule.log
The `configure()` function will read this file,
overlay it onto your default parameters,
and initialize the logger accordingly.
If the file is not readable and no config\_dirs are provided,
the module will throw an error.
To be clear, in this case, inheritance is not followed.
This mechanism allows dynamic tuning of logging behavior (or other parameters you expose) without modifying code.
More details to be written.
lib/Object/Configure.pm view on Meta::CPAN
=head3 USING A CONFIGURATION FILE
To control behavior at runtime, C<Object::Configure> supports loading settings from a configuration file via L<Config::Abstraction>.
A minimal example of a config file (C<~/.conf/local.conf>) might look like:
[My__Module]
logger.file = /var/log/mymodule.log
The C<configure()> function will read this file,
overlay it onto your default parameters,
and initialize the logger accordingly.
If the file is not readable and no config_dirs are provided,
the module will throw an error.
To be clear, in this case, inheritance is not followed.
This mechanism allows dynamic tuning of logging behavior (or other parameters you expose) without modifying code.
More details to be written.
lib/Object/Configure.pm view on Meta::CPAN
_walk_isa('UNIVERSAL', $chain, $seen);
}
# Add current class to chain (after parents)
push @$chain, $class;
}
# Deep merge two hash references
# Second hash takes precedence over first
sub _deep_merge {
my ($base, $overlay) = @_;
return $overlay unless ref($base) eq 'HASH';
return $base unless ref($overlay) eq 'HASH';
my $result = { %$base };
foreach my $key (keys %$overlay) {
if (ref($overlay->{$key}) eq 'HASH' && ref($result->{$key}) eq 'HASH') {
$result->{$key} = _deep_merge($result->{$key}, $overlay->{$key});
} else {
$result->{$key} = $overlay->{$key};
}
}
return $result;
}
=head2 instantiate($class,...)
Create and configure an object of the given class.
( run in 1.374 second using v1.01-cache-2.11-cpan-39bf76dae61 )