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