line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::Session::Store::Memcached; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1492
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
21
|
use base 'MojoX::Session::Store'; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
276
|
|
7
|
1
|
|
|
1
|
|
5
|
use Cache::Memcached; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
264
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->attr('memcached_connector'); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
1
|
|
|
1
|
|
544
|
my($class,$param)=@_; |
15
|
1
|
|
|
|
|
39
|
my $self = $class->SUPER::new(); |
16
|
0
|
|
|
|
|
|
bless $self,$class; |
17
|
|
|
|
|
|
|
|
18
|
0
|
0
|
|
|
|
|
if( ref $param->{servers} ne 'ARRAY' ){ |
19
|
0
|
|
|
|
|
|
$param->{servers} = [$param->{servers}]; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
$self->memcached_connector(Cache::Memcached->new($param)); |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub create { |
28
|
0
|
|
|
0
|
|
|
my ($self, $sid, $expires, $data) = @_; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $new_data = { |
31
|
|
|
|
|
|
|
data => $data, |
32
|
|
|
|
|
|
|
expires => $expires |
33
|
|
|
|
|
|
|
}; |
34
|
0
|
|
|
|
|
|
my $res = $self->{memcached_connector}->set($sid,$new_data); |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
return $res; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub update { |
40
|
0
|
|
|
0
|
|
|
my ($self, $sid, $expires, $data) = @_; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $new_data = { |
43
|
|
|
|
|
|
|
data => $data, |
44
|
|
|
|
|
|
|
expires => $expires |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $res = $self->{memcached_connector}->replace($sid,$new_data); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
return $res; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub load { |
53
|
0
|
|
|
0
|
|
|
my ($self, $sid) = @_; |
54
|
0
|
|
|
|
|
|
my $memd = $self->{memcached_connector}; |
55
|
0
|
|
|
|
|
|
my $res = $memd->get($sid); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
return ($res->{expires},$res->{data}); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub delete { |
61
|
0
|
|
|
0
|
|
|
my ($self, $sid) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $res = $self->{memcached_connector}->delete($sid); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
__END__ |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 NAME |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
MojoX::Session::Store::Memcached - Memcached Store for MojoX::Session |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 SYNOPSIS |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $session = MojoX::Session->new( |
78
|
|
|
|
|
|
|
tx => $tx, |
79
|
|
|
|
|
|
|
# all params as for Cache::Memcached |
80
|
|
|
|
|
|
|
store => MojoX::Session::Store::Memcached->new({ |
81
|
|
|
|
|
|
|
servers => [127.0.0.1:11211] |
82
|
|
|
|
|
|
|
}), |
83
|
|
|
|
|
|
|
transport => MojoX::Session::Transport::Cookie->new, |
84
|
|
|
|
|
|
|
ip_match => 1 |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# see doc for MojoX::Session |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 DESCRIPTION |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
L<MojoX::Session::Store::Memcached> is a store for L<MojoX::Session> that stores a |
92
|
|
|
|
|
|
|
session in a memcached daemon . |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
L<MojoX::Session::Store::Memcached> implements the following attributes. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 C<memcached_connector> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $memcached_connector = $store->memcached_connector; |
101
|
|
|
|
|
|
|
$store = $store->memcached_connector($memcached_connector); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Get and set memcached handler. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 METHODS |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
L<MojoX::Session::Store::Memcached> inherits all methods from |
108
|
|
|
|
|
|
|
L<MojoX::Session::Store>. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 C<create> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Insert session to memcached. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 C<update> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Update session in memcached. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 C<load> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Load session from memcached. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 C<delete> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Delete session from memcached. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 AUTHOR |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Harper, C<plcgi1 at gmail.com>. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 COPYRIGHT |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Copyright (C) 2009, Harper. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under |
135
|
|
|
|
|
|
|
the same terms as Perl 5.10. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
|