line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Meta::Method::Transactional; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
10
|
|
119956
|
use strict; # keep CPANTS Kwalitee happy |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
136
|
|
4
|
5
|
|
|
5
|
|
17
|
use warnings; # keep CPANTS Kwalitee happy |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
96
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
1475
|
use MooseX::Meta::Method::Transactional::Meta::Role; |
|
5
|
|
|
|
|
28
|
|
|
5
|
|
|
|
|
22
|
|
7
|
5
|
|
|
5
|
|
6178
|
use Moose::Util::TypeConstraints; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
34
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
subtype 'SchemaGenerator', |
10
|
|
|
|
|
|
|
as 'CodeRef'; |
11
|
|
|
|
|
|
|
coerce 'SchemaGenerator', |
12
|
|
|
|
|
|
|
from duck_type(['txn_do']), |
13
|
|
|
|
|
|
|
via { my $schema = $_; sub { $schema } }; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has schema => |
16
|
|
|
|
|
|
|
( is => 'ro', |
17
|
|
|
|
|
|
|
isa => 'SchemaGenerator', |
18
|
|
|
|
|
|
|
default => sub { sub { shift->schema } }, |
19
|
|
|
|
|
|
|
coerce => 1 ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
around 'wrap' => sub { |
22
|
|
|
|
|
|
|
my ($wrap, $method, $code, %options) = @_; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $meth_obj; |
25
|
|
|
|
|
|
|
$meth_obj = $method->$wrap |
26
|
|
|
|
|
|
|
( |
27
|
|
|
|
|
|
|
sub { |
28
|
9
|
|
|
9
|
|
4346
|
my ($self) = @_; |
|
|
|
|
9
|
|
|
|
29
|
9
|
|
|
|
|
278
|
$meth_obj->schema->($self)->txn_do($code, @_); |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
%options |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
return $meth_obj; |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
1; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
__END__ |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 NAME |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
MooseX::Meta::Method::Transactional - Transactional methods trait |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
This Role wraps methods in transactions to be used with DBIx::Class, |
47
|
|
|
|
|
|
|
KiokuDB or any other object providing a txn_do method. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 METHOD |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=over |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item wrap |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This role overrides wrap so that the actual method is wrapped in a |
56
|
|
|
|
|
|
|
txn_do call. It uses the 'schema' accessor to obtain the object in |
57
|
|
|
|
|
|
|
which it will call txn_do. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=back |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=over |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item schema |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
This attribute contains a CodeRef that should return the schema |
68
|
|
|
|
|
|
|
object. It can be used to pass a schema object when it can be defined |
69
|
|
|
|
|
|
|
in compile-time, otherwise it will call "schema" on the object |
70
|
|
|
|
|
|
|
instance to find it. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=back |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 SEE ALSO |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
L<MooseX::TransactionalMethods>, L<Class::MOP::Method> |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 AUTHORS |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Daniel Ruoso E<lt>daniel@ruoso.comE<gt> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
With help from rafl and doy from #moose. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Copyright 2010 by Daniel Ruoso et al |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
89
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |