1Rex::Shared::Var(3) User Contributed Perl Documentation Rex::Shared::Var(3)
2
3
4
6 Rex::Shared::Var - Share variables across Rex tasks
7
9 Share variables across Rex tasks with the help of Storable, using a
10 "vars.db.$PID" file in the local directory, where $PID is the PID of
11 the parent process.
12
14 BEGIN { # put share in a BEGIN block
15 use Rex::Shared::Var;
16 share qw($scalar @array %hash); # share the listed variables
17 }
18
20 Currently nesting data structures works only if the assignment is made
21 on the top level of the structure, or when the nested structures are
22 also shared variables. For example:
23
24 BEGIN {
25 use Rex::Shared::Var;
26 share qw(%hash %nested);
27 }
28
29 # this doesn't work as expected
30 $hash{key} = { nested_key => 42 };
31 $hash{key}->{nested_key} = -1; # $hash{key}->{nested_key} still returns 42
32
33 # workaround 1 - top level assignments
34 $hash{key} = { nested_key => 42 };
35 $hash{key} = { nested_key => -1 };
36
37 # workaround 2 - nesting shared variables
38 $nested{nested_key} = 42;
39 $hash{key} = \%nested;
40 $hash{key}->{nested_key} = -1;
41
43 share
44 Share the passed list of variables across Rex tasks. Should be used in
45 a "BEGIN" block.
46
47 BEGIN {
48 use Rex::Shared::Var;
49 share qw($error_count);
50 }
51
52 task 'count', sub {
53 $error_count += run 'wc -l /var/log/syslog';
54 };
55
56 after_task_finished 'count', sub {
57 say "Total number of errors: $error_count";
58 };
59
60
61
62perl v5.34.0 2021-07-21 Rex::Shared::Var(3)