Rex::Shared::Var(3)

πŸ“¦ version 1.14.3, in nixos 26.05, nixpkgs unstable

πŸ’– 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