Rex::Shared::Var(3pm)
π NAME π
Rex::Shared::Var β share your variables across Rex tasks, bestie, no cap π«Ά
πΈ DESCRIPTION πΈ
Okay so picture this: you've got a bunch of Rex tasks and they're all refusing to talk to each other like they're in a group chat with read receipts off. Rex::Shared::Var fixes that. It lets you share variables across Rex tasks with a lil assist from Storable π¦, and it does it by keeping a file called vars.db.$PID in your local directory β where $PID is the PID of the parent process. That's literally it. Slay.
β¨ SYNOPSIS β¨
BEGIN { # put share in a BEGIN block
use Rex::Shared::Var;
share qw($scalar @array %hash); # share the listed variables
}
heads up bestie: thesharecall goes in aBEGINblock. That part is non-negotiable π
π LIMITATIONS π
Not everything is perfect, and honestly, same. Right now, nesting data structures only works if either:
- the assignment happens at the top level of the structure, or
- the nested structures are also shared variables
Like, 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;
So yeah β that deep-nesting edit? It just does not stick, $hash{key}->{nested_key} still returns 42 and you're left staring at your terminal like π§ββοΈ. Use workaround 1 or workaround 2 and you're golden π
π METHODS π
π share
Shares the passed list of variables across Rex tasks. Should be used in a BEGIN block. (Yes, again. It's that serious.)
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";
};
Look at that β one task bumps $error_count, another task reads it back like a true bestie who actually remembers what you told her π«Ά iconic behaviour fr fr.
and that's the whole vibe, periodt β¨π π¦
This page came to you courtesy of the Perl docs, version perl v5.40.1, dated 2025-10-03 β Rex::Shared::Var(3pm), out π
π¦ where this page comes from
- ubuntu resolute: rex 1.16.1-1 Β· Apache-2.0
- ubuntu stonking: rex 1.16.1-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms