| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Dancer2::Plugin::SessionDatabase; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1034488
|
use Modern::Perl; |
|
|
2
|
|
|
|
|
12
|
|
|
|
2
|
|
|
|
|
19
|
|
|
4
|
2
|
|
|
2
|
|
983
|
use Dancer2::Plugin; |
|
|
2
|
|
|
|
|
299497
|
|
|
|
2
|
|
|
|
|
22
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
56509
|
use Carp qw(croak); |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
123
|
|
|
7
|
2
|
|
|
2
|
|
834
|
use Data::Dumper; |
|
|
2
|
|
|
|
|
7739
|
|
|
|
2
|
|
|
|
|
1280
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Dancer2::Plugin::SessionDatabase - Hook Loader For Dancer2::Session::DatabasePlugin |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Hook loader for Dancer2::Session::DatabasePlugin. |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head2 Plugin options |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
In your config.yml |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
plugins: |
|
23
|
|
|
|
|
|
|
SessionDatabase: |
|
24
|
|
|
|
|
|
|
# when set to true this forces a call to the database plugin |
|
25
|
|
|
|
|
|
|
always_clean: 1 |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has always_clean=>( |
|
31
|
|
|
|
|
|
|
is=>'rw', |
|
32
|
|
|
|
|
|
|
default=>sub { 1 }, |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
our $DBH; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub reset_session { |
|
38
|
0
|
|
|
0
|
0
|
0
|
%{$Dancer2::Session::DatabasePlugin::CACHE}=(); |
|
|
0
|
|
|
|
|
0
|
|
|
39
|
0
|
|
|
|
|
0
|
$DBH=undef; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub DBC { |
|
43
|
0
|
|
|
0
|
0
|
0
|
my ($self,$conn)=@_; |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
0
|
if($self->always_clean) { |
|
46
|
0
|
|
|
|
|
0
|
$self->reset_session; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
0
|
|
|
|
|
0
|
my $db=$self->find_plugin('Dancer2::Plugin::Database'); |
|
49
|
0
|
|
|
|
|
0
|
my $dbh=$db->database($conn); |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
0
|
0
|
|
|
0
|
if(defined($DBH) && $dbh ne $DBH) { |
|
52
|
0
|
|
|
|
|
0
|
%{$Dancer2::Session::DatabasePlugin::CACHE}=(); |
|
|
0
|
|
|
|
|
0
|
|
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
return $DBH=$dbh; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# This method runs after the new constructor |
|
59
|
|
|
|
|
|
|
sub BUILD { |
|
60
|
1
|
|
|
1
|
0
|
77
|
my ($self)=@_; |
|
61
|
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
3
|
while(my ($method,$value)=each %{$self->config}) { |
|
|
1
|
|
|
|
|
21
|
|
|
63
|
0
|
|
|
|
|
0
|
$self->$method($value); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$self->app->add_hook( |
|
67
|
|
|
|
|
|
|
Dancer2::Core::Hook->new( |
|
68
|
|
|
|
|
|
|
name=>"engine.session.before_db", |
|
69
|
|
|
|
|
|
|
code=>sub { |
|
70
|
0
|
|
|
0
|
|
0
|
my ($session)=@_; |
|
71
|
0
|
|
|
|
|
0
|
my $dbh=$self->DBC($session->connection); |
|
72
|
0
|
|
|
|
|
0
|
$session->dbh($dbh); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
) |
|
75
|
1
|
|
|
|
|
81
|
); |
|
76
|
|
|
|
|
|
|
$self->app->add_hook( |
|
77
|
|
|
|
|
|
|
Dancer2::Core::Hook->new( |
|
78
|
|
|
|
|
|
|
name=>"database_connection_lost", |
|
79
|
|
|
|
|
|
|
code=>sub { |
|
80
|
0
|
|
|
0
|
|
0
|
my ($dbh)=@_; |
|
81
|
0
|
|
|
|
|
0
|
$self->reset_session; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
) |
|
84
|
1
|
|
|
|
|
127869
|
); |
|
85
|
|
|
|
|
|
|
$self->app->add_hook( |
|
86
|
|
|
|
|
|
|
Dancer2::Core::Hook->new( |
|
87
|
|
|
|
|
|
|
name=>"database_error", |
|
88
|
|
|
|
|
|
|
code=>sub { |
|
89
|
0
|
|
|
0
|
|
|
my ($err,$dbh)=@_; |
|
90
|
0
|
|
|
|
|
|
$self->reset_session; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
) |
|
93
|
1
|
|
|
|
|
619
|
); |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 AUTHOR |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Michael Shipper AKALINUX@CPAN.ORG |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |