line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Rose::DBx::Role::NestTransaction; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
51388
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
45
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1102
|
use Role::Tiny; |
|
1
|
|
|
|
|
5457
|
|
|
1
|
|
|
|
|
8
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub nest_transaction { |
11
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
12
|
0
|
|
|
|
|
|
my $cb = shift; |
13
|
|
|
|
|
|
|
|
14
|
0
|
0
|
|
|
|
|
if ( $self->in_transaction ) { |
15
|
0
|
|
|
|
|
|
$cb->(@_); |
16
|
|
|
|
|
|
|
} else { |
17
|
0
|
0
|
|
|
|
|
$self->do_transaction($cb, @_) or die $self->error; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
return 1; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
1; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 NAME |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Rose::DBx::Role::NestTransaction - Nested transactions support for Rose::DB |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Define yout DB class |
32
|
|
|
|
|
|
|
package MyDB; |
33
|
|
|
|
|
|
|
use base 'Rose::DB'; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use Role::Tiny::With; |
36
|
|
|
|
|
|
|
with 'Rose::DBx::Role::NestTransaction'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Somewhere in your code |
39
|
|
|
|
|
|
|
MyDB->new_or_cached->nest_transaction(sub { |
40
|
|
|
|
|
|
|
User->new( name => 'name' )->save(); |
41
|
|
|
|
|
|
|
}); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
This module provides a role for Rose::DB. Just consume the role in your Rose::DB subclass |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 METHODS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 nest_transaction |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
These methods behaves like do_transaction but it repects existing transactions and do not start new one if the transaction already started. On error it revert transaction and rethrow error and on success it returns true |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 AUTHOR |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Viktor Turskyi, C<< >> |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 BUGS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Please report any bugs or feature requests to Github L |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Copyright 2012 Viktor Turskyi. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
66
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
67
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|