Venus::Config

Config Class

Config Class for Perl 5

method: edit_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_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 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_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

59 POD Errors

The following errors were encountered while parsing the POD:

Around line 13:

Unknown directive: =name

Around line 21:

Unknown directive: =tagline

Around line 29:

Unknown directive: =abstract

Around line 37:

Unknown directive: =includes

Around line 59:

Unknown directive: =synopsis

Around line 81:

Unknown directive: =description

Around line 90:

Unknown directive: =inherits

Around line 98:

Unknown directive: =integrates

Around line 107:

Unknown directive: =method

Around line 113:

Unknown directive: =signature

Around line 117:

Unknown directive: =metadata

Around line 141:

=cut found outside a pod block. Skipping to next block.

Around line 161:

Unknown directive: =method

Around line 166:

Unknown directive: =signature

Around line 170:

Unknown directive: =metadata

Around line 209:

=cut found outside a pod block. Skipping to next block.

Around line 240:

=cut found outside a pod block. Skipping to next block.

Around line 261:

Unknown directive: =method

Around line 266:

Unknown directive: =signature

Around line 270:

Unknown directive: =metadata

Around line 316:

Unknown directive: =method

Around line 321:

Unknown directive: =signature

Around line 325:

Unknown directive: =metadata

Around line 362:

Unknown directive: =method

Around line 367:

Unknown directive: =signature

Around line 371:

Unknown directive: =metadata

Around line 409:

Unknown directive: =method

Around line 414:

Unknown directive: =signature

Around line 418:

Unknown directive: =metadata

Around line 448:

Unknown directive: =method

Around line 453:

Unknown directive: =signature

Around line 457:

Unknown directive: =metadata

Around line 502:

Unknown directive: =method

Around line 507:

Unknown directive: =signature

Around line 511:

Unknown directive: =metadata

Around line 548:

Unknown directive: =method

Around line 553:

Unknown directive: =signature

Around line 557:

Unknown directive: =metadata

Around line 607:

=cut found outside a pod block. Skipping to next block.

Around line 646:

=cut found outside a pod block. Skipping to next block.

Around line 668:

Unknown directive: =method

Around line 673:

Unknown directive: =signature

Around line 677:

Unknown directive: =metadata

Around line 716:

Unknown directive: =method

Around line 721:

Unknown directive: =signature

Around line 725:

Unknown directive: =metadata

Around line 766:

Unknown directive: =method

Around line 771:

Unknown directive: =signature

Around line 775:

Unknown directive: =metadata

Around line 806:

Unknown directive: =method

Around line 811:

Unknown directive: =signature

Around line 815:

Unknown directive: =metadata

Around line 848:

Unknown directive: =method

Around line 853:

Unknown directive: =signature

Around line 857:

Unknown directive: =metadata

Around line 896:

Unknown directive: =method

Around line 901:

Unknown directive: =signature

Around line 905:

Unknown directive: =metadata

Around line 946:

Unknown directive: =partials