Venus::Config
Config Class
Config Class for Perl 5
method: edit_file method: new method: read_env method: read_env_file method: read_file method: read_json method: read_json_file method: read_perl method: read_perl_file method: read_yaml method: read_yaml_file method: write_env method: write_env_file method: write_file method: write_json method: write_json_file method: write_perl method: write_perl_file method: write_yaml method: write_yaml_file
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.
Venus::Kind::Utility
Venus::Role::Buildable Venus::Role::Valuable
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.
edit_file(string $file, string | coderef $code) (Venus::Config)
{ since => '3.10', }
The new method constructs an instance of the package.
new(any @args) (Venus::Config)
{ since => '4.15', }
The read_env method returns a new Venus::Config object based on the string of key/value pairs provided. This method supports multiline values when enclosed in double or single quotes.
read_env(string $data) (Venus::Config)
{ since => '4.15', }
The read_env_file method uses Venus::Path to return a new Venus::Config object based on the file provided.
read_env_file(string $file) (Venus::Config)
{ since => '4.15', }
=example-1 read_env_file
# given: synopsis
package main;
$config = $config->read_env_file('t/conf/read.env');
# bless(..., '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.
read_file(string $path) (Venus::Config)
{ since => '2.91', }
=example-1 read_file
package main;
use Venus::Config;
my $config = Venus::Config->read_file('t/conf/read.perl');
# bless(..., 'Venus::Config')
The read_json method returns a new Venus::Config object based on the JSON string provided.
read_json(string $data) (Venus::Config)
{ since => '2.91', }
=example-1 read_json
# given: synopsis
package main;
$config = $config->read_json(q(
{
"$metadata": {
"tmplog": "/tmp/log"
},
"$services": {
"log": { "package": "Venus/Path", "argument": { "$metadata": "tmplog" } }
}
}
));
# bless(..., 'Venus::Config')
The read_json_file method uses Venus::Path to return a new Venus::Config object based on the file provided.
read_json_file(string $file) (Venus::Config)
{ since => '2.91', }
=example-1 read_json_file
# given: synopsis
package main;
$config = $config->read_json_file('t/conf/read.json');
# bless(..., 'Venus::Config')
The read_perl method returns a new Venus::Config object based on the Perl string provided.
read_perl(string $data) (Venus::Config)
{ since => '2.91', }
=example-1 read_perl
# given: synopsis
package main;
$config = $config->read_perl(q(
{
'$metadata' => {
tmplog => "/tmp/log"
},
'$services' => {
log => { package => "Venus/Path", argument => { '$metadata' => "tmplog" } }
}
}
));
# bless(..., 'Venus::Config')
The read_perl_file method uses Venus::Path to return a new Venus::Config object based on the file provided.
read_perl_file(string $file) (Venus::Config)
{ since => '2.91', }
=example-1 read_perl_file
# given: synopsis
package main;
$config = $config->read_perl_file('t/conf/read.perl');
# bless(..., 'Venus::Config')
The read_yaml method returns a new Venus::Config object based on the YAML string provided.
read_yaml(string $data) (Venus::Config)
{ since => '2.91', }
=example-1 read_yaml
# given: synopsis
package main;
$config = $config->read_yaml(q(
'$metadata':
tmplog: /tmp/log
'$services':
log:
package: "Venus/Path"
argument:
'$metadata': tmplog
));
# bless(..., 'Venus::Config')
The read_yaml_file method uses Venus::Path to return a new Venus::Config object based on the YAML string provided.
read_yaml_file(string $file) (Venus::Config)
{ since => '2.91', }
=example-1 read_yaml_file
# given: synopsis
package main;
$config = $config->read_yaml_file('t/conf/read.yaml');
# bless(..., 'Venus::Config')
The write_env method returns a string representing environment variable key/value pairs based on the "value" held by the underlying Venus::Config object. Multiline values are escaped using \n notation and enclosed in double quotes.
write_env() (string)
{ since => '4.15', }
The write_env_file method saves a environment configuration file and returns a new Venus::Config object.
write_env_file(string $path) (Venus::Config)
{ since => '4.15', }
=example-1 write_env_file
# given: synopsis
my $value = $config->value({
APPNAME => "Example",
APPTAG => "Godzilla",
APPVER => 0.01,
});
$config = $config->write_env_file('t/conf/write.env');
# bless(..., '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.
write_file(string $path) (Venus::Config)
{ since => '2.91', }
=example-1 write_file
# given: synopsis
my $value = $config->value({
'$services' => {
log => { package => "Venus/Path", argument => { value => "." } }
}
});
$config = $config->write_file('t/conf/write.perl');
# bless(..., 'Venus::Config')
The write_json method returns a JSON encoded string based on the "value" held by the underlying Venus::Config object.
write_json() (string)
{ since => '2.91', }
=example-1 write_json
# given: synopsis
my $value = $config->value({
'$services' => {
log => { package => "Venus::Path" },
},
});
my $json = $config->write_json;
# '{ "$services":{ "log":{ "package":"Venus::Path" } } }'
The write_json_file method saves a JSON configuration file and returns a new Venus::Config object.
write_json_file(string $path) (Venus::Config)
{ since => '2.91', }
=example-1 write_json_file
# 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')
The write_perl method returns a FILE encoded string based on the "value" held by the underlying Venus::Config object.
write_perl() (string)
{ since => '2.91', }
=example-1 write_perl
# given: synopsis
my $value = $config->value({
'$services' => {
log => { package => "Venus::Path" },
},
});
my $perl = $config->write_perl;
# '{ "\$services" => { log => { package => "Venus::Path" } } }'
The write_perl_file method saves a Perl configuration file and returns a new Venus::Config object.
write_perl_file(string $path) (Venus::Config)
{ since => '2.91', }
=example-1 write_perl_file
# 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')
The write_yaml method returns a FILE encoded string based on the "value" held by the underlying Venus::Config object.
write_yaml() (string)
{ since => '2.91', }
=example-1 write_yaml
# 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'
The write_yaml_file method saves a YAML configuration file and returns a new Venus::Config object.
write_yaml_file(string $path) (Venus::Config)
{ since => '2.91', }
=example-1 write_yaml_file
# 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')
t/Venus.t: present: authors t/Venus.t: present: license
82 POD Errors
The following errors were encountered while parsing the POD:
- Around line 14:
Unknown directive: =name
- Around line 22:
Unknown directive: =tagline
- Around line 30:
Unknown directive: =abstract
- Around line 38:
Unknown directive: =includes
- Around line 65:
Unknown directive: =synopsis
- Around line 87:
Unknown directive: =description
- Around line 96:
Unknown directive: =inherits
- Around line 104:
Unknown directive: =integrates
- Around line 113:
Unknown directive: =method
- Around line 119:
Unknown directive: =signature
- Around line 123:
Unknown directive: =metadata
- Around line 147:
=cut found outside a pod block. Skipping to next block.
- Around line 167:
Unknown directive: =method
- Around line 171:
Unknown directive: =signature
- Around line 175:
Unknown directive: =metadata
- Around line 193:
=cut found outside a pod block. Skipping to next block.
- Around line 213:
=cut found outside a pod block. Skipping to next block.
- Around line 224:
Unknown directive: =method
- Around line 230:
Unknown directive: =signature
- Around line 234:
Unknown directive: =metadata
- Around line 254:
=cut found outside a pod block. Skipping to next block.
- Around line 282:
=cut found outside a pod block. Skipping to next block.
- Around line 307:
=cut found outside a pod block. Skipping to next block.
- Around line 319:
Unknown directive: =method
- Around line 324:
Unknown directive: =signature
- Around line 328:
Unknown directive: =metadata
- Around line 358:
Unknown directive: =method
- Around line 363:
Unknown directive: =signature
- Around line 367:
Unknown directive: =metadata
- Around line 406:
=cut found outside a pod block. Skipping to next block.
- Around line 437:
=cut found outside a pod block. Skipping to next block.
- Around line 458:
Unknown directive: =method
- Around line 463:
Unknown directive: =signature
- Around line 467:
Unknown directive: =metadata
- Around line 513:
Unknown directive: =method
- Around line 518:
Unknown directive: =signature
- Around line 522:
Unknown directive: =metadata
- Around line 559:
Unknown directive: =method
- Around line 564:
Unknown directive: =signature
- Around line 568:
Unknown directive: =metadata
- Around line 606:
Unknown directive: =method
- Around line 611:
Unknown directive: =signature
- Around line 615:
Unknown directive: =metadata
- Around line 645:
Unknown directive: =method
- Around line 650:
Unknown directive: =signature
- Around line 654:
Unknown directive: =metadata
- Around line 699:
Unknown directive: =method
- Around line 704:
Unknown directive: =signature
- Around line 708:
Unknown directive: =metadata
- Around line 745:
Unknown directive: =method
- Around line 752:
Unknown directive: =signature
- Around line 756:
Unknown directive: =metadata
- Around line 780:
=cut found outside a pod block. Skipping to next block.
- Around line 805:
=cut found outside a pod block. Skipping to next block.
- Around line 835:
=cut found outside a pod block. Skipping to next block.
- Around line 849:
Unknown directive: =method
- Around line 854:
Unknown directive: =signature
- Around line 858:
Unknown directive: =metadata
- Around line 893:
Unknown directive: =method
- Around line 898:
Unknown directive: =signature
- Around line 902:
Unknown directive: =metadata
- Around line 952:
=cut found outside a pod block. Skipping to next block.
- Around line 991:
=cut found outside a pod block. Skipping to next block.
- Around line 1013:
Unknown directive: =method
- Around line 1018:
Unknown directive: =signature
- Around line 1022:
Unknown directive: =metadata
- Around line 1061:
Unknown directive: =method
- Around line 1066:
Unknown directive: =signature
- Around line 1070:
Unknown directive: =metadata
- Around line 1111:
Unknown directive: =method
- Around line 1116:
Unknown directive: =signature
- Around line 1120:
Unknown directive: =metadata
- Around line 1151:
Unknown directive: =method
- Around line 1156:
Unknown directive: =signature
- Around line 1160:
Unknown directive: =metadata
- Around line 1193:
Unknown directive: =method
- Around line 1198:
Unknown directive: =signature
- Around line 1202:
Unknown directive: =metadata
- Around line 1241:
Unknown directive: =method
- Around line 1246:
Unknown directive: =signature
- Around line 1250:
Unknown directive: =metadata
- Around line 1291:
Unknown directive: =partials