| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
2
|
|
|
2
|
|
728725
|
use strictures 2; |
|
|
2
|
|
|
|
|
17
|
|
|
|
2
|
|
|
|
|
96
|
|
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Dancer2::Plugin::Shutdown::Redis; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Graceful shutdown your Dancer2 application with Redis propagation |
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
1235
|
use Dancer2::Plugin; |
|
|
2
|
|
|
|
|
3681
|
|
|
|
2
|
|
|
|
|
11
|
|
|
8
|
2
|
|
|
2
|
|
2481
|
use Scalar::Util qw(blessed); |
|
|
2
|
|
|
|
|
8
|
|
|
|
2
|
|
|
|
|
95
|
|
|
9
|
2
|
|
|
2
|
|
1210
|
use Redis; |
|
|
2
|
|
|
|
|
40907
|
|
|
|
2
|
|
|
|
|
56
|
|
|
10
|
2
|
|
|
2
|
|
12
|
use Carp qw(croak); |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
100
|
|
|
11
|
2
|
|
|
2
|
|
836
|
use Tie::Redis::Candy 1.001 qw(redis_hash); |
|
|
2
|
|
|
|
|
7461
|
|
|
|
2
|
|
|
|
|
604
|
|
|
12
|
|
|
|
|
|
|
with 'Dancer2::Plugin::Role::Shutdown'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has _redis => ( |
|
17
|
|
|
|
|
|
|
is => 'rw', |
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _shutdown_redis { |
|
21
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
22
|
0
|
0
|
|
|
|
|
return $self->_redis unless @_; |
|
23
|
0
|
|
|
|
|
|
my ($redis, $key) = @_; |
|
24
|
0
|
0
|
|
|
|
|
croak "you have specify a key" unless $key; |
|
25
|
0
|
0
|
0
|
|
|
|
if (blessed $redis and ($redis->isa('Redis') or $redis->isa('Test::Mock::Redis'))) { |
|
|
|
0
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
$self->_redis($redis); |
|
27
|
|
|
|
|
|
|
} elsif (defined $redis and not ref $redis) { |
|
28
|
0
|
|
|
|
|
|
$self->_redis(Redis->new(server => $redis)); |
|
29
|
|
|
|
|
|
|
} else { |
|
30
|
0
|
|
|
|
|
|
croak("Not a Redis instance: $redis"); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
0
|
|
|
|
|
|
my $shared = redis_hash($self->_redis, $key, %{ $self->shared }); |
|
|
0
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
$self->_set_shared($shared); |
|
34
|
0
|
|
|
|
|
|
return $self->_redis; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
register shutdown_at => \&_shutdown_at; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
register shutdown_session_validator => sub { |
|
42
|
|
|
|
|
|
|
shift->validator(@_) |
|
43
|
|
|
|
|
|
|
}, { is_global => 1 }; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
register shutdown_redis => sub { |
|
47
|
|
|
|
|
|
|
shift->_shutdown_redis(@_) |
|
48
|
|
|
|
|
|
|
}, { is_global => 1 }; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
on_plugin_import { |
|
51
|
|
|
|
|
|
|
my $self = shift; |
|
52
|
|
|
|
|
|
|
$self->app->add_hook( |
|
53
|
|
|
|
|
|
|
Dancer2::Core::Hook->new( |
|
54
|
|
|
|
|
|
|
name => 'before', |
|
55
|
|
|
|
|
|
|
code => sub { $self->before_hook(@_) }, |
|
56
|
|
|
|
|
|
|
) |
|
57
|
|
|
|
|
|
|
); |
|
58
|
|
|
|
|
|
|
}; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
register_plugin; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |