The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

Name

SPVM::Sys::Env - Environemnt Variables

Description

The Sys::Env class in SPVM has methods to manipulate environemnt variables.

Usage

  use Sys::Env;
  
  my $path = Sys::Env->getenv("PATH");
  
  Sys::Env->setenv("PATH", "/foo/bar");

Class Methods

getenv

static method getenv : string ($name : string);

Calls the getenv function and copy its return value and returns it.

Exceptions:

$name must be defined. Otherwise an exception is thrown.

setenv

static method setenv : int ($name : string, $value : string, $overwrite : int);

Calls the setenv function and returns its return value.

Exceptions:

$name must be defined. Otherwise an exception is thrown.

$value must be defined. Otherwise an exception is thrown.

If setenv failed, an exception is thrown and eval_error_id is set to the basic type ID of the Error::System.

In Windows the following exception is thrown. setenv is not supported in this system(defined(_WIN32)).

unsetenv

static method unsetenv : int ($name : string);

Calls the unsetenv function and returns its return value.

Exceptions:

$name must be defined. Otherwise an exception is thrown.

If unsetenv failed, an exception is thrown and eval_error_id is set to the basic type ID of the Error::System.

In Windows the following exception is thrown. unsetenv is not supported in this system(defined(_WIN32)).

_putenv_s

static method _putenv_s : int ($name : string, $value : string);

Calls the _putenv_s function and returns its return value.

Exceptions:

$name must be defined. Otherwise an exception is thrown.

$value must be defined. Otherwise an exception is thrown.

If _putenv_s failed, an exception is thrown and eval_error_id is set to the basic type ID of the Error::System.

In OSs ohter than Windows the following exception is thrown. _putenv_s is not supported in this system(!defined(_WIN32)).

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License