From: Michael Neumann Date: 2004-11-05T00:24:30+09:00 Subject: Re: [ANN] Transaction::Simple 1.2.0 On Thu, Nov 04, 2004 at 10:08:17AM -0500, Austin Ziegler wrote: > On Thu, 4 Nov 2004 15:21:49 +0100, Michael Neumann > >> reasons that I implemented it this way, the most important being > >> your implementation of Array#take_snapshot: it dups the array: > >> > >> irb#1(main):001:0> arr = %w(a b c d) > >> => ["a", "b", "c", "d"] > >> irb#1(main):002:0> arr2 = arr.dup > >> => ["a", "b", "c", "d"] > >> irb#1(main):003:0> arr2[0] << "z" > >> => "az" > >> irb#1(main):004:0> arr > >> => ["az", "b", "c", "d"] > >> irb#1(main):005:0> > > > > Right! And that's for my purposes a good thing, as I register > > objects that I want to be "backtrackable" (it's more flexible this > > way). > > Mmm. More flexible, but more work. When I want a transaction on an > object, I want its full state kept. This, to me, is useless: > > a = %w(a b c) # 'a', 'b', 'c' > # take a snapshot > a << "d" # 'a', 'b', 'c', 'd' > a[0] << "z" # 'az', 'b', 'c', 'd' > # restore # 'az', 'b', 'c' Sure. My problem indeed is completely different. I register callbacks for components which live in a "tree". Then I want to be able to make snapshots and go back in time. I can't use marshal (or dup), without loosing the callbacks (or use an external representation of the components, e.g. as IOWA does with it's positional component id's). > Simply taking snapshots of the current object references (which is > what your snapshot process does) only performs part of the necessary > behaviour for true transaction support. I actually was trying > something like this (not as formalised, certainly) with PDF::Writer > and was running into problems because my objects were changing even > when I didn't want them to change, which is why I created > Transaction::Simple. Well, it's up to you whether they change or not, or whether you register them for being part of the transaction or not. But sure, deep-cloning is probably much more user-friendly. Regards, Michael