in reply to how to build a transaction?

Hmm...
Looks fine for a start to me. I would like to be very sure that not one of the commits could trigger a fatal error, which would terminate the script before rolbacks are done. Maybe a __DIE__ handler could help here, or a DESTROY sub if you're wrapping your script in an OO package. These all would be futile in case of network failure, though.

Maybe you could create something with temporary records, or at least make backups of the changes. An audit log comes to mind...

Also, make sure that the rollback order (reversed commit order) is always OK and there are no cross dependencies which prevent this from working.

Good luck!

--
Cheers, Joe