The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Venus::Vars - Vars Class

ABSTRACT

Vars Class for Perl 5

SYNOPSIS

  package main;

  use Venus::Vars;

  my $vars = Venus::Vars->new(
    value => { USER => 'cpanery', HOME => '/home/cpanery', },
    named => { iam => 'USER', root => 'HOME', },
  );

  # $vars->root; # $ENV{HOME}
  # $vars->home; # $ENV{HOME}
  # $vars->get('home'); # $ENV{HOME}
  # $vars->get('HOME'); # $ENV{HOME}

  # $vars->iam; # $ENV{USER}
  # $vars->user; # $ENV{USER}
  # $vars->get('user'); # $ENV{USER}
  # $vars->get('USER'); # $ENV{USER}

DESCRIPTION

This package provides methods for accessing %ENV items.

ATTRIBUTES

This package has the following attributes:

named

  named(HashRef)

This attribute is read-write, accepts (HashRef) values, is optional, and defaults to {}.

INHERITS

This package inherits behaviors from:

Venus::Kind::Utility

INTEGRATES

This package integrates behaviors from:

Venus::Role::Accessible

Venus::Role::Proxyable

METHODS

This package provides the following methods:

default

  default() (HashRef)

The default method returns the default value, i.e. {%ENV}.

Since 0.01

default example 1
  # given: synopsis;

  my $default = $vars->default;

  # { USER => 'cpanery', HOME => '/home/cpanery', ... }

exists

  exists(Str $key) (Bool)

The exists method takes a name or index and returns truthy if an associated value exists.

Since 0.01

exists example 1
  # given: synopsis;

  my $exists = $vars->exists('iam');;

  # 1
exists example 2
  # given: synopsis;

  my $exists = $vars->exists('USER');;

  # 1
exists example 3
  # given: synopsis;

  my $exists = $vars->exists('PATH');

  # undef
exists example 4
  # given: synopsis;

  my $exists = $vars->exists('user');

  # 1

get

  get(Str $key) (Any)

The get method takes a name or index and returns the associated value.

Since 0.01

get example 1
  # given: synopsis;

  my $get = $vars->get('iam');

  # "cpanery"
get example 2
  # given: synopsis;

  my $get = $vars->get('USER');

  # "cpanery"
get example 3
  # given: synopsis;

  my $get = $vars->get('PATH');

  # undef
get example 4
  # given: synopsis;

  my $get = $vars->get('user');

  # "cpanery"

name

  name(Str $key) (Str | Undef)

The name method takes a name or index and returns index if the the associated value exists.

Since 0.01

name example 1
  # given: synopsis;

  my $name = $vars->name('iam');

  # "USER"
name example 2
  # given: synopsis;

  my $name = $vars->name('USER');

  # "USER"
name example 3
  # given: synopsis;

  my $name = $vars->name('PATH');

  # undef
name example 4
  # given: synopsis;

  my $name = $vars->name('user');

  # "USER"

set

  set(Str $key, Any $value) (Any)

The set method takes a name or index and sets the value provided if the associated argument exists.

Since 0.01

set example 1
  # given: synopsis;

  my $set = $vars->set('iam', 'root');

  # "root"
set example 2
  # given: synopsis;

  my $set = $vars->set('USER', 'root');

  # "root"
set example 3
  # given: synopsis;

  my $set = $vars->set('PATH', '/tmp');

  # undef
set example 4
  # given: synopsis;

  my $set = $vars->set('user', 'root');

  # "root"

unnamed

  unnamed() (HashRef)

The unnamed method returns an arrayref of values which have not been named using the named attribute.

Since 0.01

unnamed example 1
  package main;

  use Venus::Vars;

  my $vars = Venus::Vars->new(
    value => { USER => 'cpanery', HOME => '/home/cpanery', },
    named => { root => 'HOME', },
  );

  my $unnamed = $vars->unnamed;

  # { USER => "cpanery" }

AUTHORS

Cpanery, cpanery@cpan.org

LICENSE

Copyright (C) 2021, Cpanery

Read the "license" file.