Data::Object::Vars
Env Vars Class for Perl 5
package main; use Data::Object::Vars; local %ENV = (USER => 'ubuntu', HOME => '/home/ubuntu'); my $vars = Data::Object::Vars->new( 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 integrates behaviors from:
Data::Object::Role::Buildable
Data::Object::Role::Proxyable
Data::Object::Role::Stashable
This package uses type constraints from:
Types::Standard
This package has the following attributes:
named(HashRef)
This attribute is read-only, accepts (HashRef) values, and is optional.
(HashRef)
This package implements the following methods:
exists(Str $key) : Any
The exists method takes a name or index and returns truthy if an associated value exists.
# given: synopsis $vars->exists('iam'); # truthy
# given: synopsis $vars->exists('USER'); # truthy
# given: synopsis $vars->exists('PATH'); # falsy
# given: synopsis $vars->exists('user'); # truthy
get(Str $key) : Any
The get method takes a name or index and returns the associated value.
# given: synopsis $vars->get('iam'); # ubuntu
# given: synopsis $vars->get('USER'); # ubuntu
# given: synopsis $vars->get('PATH'); # undef
# given: synopsis $vars->get('user'); # ubuntu
name(Str $key) : Any
The name method takes a name or index and returns index if the the associated value exists.
# given: synopsis $vars->name('iam'); # USER
# given: synopsis $vars->name('USER'); # USER
# given: synopsis $vars->name('PATH'); # undef
# given: synopsis $vars->name('user'); # USER
set(Str $key, Maybe[Any] $value) : Any
The set method takes a name or index and sets the value provided if the associated argument exists.
# given: synopsis $vars->set('iam', 'root'); # root
# given: synopsis $vars->set('USER', 'root'); # root
# given: synopsis $vars->set('PATH', '/tmp'); # undef # is not set
# given: synopsis $vars->set('user', 'root'); # root
stashed() : HashRef
The stashed method returns the stashed data associated with the object.
# given: synopsis $vars->stashed
Al Newkirk, awncorp@cpan.org
awncorp@cpan.org
Copyright (C) 2011-2019, Al Newkirk, et al.
This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file".
Wiki
Project
Initiatives
Milestones
Contributing
Issues
To install Data::Object::Vars, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Object::Vars
CPAN shell
perl -MCPAN -e shell install Data::Object::Vars
For more information on module installation, please visit the detailed CPAN module installation guide.