Rex::Shared::Var(3pm)

Rex::Shared::Var3pm

Share variables across rex tasks

Usage

 BEGIN {                           # put share in a BEGIN block
   use Rex::Shared::Var;
   share qw($scalar @array %hash); # share the listed variables
 }

Overview

Share variables across Rex tasks with the help of Storable, using a "vars.db.$PID" file in the local directory, where $PID is the PID of the parent process.

Limitations

Currently nesting data structures works only if the assignment is made on the top level of the structure, or when the nested structures are also shared variables. For example:

 BEGIN {
   use Rex::Shared::Var;
   share qw(%hash %nested);
 }
 # this doesn't work as expected
 $hash{key} = { nested_key => 42 };
 $hash{key}->{nested_key} = -1; # $hash{key}->{nested_key} still returns 42
 # workaround 1 - top level assignments
 $hash{key} = { nested_key => 42 };
 $hash{key} = { nested_key => -1 };
 # workaround 2 - nesting shared variables
 $nested{nested_key}      = 42;
 $hash{key}               = \%nested;
 $hash{key}->{nested_key} = -1;

Methods

share

Share the passed list of variables across Rex tasks. Should be used in a "BEGIN" block.

 BEGIN {
   use Rex::Shared::Var;
   share qw($error_count);
 }
 task 'count', sub {
   $error_count += run 'wc -l /var/log/syslog';
 };
 after_task_finished 'count', sub {
   say "Total number of errors: $error_count";
 };

Releases

5 releases since Debian 9 (Stretch); the text changed 4 times.

  1. 9
  2. 10
  3. 11
  4. 12
  5. 13

From rex 1.16.0-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.