line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Apache::Session::Store::MongoDB; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
18
|
use 5.010; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.21'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
557
|
use MongoDB; |
|
1
|
|
|
|
|
1718624
|
|
|
1
|
|
|
|
|
529
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $default = { |
11
|
|
|
|
|
|
|
host => 'localhost:27017', |
12
|
|
|
|
|
|
|
db_name => 'sessions', |
13
|
|
|
|
|
|
|
collection => 'sessions', |
14
|
|
|
|
|
|
|
}; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
return bless {}, $class; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub connection { |
23
|
0
|
|
|
0
|
0
|
|
my ( $self, $session ) = splice @_; |
24
|
|
|
|
|
|
|
return |
25
|
0
|
0
|
|
|
|
|
if ( defined $self->{collection} ); |
26
|
0
|
|
|
|
|
|
my $conn_args; |
27
|
0
|
|
|
|
|
|
foreach my $w ( |
28
|
|
|
|
|
|
|
qw(host auth_mechanism auth_mechanism_properties bson_codec |
29
|
|
|
|
|
|
|
connect_timeout_ms db_name heartbeat_frequency_ms j local_threshold_ms |
30
|
|
|
|
|
|
|
max_time_ms password port read_pref_mode read_pref_tag_sets |
31
|
|
|
|
|
|
|
replica_set_name server_selection_timeout_ms server_selection_try_once |
32
|
|
|
|
|
|
|
socket_check_interval_ms socket_timeout_ms ssl username w wtimeout |
33
|
|
|
|
|
|
|
read_concern_level) |
34
|
|
|
|
|
|
|
) |
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
0
|
|
|
|
$conn_args->{$w} = $session->{args}->{$w} || $default->{$w}; |
37
|
0
|
0
|
|
|
|
|
delete $conn_args->{$w} unless ( defined $conn_args->{$w} ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
my $s = |
40
|
|
|
|
|
|
|
MongoDB->connect( $session->{args}->{host} || $default->{host}, |
41
|
0
|
0
|
0
|
|
|
|
$conn_args ) |
42
|
|
|
|
|
|
|
or die('Unable to connect to MongoDB server'); |
43
|
|
|
|
|
|
|
$self->{collection} = |
44
|
|
|
|
|
|
|
$s->get_database( $session->{args}->{db_name} || $default->{db_name} ) |
45
|
|
|
|
|
|
|
->get_collection( $session->{args}->{collection} |
46
|
0
|
|
0
|
|
|
|
|| $default->{collection} ); |
|
|
|
0
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub insert { |
50
|
0
|
|
|
0
|
0
|
|
my ( $self, $session ) = splice @_; |
51
|
0
|
|
|
|
|
|
$self->connection($session); |
52
|
0
|
0
|
|
|
|
|
die('no id') unless ( $session->{data}->{_session_id} ); |
53
|
0
|
|
|
|
|
|
$session->{data}->{_id} = $session->{data}->{_session_id}; |
54
|
0
|
|
|
|
|
|
$self->{collection}->insert_one( $session->{data} ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub update { |
58
|
0
|
|
|
0
|
0
|
|
my ( $self, $session ) = splice @_; |
59
|
0
|
|
|
|
|
|
$self->remove($session); |
60
|
0
|
|
|
|
|
|
$self->insert($session); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub materialize { |
64
|
0
|
|
|
0
|
0
|
|
my ( $self, $session ) = splice @_; |
65
|
0
|
|
|
|
|
|
$self->connection($session); |
66
|
|
|
|
|
|
|
$session->{data} = $self->{collection} |
67
|
0
|
|
|
|
|
|
->find_one( { _id => $session->{data}->{_session_id} } ); |
68
|
0
|
0
|
|
|
|
|
if ( $session->{data}->{_session_id} ) { |
69
|
0
|
|
|
|
|
|
$session->{data}->{_session_id} = $session->{data}->{_id}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
0
|
|
|
|
|
|
die "Object does not exist in data store"; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub remove { |
77
|
0
|
|
|
0
|
0
|
|
my ( $self, $session ) = splice @_; |
78
|
0
|
|
|
|
|
|
$self->connection($session); |
79
|
0
|
|
|
|
|
|
$self->{collection}->delete_one( { _id => $session->{data}->{_session_id} } ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub DESTROY { |
83
|
0
|
|
|
0
|
|
|
my $self = shift; |
84
|
0
|
|
|
|
|
|
$self->{collection} = undef; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
__END__ |