1Storm::Transaction(3) User Contributed Perl DocumentationStorm::Transaction(3)
2
3
4
6 Storm::Transaction - Execute a code block in a database transaction
7
9 use Storm::Transaction;
10
11 $txn = Storm::Transaction->new( $storm, sub {
12
13 ... do work on $storm ...
14
15 });
16
17 eval { $source->commit };
18
19 print "transaction successfull" if ! $@;
20
22 "Storm::Transaction" executes a block of code within a datbase
23 transaction. This requires that the database supports transactions. If
24 the database does not support transactions, the code block will simply
25 be invoked.
26
28 storm
29 The Storm object to perform transactions on.
30
31 code
32 The code to be invoked within the transaction. If the code block
33 finishes without any errors, then the database changes are
34 commited. If errors are encountered, then the changes are rolled
35 back.
36
38 commit
39 Begins a new transaction and then invokes the code block to perform
40 the work. Database changes are committed if the code block
41 executes without any errors. If errors are thrown, then the
42 changes work are rolled back.
43
44 It is useful to call commit within an "eval { }" block to trap any
45 errors that are thrown. Alternatively, use a module like TryCatch
46 or Try::Tiny and call commit within a "try { }" block.
47
49 Jeffrey Ray Hallock <jeffrey.hallock at gmail dot com>
50
52 Copyright (c) 2010 Jeffrey Ray Hallock. All rights reserved.
53 This program is free software; you can redistribute it and/or
54 modify it under the same terms as Perl itself.
55
56
57
58perl v5.36.0 2023-01-20 Storm::Transaction(3)