Venus::Config - Config Class
Config Class for Perl 5
package main; use Venus::Config; my $config = Venus::Config->new; # $config = $config->read_file('app.pl'); # "..."
This package provides methods for loading Perl, YAML, and JSON configuration files, and fetching configuration information.
This package inherits behaviors from:
Venus::Kind::Utility
This package integrates behaviors from:
Venus::Role::Buildable
Venus::Role::Valuable
This package provides the following methods:
edit_file(string $file, string | coderef $code) (Venus::Config)
The edit_file method does an in-place edit, i.e. it loads a Perl, YAML, or JSON configuration file, passes the decoded data to the method or callback provided, and writes the results of the method or callback to the file.
Since 3.10
3.10
package main; use Venus::Config; my $config = Venus::Config->edit_file('t/conf/edit.perl', sub { my ($self, $data) = @_; $data->{edited} = 1; return $data; }); # bless(..., 'Venus::Config')
read_file(string $path) (Venus::Config)
The read_file method load a Perl, YAML, or JSON configuration file, based on the file extension, and returns a new Venus::Config object.
Since 2.91
2.91
package main; use Venus::Config; my $config = Venus::Config->read_file('t/conf/read.perl'); # bless(..., 'Venus::Config')
package main; use Venus::Config; my $config = Venus::Config->read_file('t/conf/read.json'); # bless(..., 'Venus::Config')
package main; use Venus::Config; my $config = Venus::Config->read_file('t/conf/read.yaml'); # bless(..., 'Venus::Config')
read_json(string $data) (Venus::Config)
The read_json method returns a new Venus::Config object based on the JSON string provided.
# given: synopsis package main; $config = $config->read_json(q( { "$metadata": { "tmplog": "/tmp/log" }, "$services": { "log": { "package": "Venus/Path", "argument": { "$metadata": "tmplog" } } } } )); # bless(..., 'Venus::Config')
read_json_file(string $file) (Venus::Config)
The read_json_file method uses Venus::Path to return a new Venus::Config object based on the file provided.
# given: synopsis package main; $config = $config->read_json_file('t/conf/read.json'); # bless(..., 'Venus::Config')
read_perl(string $data) (Venus::Config)
The read_perl method returns a new Venus::Config object based on the Perl string provided.
# given: synopsis package main; $config = $config->read_perl(q( { '$metadata' => { tmplog => "/tmp/log" }, '$services' => { log => { package => "Venus/Path", argument => { '$metadata' => "tmplog" } } } } )); # bless(..., 'Venus::Config')
read_perl_file(string $file) (Venus::Config)
The read_perl_file method uses Venus::Path to return a new Venus::Config object based on the file provided.
# given: synopsis package main; $config = $config->read_perl_file('t/conf/read.perl'); # bless(..., 'Venus::Config')
read_yaml(string $data) (Venus::Config)
The read_yaml method returns a new Venus::Config object based on the YAML string provided.
# given: synopsis package main; $config = $config->read_yaml(q( '$metadata': tmplog: /tmp/log '$services': log: package: "Venus/Path" argument: '$metadata': tmplog )); # bless(..., 'Venus::Config')
read_yaml_file(string $file) (Venus::Config)
The read_yaml_file method uses Venus::Path to return a new Venus::Config object based on the YAML string provided.
# given: synopsis package main; $config = $config->read_yaml_file('t/conf/read.yaml'); # bless(..., 'Venus::Config')
write_file(string $path) (Venus::Config)
The write_file method saves a Perl, YAML, or JSON configuration file, based on the file extension, and returns a new Venus::Config object.
# given: synopsis my $value = $config->value({ '$services' => { log => { package => "Venus/Path", argument => { value => "." } } } }); $config = $config->write_file('t/conf/write.perl'); # bless(..., 'Venus::Config')
# given: synopsis my $value = $config->value({ '$metadata' => { tmplog => "/tmp/log" }, '$services' => { log => { package => "Venus/Path", argument => { '$metadata' => "tmplog" } } } }); $config = $config->write_file('t/conf/write.json'); # bless(..., 'Venus::Config')
# given: synopsis my $value = $config->value({ '$metadata' => { tmplog => "/tmp/log" }, '$services' => { log => { package => "Venus/Path", argument => { '$metadata' => "tmplog" } } } }); $config = $config->write_file('t/conf/write.yaml'); # bless(..., 'Venus::Config')
write_json() (string)
The write_json method returns a JSON encoded string based on the "value" held by the underlying Venus::Config object.
# given: synopsis my $value = $config->value({ '$services' => { log => { package => "Venus::Path" }, }, }); my $json = $config->write_json; # '{ "$services":{ "log":{ "package":"Venus::Path" } } }'
write_json_file(string $path) (Venus::Config)
The write_json_file method saves a JSON configuration file and returns a new Venus::Config object.
# given: synopsis my $value = $config->value({ '$services' => { log => { package => "Venus/Path", argument => { value => "." } } } }); $config = $config->write_json_file('t/conf/write.json'); # bless(..., 'Venus::Config')
write_perl() (string)
The write_perl method returns a FILE encoded string based on the "value" held by the underlying Venus::Config object.
# given: synopsis my $value = $config->value({ '$services' => { log => { package => "Venus::Path" }, }, }); my $perl = $config->write_perl; # '{ "\$services" => { log => { package => "Venus::Path" } } }'
write_perl_file(string $path) (Venus::Config)
The write_perl_file method saves a Perl configuration file and returns a new Venus::Config object.
# given: synopsis my $value = $config->value({ '$services' => { log => { package => "Venus/Path", argument => { value => "." } } } }); $config = $config->write_perl_file('t/conf/write.perl'); # bless(..., 'Venus::Config')
write_yaml() (string)
The write_yaml method returns a FILE encoded string based on the "value" held by the underlying Venus::Config object.
# given: synopsis my $value = $config->value({ '$services' => { log => { package => "Venus::Path" }, }, }); my $yaml = $config->write_yaml; # '---\n$services:\n\s\slog:\n\s\s\s\spackage:\sVenus::Path'
write_yaml_file(string $path) (Venus::Config)
The write_yaml_file method saves a YAML configuration file and returns a new Venus::Config object.
# given: synopsis my $value = $config->value({ '$services' => { log => { package => "Venus/Path", argument => { value => "." } } } }); $config = $config->write_yaml_file('t/conf/write.yaml'); # bless(..., 'Venus::Config')
Awncorp, awncorp@cpan.org
awncorp@cpan.org
Copyright (C) 2022, Awncorp, awncorp@cpan.org.
This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.
To install Venus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Venus
CPAN shell
perl -MCPAN -e shell install Venus
For more information on module installation, please visit the detailed CPAN module installation guide.