| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojo::Hakkefuin::Test::Backend; |
|
2
|
4
|
|
|
4
|
|
473609
|
use Mojo::Base 'Mojo::Hakkefuin::Backend'; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
46
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
348
|
use Carp 'croak'; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
2654
|
|
|
5
|
4
|
|
|
4
|
|
2280
|
use Mojo::Loader 'load_class'; |
|
|
4
|
|
|
|
|
962808
|
|
|
|
4
|
|
|
|
|
320
|
|
|
6
|
4
|
|
|
4
|
|
3665
|
use CellBIS::Random; |
|
|
4
|
|
|
|
|
77060
|
|
|
|
4
|
|
|
|
|
3592
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Attribute |
|
9
|
|
|
|
|
|
|
has 'via'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Internal Attributes : |
|
12
|
|
|
|
|
|
|
has 'backend'; |
|
13
|
|
|
|
|
|
|
has crand => sub { state $cr = CellBIS::Random->new }; |
|
14
|
|
|
|
|
|
|
has utils => sub { |
|
15
|
|
|
|
|
|
|
state $utils = Mojo::Hakkefuin::Utils->new(random => 'String::Random'); |
|
16
|
|
|
|
|
|
|
}; |
|
17
|
|
|
|
|
|
|
has cookies => sub { |
|
18
|
|
|
|
|
|
|
state $cookies = Mojolicious::Plugin::Hakkefuin::_cookies->new( |
|
19
|
|
|
|
|
|
|
utils => shift->utils, |
|
20
|
|
|
|
|
|
|
random => 'String::Random' |
|
21
|
|
|
|
|
|
|
); |
|
22
|
|
|
|
|
|
|
}; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new { |
|
25
|
2
|
|
|
2
|
1
|
477280
|
my $self = shift->SUPER::new(@_); |
|
26
|
|
|
|
|
|
|
|
|
27
|
2
|
|
50
|
|
|
38
|
$self->{via} //= 'sqlite'; |
|
28
|
2
|
|
50
|
|
|
9
|
$self->{dir} //= 'migrations'; |
|
29
|
2
|
50
|
|
|
|
11
|
$self->via('mariadb') if $self->via eq 'mysql'; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Params for backend |
|
32
|
2
|
|
|
|
|
17
|
my @param; |
|
33
|
2
|
50
|
|
|
|
7
|
push @param, dir => $self->dir if $self->via eq 'sqlite'; |
|
34
|
2
|
50
|
|
|
|
35
|
push @param, dsn => $self->dsn if $self->dsn; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Load class backend |
|
37
|
2
|
|
|
|
|
13
|
my $class = 'Mojo::Hakkefuin::Backend::' . $self->via; |
|
38
|
2
|
|
|
|
|
17
|
my $load = load_class $class; |
|
39
|
2
|
0
|
|
|
|
67
|
croak ref $load ? $load : qq{Backend "$class" missing} if $load; |
|
|
|
50
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
13
|
$self->backend($class->new(@param)); |
|
41
|
2
|
|
|
|
|
33
|
$self->crand(CellBIS::Random->new); |
|
42
|
|
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
42
|
return $self; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub load_backend { |
|
47
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
0
|
|
|
0
|
$self->{via} //= 'sqlite'; |
|
50
|
0
|
0
|
|
|
|
0
|
$self->via('mariadb') if $self->via eq 'mysql'; |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Params for backend |
|
53
|
0
|
|
|
|
|
0
|
my @param = (dir => $self->dir); |
|
54
|
0
|
0
|
|
|
|
0
|
push @param, dsn => $self->dsn if $self->dsn; |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
my $class = 'Mojo::Hakkefuin::Backend::' . $self->via; |
|
57
|
0
|
|
|
|
|
0
|
my $load = load_class $class; |
|
58
|
0
|
0
|
|
|
|
0
|
croak ref $load ? $load : qq{Backend "$class" missing} if $load; |
|
|
|
0
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
$self->backend($class->new(@param)); |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
return $self; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub example_data { |
|
65
|
4
|
|
|
4
|
1
|
2057
|
my ($self, $identify) = @_; |
|
66
|
|
|
|
|
|
|
|
|
67
|
4
|
|
|
|
|
21
|
my $cook = $self->utils->gen_cookie(3); |
|
68
|
4
|
|
|
|
|
1087
|
my $csrf = $self->crand->random($cook, 2, 3); |
|
69
|
|
|
|
|
|
|
|
|
70
|
4
|
|
|
|
|
8045
|
my $cookie_val |
|
71
|
|
|
|
|
|
|
= Mojo::Util::hmac_sha1_sum($self->utils->gen_cookie(5), $csrf); |
|
72
|
|
|
|
|
|
|
|
|
73
|
4
|
|
|
|
|
1421
|
return [$identify, $cookie_val, $csrf]; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=encoding utf8 |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 NAME |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Mojo::Hakkefuin::Test::Backend - A part of Unit Testing |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
use Mojo::Hakkefuin::Test::Backend |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Initialization for SQLite |
|
89
|
|
|
|
|
|
|
my $btest = Mojo::Hakkefuin::Test::Backend->new( |
|
90
|
|
|
|
|
|
|
via => 'sqlite', |
|
91
|
|
|
|
|
|
|
dir => '/home/user/mojo/app/t/path', |
|
92
|
|
|
|
|
|
|
); |
|
93
|
|
|
|
|
|
|
$backend = $btest->backend; |
|
94
|
|
|
|
|
|
|
$db = $backend->sqlite->db; |
|
95
|
|
|
|
|
|
|
ok $db->ping, 'SQLite connected'; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# Initialization for MariaDB/MySQL |
|
98
|
|
|
|
|
|
|
my $btest = Mojo::Hakkefuin::Test::Backend->new( |
|
99
|
|
|
|
|
|
|
via => 'mariadb', |
|
100
|
|
|
|
|
|
|
dir => 'migrations', |
|
101
|
|
|
|
|
|
|
dsn => 'mariadb://username:password@hostname/database' |
|
102
|
|
|
|
|
|
|
); |
|
103
|
|
|
|
|
|
|
my $btest = Mojo::Hakkefuin::Test::Backend->new( |
|
104
|
|
|
|
|
|
|
via => 'mysql', |
|
105
|
|
|
|
|
|
|
dir => 'migrations', |
|
106
|
|
|
|
|
|
|
dsn => 'mysql://username:password@hostname/database' |
|
107
|
|
|
|
|
|
|
); |
|
108
|
|
|
|
|
|
|
$backend = $btest->backend; |
|
109
|
|
|
|
|
|
|
$db = $backend->mariadb->db; |
|
110
|
|
|
|
|
|
|
ok $db->ping, 'MariaDB connected'; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Initialization for PostgreSQL |
|
113
|
|
|
|
|
|
|
my $btest = Mojo::Hakkefuin::Test::Backend->new( |
|
114
|
|
|
|
|
|
|
via => 'pg', |
|
115
|
|
|
|
|
|
|
dir => 'migrations', |
|
116
|
|
|
|
|
|
|
dsn => 'postgresql://username:password@hostname/database' |
|
117
|
|
|
|
|
|
|
); |
|
118
|
|
|
|
|
|
|
$backend = $btest->backend; |
|
119
|
|
|
|
|
|
|
$db = $backend->pg->db; |
|
120
|
|
|
|
|
|
|
ok $db->ping, 'PostgreSQL connected'; |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# Switch from another Backend |
|
123
|
|
|
|
|
|
|
my $btest = Mojo::Hakkefuin::Test::Backend->new( |
|
124
|
|
|
|
|
|
|
via => 'sqlite', |
|
125
|
|
|
|
|
|
|
dir => '/home/user/mojo/app/t/path', |
|
126
|
|
|
|
|
|
|
); |
|
127
|
|
|
|
|
|
|
$backend = $btest->backend; |
|
128
|
|
|
|
|
|
|
$db = $backend->sqlite->db; |
|
129
|
|
|
|
|
|
|
ok $db->ping, 'SQLite connected'; |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
$btest->via('mysql'); |
|
132
|
|
|
|
|
|
|
$btest->dsn('mariadb://username:password@hostname/database'); |
|
133
|
|
|
|
|
|
|
$btest->load_backend; |
|
134
|
|
|
|
|
|
|
$backend = $btest->backend; |
|
135
|
|
|
|
|
|
|
$db = $backend->mariadb->db; |
|
136
|
|
|
|
|
|
|
ok $db->ping, 'MariaDB connected'; |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
$btest->via('mariadb'); |
|
139
|
|
|
|
|
|
|
$btest->dsn('mariadb://username:password@hostname/database'); |
|
140
|
|
|
|
|
|
|
$btest->load_backend; |
|
141
|
|
|
|
|
|
|
$backend = $btest->backend; |
|
142
|
|
|
|
|
|
|
$db = $backend->mariadb->db; |
|
143
|
|
|
|
|
|
|
ok $db->ping, 'MariaDB connected'; |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
$btest->via('pg'); |
|
146
|
|
|
|
|
|
|
$btest->dsn('postgresql://username:password@hostname/database'); |
|
147
|
|
|
|
|
|
|
$btest->load_backend; |
|
148
|
|
|
|
|
|
|
$backend = $btest->backend; |
|
149
|
|
|
|
|
|
|
$db = $backend->pg->db; |
|
150
|
|
|
|
|
|
|
ok $db->ping, 'PostgreSQL connected'; |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
This module is only for unit testing purposes to test each backend. |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L inherits all attributes |
|
159
|
|
|
|
|
|
|
from L and implements the following new ones. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 via |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# When initialization Module - Use SQLite |
|
164
|
|
|
|
|
|
|
my $btest = Mojo::Hakkefuin::Test::Backend->new( |
|
165
|
|
|
|
|
|
|
.... |
|
166
|
|
|
|
|
|
|
via => 'sqlite', |
|
167
|
|
|
|
|
|
|
... |
|
168
|
|
|
|
|
|
|
); |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# When initialization Module - Use MariaDB/MySQL |
|
171
|
|
|
|
|
|
|
my $btest = Mojo::Hakkefuin::Test::Backend->new( |
|
172
|
|
|
|
|
|
|
.... |
|
173
|
|
|
|
|
|
|
via => 'mariadb', |
|
174
|
|
|
|
|
|
|
... |
|
175
|
|
|
|
|
|
|
); |
|
176
|
|
|
|
|
|
|
# or |
|
177
|
|
|
|
|
|
|
my $btest = Mojo::Hakkefuin::Test::Backend->new( |
|
178
|
|
|
|
|
|
|
.... |
|
179
|
|
|
|
|
|
|
via => 'mysql', |
|
180
|
|
|
|
|
|
|
... |
|
181
|
|
|
|
|
|
|
); |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# When initialization Module - Use PostgreSQL |
|
184
|
|
|
|
|
|
|
my $btest = Mojo::Hakkefuin::Test::Backend->new( |
|
185
|
|
|
|
|
|
|
.... |
|
186
|
|
|
|
|
|
|
via => 'pg', |
|
187
|
|
|
|
|
|
|
... |
|
188
|
|
|
|
|
|
|
); |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
# use as a method |
|
191
|
|
|
|
|
|
|
$btest->via; |
|
192
|
|
|
|
|
|
|
$btest->via('sqlite'); |
|
193
|
|
|
|
|
|
|
$btest->via('mariadb'); |
|
194
|
|
|
|
|
|
|
$btest->via('mysql'); |
|
195
|
|
|
|
|
|
|
$btest->via('pg'); |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Specify of backend via MariaDB/MySQL or SQLite or PostgreSQL. |
|
198
|
|
|
|
|
|
|
This attribute by default contains . |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head2 dir |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# Example use as a config |
|
203
|
|
|
|
|
|
|
my $backend = Mojo::Hakkefuin::Backend::mariadb->new( |
|
204
|
|
|
|
|
|
|
... |
|
205
|
|
|
|
|
|
|
dir => '/home/user/mojo/app/path/', |
|
206
|
|
|
|
|
|
|
... |
|
207
|
|
|
|
|
|
|
); |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
# use as a method |
|
210
|
|
|
|
|
|
|
my $backend = $backend->dir; |
|
211
|
|
|
|
|
|
|
$backend->dir('/home/user/mojo/app/path/'); |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head1 METHODS |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
L inherits all methods from |
|
216
|
|
|
|
|
|
|
L and implements the following new ones. |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head2 load_backend |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
$btest->load_backend; |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
This method will be used after changing the backend using |
|
223
|
|
|
|
|
|
|
the "via" attribute. |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head2 example_data |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
$btest->example_data($identify); |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
To generate example data Cookies and CSRF hash. |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head2 new |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
my $btest = Mojo::Hakkefuin::Test::Backend->new(\%attr); |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Construct a new L object either from L. |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head1 AUTHOR |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Achmad Yusri Afandi, C |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
Copyright (C) 2023 by Achmad Yusri Afandi |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify |
|
246
|
|
|
|
|
|
|
it under the terms of the Artistic License version 2.0. |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=cut |