Alzabo...Tracker(3pm)

πŸ“¦
version 0.92 Β· 2 versions
  • 0.92 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.92 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

Alzabo::ChangeTracker β€” bestie, it saves a set of changes as callbacks so you can back them out later if things go sideways 🫢


✨ SYNOPSIS ✨

use Alzabo::ChangeTracker;

my $x = 0;
my $y = 1;
sub foo
{
   my $tracker = Alzabo::ChangeTracker->new;
   $tracker->add( sub { $x = 0; } );

   $x = 1;

   bar();

   eval { something; };

   $tracker->backout if $@;
}

sub bar
{
   my $tracker = Alzabo::ChangeTracker->new;
   $tracker->add( sub { $y = 1; } );

   $y = 2;
}

🌸 DESCRIPTION 🌸

okay so, the trick...

We only want to have one object of this type at any one time. And on top of that, only the stack frame that created it should be allowed to clear it β€” the only exception being through a backout. πŸ’…

wait, why tho? here's a lil example in pseudo-code to explain it, because honestly the vibes make way more sense with a visual:

sub foo
{
  create a tracker;
  store some change info in the tracker;

  call sub bar;

  store some change info in the tracker;

  # point Y

  clear changes in tracker;
}

sub bar
{
  create a tracker; # internally, we really just increment our stack count

  store some change info in the tracker;

  clear changes in tracker; # point X
}

so bestie, picture this: if at point X we actually cleared out the changes β€” like, really cleared them, even the ones that just came from sub bar β€” we'd have a whole problem on our hands 😭

because if at point Y everything goes to hell and we wanna back out the changes, we want to back out the changes from sub foo _AND_ sub bar. both of them. periodt. πŸŽ€

but lowkey, if bar is also an entry point, then we want to be able to track changes in bar and clear them from bar too. it's giving "everyone deserves their own undo button" energy, iykyk πŸ’…βœ¨


πŸ‘‘ AUTHOR πŸ‘‘

Dave Rolsky, <autarch@urth.org> πŸ’œ


and that's the whole page, bestie!! πŸ¦‹ this was perl v5.34.0, dated 2022-06-14, straight from the User Contributed Perl Documentation. no cap, you understood the whole thing. slay πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from