NAME Perinci::Tx::Manager - Transaction manager VERSION version 0.29 SYNOPSIS # used by Perinci::Access::InProcess DESCRIPTION This class implements transaction and undo manager (TM), as specified by Rinci::function::Transaction and Riap::Transaction. It is meant to be instantiated by Perinci::Access::InProcess, but will also be passed to transactional functions to save undo/redo data. It uses SQLite database to store transaction list and undo/redo data as well as transaction data directory to provide trash_dir/tmp_dir for functions that require it. ATTRIBUTES _tx_id This is just a convenience so that methods that require tx_id will get the default value from here if tx_id not specified in arguments. METHODS new(%args) => OBJ Create new object. Arguments: * pa => OBJ Perinci::Access::InProcess object. This is required by Perinci::Tx::Manager to load/get functions when it wants to perform undo/redo/recovery. Perinci::Access::InProcess conveniently require() the Perl modules and wraps the functions. * data_dir => STR (default "~/.perinci/.tx") * max_txs => INT (default 1000) Limit maximum number of transactions maintained by the TM, including all rolled back and committed transactions, since they are still recorded in the database. The default is 1000. Not yet implemented. After this limit is reached, cleanup will be performed to delete rolled back transactions, and after that committed transactions. * max_open_txs => INT (default 100) Limit maximum number of open (in progress, aborted, prepared) transactions. This exclude resolved transactions (rolled back and committed). The default is no limit. Not yet implemented. After this limit is reached, starting a new transaction will fail. * max_committed_txs => INT (default 100) Limit maximum number of committed transactions that is recorded by the database. This is equal to the number of undo steps that are remembered. After this limit is reached, cleanup will automatically be performed so that the oldest committed transactions are purged. Not yet implemented. * max_open_age => INT Limit the maximum age of open transactions (in seconds). If this limit is reached, in progress transactions will automatically be purged because it times out. Not yet implemented. * max_committed_age => INT Limit the maximum age of committed transactions (in seconds). If this limit is reached, the old transactions will start to be purged. Not yet implemented. $tx->get_trash_dir => RESP $tx->get_tmp_dir => RESP $tm->begin(%args) => RESP Start a new transaction. Arguments: tx_id (str, required, unless already supplied via _tx_id()), twopc (bool, optional, currently must be false since distributed transaction is not yet supported), summary (optional). TM will create an entry for this transaction in its database. $tm->call(%args) => RESP Arguments: "sp" (optional, savepoint name, must be unique for this transaction, not yet implemented), "f" (fully-qualified function name), "args" (arguments to function, hashref), "dry_run" (bool). Or, "calls" (list of function calls, array, [[f1, args1], ...], alternative to specifying "f" and "args"). Call one or more functions inside the scope of a transaction, i.e. recording the undo call for each function call before actually calling it, to allow for rollback/undo/redo. TM will first check that each function supports transaction, and return 412 if it does not. (Note: if call is a dry-run call, or to a pure function [one that does not produce side effects], you can just perform the function directly without using TM.) To call a single function, specify "f" and "args". To call several functions, supply "calls". Note: special arguments (those started with dash, "-") will be stripped from function arguments by TM. If response from function is not success, rollback() will be called. On success, will return the result from the last function. $tx->commit(%args) => RESP Arguments: tx_id $tx->rollback(%args) => RESP Arguments: tx_id, sp (optional, savepoint name to rollback to a specific savepoint only). Currently rolling back to a savepoint is not implemented. $tx->prepare(%args) => RESP Currently will return 501 (not implemented). This TM does not support distributed transaction. Arguments: tx_id $tx->savepoint(%args) => RESP Arguments: tx_id, sp (savepoint name). Currently not implemented. $tx->release_savepoint(%args) => RESP Arguments: tx_id, sp (savepoint name). Currently not implemented. $tx->undo(%args) => RESP Arguments: tx_id $tx->redo(%args) => RESP Arguments: tx_id $tx->list(%args) => RESP List transactions. Return an array of results sorted by creation date (in ascending order). Arguments: detail (bool, default 0, whether to return transaction records instead of just a list of transaction ID's). $tx->discard(%args) => RESP Discard (forget) a committed transaction. The transaction will no longer be undoable. Arguments: tx_id $tm->discard_all(%args) => RESP Discard (forget) all committed transactions. SEE ALSO Riap::Transaction Perinci::Access::InProcess Rinci::function::Undo Rinci::function::Transaction AUTHOR Steven Haryanto COPYRIGHT AND LICENSE This software is copyright (c) 2012 by Steven Haryanto. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.