GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Alzabo::ChangeTracker(3) User Contributed Perl Documentation Alzabo::ChangeTracker(3)

Alzabo::ChangeTracker - Saves a set of changes as callbacks that can be backed out if needed

  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;
  }

The trick ...

We only want to have one object of this type at any one time. In addition, only the stack frame that created it should be able to clear it (except through a backout). Why? Here's an example in pseudo-code to help explain it:

 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
 }

If at point X we were to really clear out the changes, even the changes just from sub bar, we'd have a problem. Because if at point Y, things go to hell and we want to back out the changes, we want to back out the changes from sub foo _AND_ sub bar. However, if bar is also an entry point we want to be able to track changes in bar and clear them from bar.

Dave Rolsky, <autarch@urth.org>
2022-04-07 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.