line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Starch::Store::DBIx::Connector; |
2
|
1
|
|
|
1
|
|
13149
|
use 5.008001; |
|
1
|
|
|
|
|
3
|
|
3
|
1
|
|
|
1
|
|
7
|
use strictures 2; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
43
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Starch::Store::DBIx::Connector - Starch storage backend using DBIx::Connector. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $starch = Starch->new( |
13
|
|
|
|
|
|
|
store => { |
14
|
|
|
|
|
|
|
class => '::DBIx::Connector', |
15
|
|
|
|
|
|
|
connector => [ |
16
|
|
|
|
|
|
|
$dsn, |
17
|
|
|
|
|
|
|
$username, |
18
|
|
|
|
|
|
|
$password, |
19
|
|
|
|
|
|
|
{ RaiseError=>1, AutoCommit=>1 }, |
20
|
|
|
|
|
|
|
], |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
This L store uses L to set and get state data. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
The table in your database should contain three columns. This |
29
|
|
|
|
|
|
|
is the SQLite syntax for creating a compatible table which you |
30
|
|
|
|
|
|
|
can modify to work for your particular database's syntax: |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
CREATE TABLE starch_states ( |
33
|
|
|
|
|
|
|
key TEXT NOT NULL PRIMARY KEY, |
34
|
|
|
|
|
|
|
data TEXT NOT NULL, |
35
|
|
|
|
|
|
|
expiration INTEGER NOT NULL |
36
|
|
|
|
|
|
|
) |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
1
|
|
806
|
use DBIx::Connector; |
|
1
|
|
|
|
|
22796
|
|
|
1
|
|
|
|
|
38
|
|
41
|
1
|
|
|
1
|
|
10
|
use Types::Standard -types; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
17
|
|
42
|
1
|
|
|
1
|
|
4868
|
use Types::Common::String -types; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
43
|
1
|
|
|
1
|
|
1445
|
use Scalar::Util qw( blessed ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
57
|
|
44
|
1
|
|
|
1
|
|
449
|
use Data::Serializer::Raw; |
|
1
|
|
|
|
|
826
|
|
|
1
|
|
|
|
|
34
|
|
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
1
|
|
9
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
47
|
1
|
|
|
1
|
|
510
|
use namespace::clean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
with qw( |
50
|
|
|
|
|
|
|
Starch::Store |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
after BUILD => sub{ |
54
|
|
|
|
|
|
|
my ($self) = @_; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Get this loaded as early as possible. |
57
|
|
|
|
|
|
|
$self->connector(); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
return; |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 REQUIRED ARGUMENTS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 connector |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This must be set to either an array ref arguments for L |
67
|
|
|
|
|
|
|
or a pre-built object (often retrieved using a method proxy). |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
When configuring Starch from static configuration files using a |
70
|
|
|
|
|
|
|
L |
71
|
|
|
|
|
|
|
is a good way to link your existing L object |
72
|
|
|
|
|
|
|
constructor in with Starch so that starch doesn't build its own. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
has _connector_arg => ( |
77
|
|
|
|
|
|
|
is => 'ro', |
78
|
|
|
|
|
|
|
isa => (InstanceOf[ 'DBIx::Connector' ]) | ArrayRef, |
79
|
|
|
|
|
|
|
init_arg => 'connector', |
80
|
|
|
|
|
|
|
required => 1, |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
has connector => ( |
84
|
|
|
|
|
|
|
is => 'lazy', |
85
|
|
|
|
|
|
|
isa => InstanceOf[ 'DBIx::Connector' ], |
86
|
|
|
|
|
|
|
init_arg => undef, |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
sub _build_connector { |
89
|
6
|
|
|
6
|
|
75
|
my ($self) = @_; |
90
|
|
|
|
|
|
|
|
91
|
6
|
|
|
|
|
25
|
my $connector = $self->_connector_arg(); |
92
|
6
|
50
|
|
|
|
34
|
return $connector if blessed $connector; |
93
|
|
|
|
|
|
|
|
94
|
6
|
|
|
|
|
48
|
return DBIx::Connector->new( @$connector ); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 OPTIONAL ARGUMENTS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 serializer |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
A L for serializing the state data for storage |
102
|
|
|
|
|
|
|
in the L. Can be specified as string containing the |
103
|
|
|
|
|
|
|
serializer name, a hash ref of Data::Serializer::Raw arguments, or as a |
104
|
|
|
|
|
|
|
pre-created Data::Serializer::Raw object. Defaults to C. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Consider using the C or C serializers for speed. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
C will likely be the fastest and produce the most compact data. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
has _serializer_arg => ( |
113
|
|
|
|
|
|
|
is => 'ro', |
114
|
|
|
|
|
|
|
isa => ((InstanceOf[ 'Data::Serializer::Raw' ]) | HashRef) | NonEmptySimpleStr, |
115
|
|
|
|
|
|
|
init_arg => 'serializer', |
116
|
|
|
|
|
|
|
default => 'JSON', |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
has serializer => ( |
120
|
|
|
|
|
|
|
is => 'lazy', |
121
|
|
|
|
|
|
|
isa => InstanceOf[ 'Data::Serializer::Raw' ], |
122
|
|
|
|
|
|
|
init_arg => undef, |
123
|
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
sub _build_serializer { |
125
|
3
|
|
|
3
|
|
42
|
my ($self) = @_; |
126
|
|
|
|
|
|
|
|
127
|
3
|
|
|
|
|
21
|
my $serializer = $self->_serializer_arg(); |
128
|
3
|
50
|
|
|
|
18
|
return $serializer if blessed $serializer; |
129
|
|
|
|
|
|
|
|
130
|
3
|
50
|
|
|
|
11
|
if (ref $serializer) { |
131
|
0
|
|
|
|
|
0
|
return Data::Serializer::Raw->new( %$serializer ); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
3
|
|
|
|
|
32
|
return Data::Serializer::Raw->new( |
135
|
|
|
|
|
|
|
serializer => $serializer, |
136
|
|
|
|
|
|
|
); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 method |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
The L method to call when executing queries. |
142
|
|
|
|
|
|
|
Must be one of C, C, or C. Defaults to C. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
has method => ( |
147
|
|
|
|
|
|
|
is => 'ro', |
148
|
|
|
|
|
|
|
isa => Enum['run', 'txn', 'svp'], |
149
|
|
|
|
|
|
|
default => 'run', |
150
|
|
|
|
|
|
|
); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 mode |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
The L to use |
155
|
|
|
|
|
|
|
when running the L. Defaults to C which lets |
156
|
|
|
|
|
|
|
L use whichever mode it has been configured to use. |
157
|
|
|
|
|
|
|
Must be on of C, C, C, or C. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Typically you will not want to set this as you will have provided |
160
|
|
|
|
|
|
|
a pre-built L object, using a method proxy, which |
161
|
|
|
|
|
|
|
you've already called L on. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
has mode => ( |
166
|
|
|
|
|
|
|
is => 'ro', |
167
|
|
|
|
|
|
|
isa => (Enum['ping', 'fixup', 'no_ping']) | Undef, |
168
|
|
|
|
|
|
|
); |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 table |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
The table name where states are stored in the database. |
173
|
|
|
|
|
|
|
Defaults to C. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
has table => ( |
178
|
|
|
|
|
|
|
is => 'ro', |
179
|
|
|
|
|
|
|
isa => NonEmptySimpleStr, |
180
|
|
|
|
|
|
|
default => 'starch_states', |
181
|
|
|
|
|
|
|
); |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head2 key_column |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
The column in the L |
where the state ID is stored.