]> Dogcows Code - chaz/p5-File-KDBX/blob - lib/File/KDBX/Transaction.pm
1c0cb4f5137dce308c444cd747ad3a1b36b3c53a
[chaz/p5-File-KDBX] / lib / File / KDBX / Transaction.pm
1 package File::KDBX::Transaction;
2 # ABSTRACT: Make multiple database edits atomically
3
4 use warnings;
5 use strict;
6
7 use Devel::GlobalDestruction;
8 use File::KDBX::Util qw(:class);
9 use namespace::clean;
10
11 our $VERSION = '0.905'; # VERSION
12
13
14 sub new {
15 my $class = shift;
16 my $object = shift;
17 $object->begin_work(@_);
18 return bless {object => $object}, $class;
19 }
20
21 sub DESTROY { !in_global_destruction and $_[0]->rollback }
22
23
24 has 'object', is => 'ro';
25
26
27 sub commit {
28 my $self = shift;
29 return if $self->{done};
30
31 my $obj = $self->object;
32 $obj->commit;
33 $self->{done} = 1;
34 return $obj;
35 }
36
37
38 sub rollback {
39 my $self = shift;
40 return if $self->{done};
41
42 my $obj = $self->object;
43 $obj->rollback;
44 $self->{done} = 1;
45 return $obj;
46 }
47
48 1;
49
50 __END__
51
52 =pod
53
54 =encoding UTF-8
55
56 =head1 NAME
57
58 File::KDBX::Transaction - Make multiple database edits atomically
59
60 =head1 VERSION
61
62 version 0.905
63
64 =head1 ATTRIBUTES
65
66 =head2 object
67
68 Get the object being transacted on.
69
70 =head1 METHODS
71
72 =head2 new
73
74 $txn = File::KDBX::Transaction->new($object);
75
76 Construct a new database transaction for editing an object atomically.
77
78 =head2 commit
79
80 $txn->commit;
81
82 Commit the transaction, making updates to the L</object> permanent.
83
84 =head2 rollback
85
86 $txn->rollback;
87
88 Roll back the transaction, throwing away any updates to the L</object> made since the transaction began. This
89 happens automatically when the transaction is released, unless it has already been committed.
90
91 =head1 BUGS
92
93 Please report any bugs or feature requests on the bugtracker website
94 L<https://github.com/chazmcgarvey/File-KDBX/issues>
95
96 When submitting a bug or request, please include a test-file or a
97 patch to an existing test-file that illustrates the bug or desired
98 feature.
99
100 =head1 AUTHOR
101
102 Charles McGarvey <ccm@cpan.org>
103
104 =head1 COPYRIGHT AND LICENSE
105
106 This software is copyright (c) 2022 by Charles McGarvey.
107
108 This is free software; you can redistribute it and/or modify it under
109 the same terms as the Perl 5 programming language system itself.
110
111 =cut
This page took 0.039839 seconds and 3 git commands to generate.