line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
32689
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
3
|
1
|
|
|
1
|
|
933
|
use utf8; |
|
1
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Amon2::Setup::Flavor::Teng; |
6
|
1
|
|
|
1
|
|
920
|
use parent qw(Amon2::Setup::Flavor); |
|
1
|
|
|
|
|
311
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub run { |
10
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
|
|
|
|
$self->write_file('lib/<>.pm', <<'...'); |
13
|
|
|
|
|
|
|
package <% $module %>; |
14
|
|
|
|
|
|
|
use strict; |
15
|
|
|
|
|
|
|
use warnings; |
16
|
|
|
|
|
|
|
use utf8; |
17
|
|
|
|
|
|
|
use parent qw/Amon2/; |
18
|
|
|
|
|
|
|
use 5.008001; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
__PACKAGE__->load_plugin(qw/DBI/); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# initialize database |
23
|
|
|
|
|
|
|
use DBI; |
24
|
|
|
|
|
|
|
sub setup_schema { |
25
|
|
|
|
|
|
|
my $self = shift; |
26
|
|
|
|
|
|
|
my $dbh = $self->dbh(); |
27
|
|
|
|
|
|
|
my $driver_name = $dbh->{Driver}->{Name}; |
28
|
|
|
|
|
|
|
my $fname = lc("sql/${driver_name}.sql"); |
29
|
|
|
|
|
|
|
open my $fh, '<:encoding(UTF-8)', $fname or die "$fname: $!"; |
30
|
|
|
|
|
|
|
my $source = do { local $/; <$fh> }; |
31
|
|
|
|
|
|
|
for my $stmt (split /;/, $source) { |
32
|
|
|
|
|
|
|
next unless $stmt =~ /\S/; |
33
|
|
|
|
|
|
|
$dbh->do($stmt) or die $dbh->errstr(); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
use Teng; |
38
|
|
|
|
|
|
|
use Teng::Schema::Loader; |
39
|
|
|
|
|
|
|
use <% $module %>::DB; |
40
|
|
|
|
|
|
|
my $schema; |
41
|
|
|
|
|
|
|
sub db { |
42
|
|
|
|
|
|
|
my $self = shift; |
43
|
|
|
|
|
|
|
if ( !defined $self->{db} ) { |
44
|
|
|
|
|
|
|
my $conf = $self->config->{'DBI'} |
45
|
|
|
|
|
|
|
or die "missing configuration for 'DBI'"; |
46
|
|
|
|
|
|
|
my $dbh = DBI->connect(@{$conf}); |
47
|
|
|
|
|
|
|
if ( !defined $schema ) { |
48
|
|
|
|
|
|
|
$self->{db} = Teng::Schema::Loader->load( |
49
|
|
|
|
|
|
|
namespace => '<% $module %>::DB', |
50
|
|
|
|
|
|
|
dbh => $dbh, |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
$schema = $self->{db}->schema; |
53
|
|
|
|
|
|
|
} else { |
54
|
|
|
|
|
|
|
$self->{db} = <% $module %>::DB->new( |
55
|
|
|
|
|
|
|
dbh => $dbh, |
56
|
|
|
|
|
|
|
schema => $schema, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
return $self->{db}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
... |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$self->write_file('lib/<>/DB.pm', <<'...'); |
67
|
|
|
|
|
|
|
package <% $module %>::DB; |
68
|
|
|
|
|
|
|
use strict; |
69
|
|
|
|
|
|
|
use warnings; |
70
|
|
|
|
|
|
|
use utf8; |
71
|
|
|
|
|
|
|
use parent qw(Teng); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
... |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$self->write_file('t/08_teng.t', <<'...'); |
77
|
|
|
|
|
|
|
use strict; |
78
|
|
|
|
|
|
|
use warnings; |
79
|
|
|
|
|
|
|
use DBI; |
80
|
|
|
|
|
|
|
use Test::More; |
81
|
|
|
|
|
|
|
use <% $module %>; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $dbi = DBI->connect('dbi:SQLite:dbname=db/development.db'); |
84
|
|
|
|
|
|
|
$dbi->do("create table if not exists sessions (id char(72) primary key, session_data text)") or die $dbi->errstr; |
85
|
|
|
|
|
|
|
my $teng = <% $module %>->new; |
86
|
|
|
|
|
|
|
is(ref $teng, '<% $module %>', 'instance'); |
87
|
|
|
|
|
|
|
isa_ok($teng->db, 'Teng', 'instance'); |
88
|
|
|
|
|
|
|
isa_ok($teng->db, '<% $module %>::DB', 'instance'); |
89
|
|
|
|
|
|
|
$teng->db->insert('sessions', { id => 'abcdefghijklmnopqrstuvwxyz', session_data => 'ka2u' }); |
90
|
|
|
|
|
|
|
my $res = $teng->db->single('sessions', { id => 'abcdefghijklmnopqrstuvwxyz' }); |
91
|
|
|
|
|
|
|
is($res->get_column('session_data'), 'ka2u', 'search'); |
92
|
|
|
|
|
|
|
$teng->db->delete('sessions', {id => 'abcdefghijklmnopqrstuvwxyz'}); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
done_testing; |
95
|
|
|
|
|
|
|
... |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |