Venus::Vars - Vars Class
Vars Class for Perl 5
package main; use Venus::Vars; my $vars = Venus::Vars->new( value => { USER => 'awncorp', HOME => '/home/awncorp', }, 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}
This package provides methods for accessing %ENV items.
%ENV
This package has the following attributes:
named(HashRef)
This attribute is read-write, accepts (HashRef) values, is optional, and defaults to {}.
(HashRef)
{}
This package inherits behaviors from:
Venus::Kind::Utility
This package integrates behaviors from:
Venus::Role::Accessible
Venus::Role::Buildable
Venus::Role::Proxyable
Venus::Role::Valuable
This package provides the following methods:
default() (HashRef)
The default method returns the default value, i.e. {%ENV}.
{%ENV}
Since 0.01
0.01
# given: synopsis; my $default = $vars->default; # { USER => 'awncorp', HOME => '/home/awncorp', ... }
exists(Str $key) (Bool)
The exists method takes a name or index and returns truthy if an associated value exists.
# given: synopsis; my $exists = $vars->exists('iam');; # 1
# given: synopsis; my $exists = $vars->exists('USER');; # 1
# given: synopsis; my $exists = $vars->exists('PATH'); # undef
# given: synopsis; my $exists = $vars->exists('user'); # 1
get(Str $key) (Any)
The get method takes a name or index and returns the associated value.
# given: synopsis; my $get = $vars->get('iam'); # "awncorp"
# given: synopsis; my $get = $vars->get('USER'); # "awncorp"
# given: synopsis; my $get = $vars->get('PATH'); # undef
# given: synopsis; my $get = $vars->get('user'); # "awncorp"
name(Str $key) (Str | Undef)
The name method takes a name or index and returns index if the the associated value exists.
# given: synopsis; my $name = $vars->name('iam'); # "USER"
# given: synopsis; my $name = $vars->name('USER'); # "USER"
# given: synopsis; my $name = $vars->name('PATH'); # undef
# given: synopsis; my $name = $vars->name('user'); # "USER"
set(Str $key, Any $value) (Any)
The set method takes a name or index and sets the value provided if the associated argument exists.
# given: synopsis; my $set = $vars->set('iam', 'root'); # "root"
# given: synopsis; my $set = $vars->set('USER', 'root'); # "root"
# given: synopsis; my $set = $vars->set('PATH', '/tmp'); # undef
# given: synopsis; my $set = $vars->set('user', 'root'); # "root"
unnamed() (HashRef)
The unnamed method returns an arrayref of values which have not been named using the named attribute.
named
package main; use Venus::Vars; my $vars = Venus::Vars->new( value => { USER => 'awncorp', HOME => '/home/awncorp', }, named => { root => 'HOME', }, ); my $unnamed = $vars->unnamed; # { USER => "awncorp" }
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.