Rex::Shared::Var(3)
π NAME π
Rex::Shared::Var β welcome to the Rex::Shared::Var(3) page, aka user-contributed Perl documentation, and it's all about sharing variables across Rex tasks. Bestie, it's giving "our variables are in the group chat now" energy. π
β¨ DESCRIPTION β¨
The whole point, fr fr: 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. slay. π«Ά
πΈ SYNOPSIS πΈ
Okay so put share in a BEGIN block, like this:
BEGIN { # put share in a BEGIN block
use Rex::Shared::Var;
share qw($scalar @array %hash); # share the listed variables
}
π¦ LIMITATIONS π¦
Ngl, there's a catch: 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. Example time:
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";
};
okay bye bestie β this iconic page is from perl v5.42.3, dated 2023-08-05, and yes she ate π
β¨
π¦ where this page comes from
- nixos 26.05: perl5.42.3-Rex 1.14.3
- nixpkgs unstable: perl5.42.3-Rex 1.14.3
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms