MongoDB/_ServerSession.pm

filter: Statementstmt 75.4% 40 / 53 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 68.7% 11 / 16 Podpod 0.0% 0 / 2 totaltotal 63.7% 51 / 80 CC 4 SCAR 16.5
CC
4
Cov
67%
_is_expiring
20.0
_build_session_id
2.0
__ANON__
2.0
CRAP 5.2
« MongoDB/Op/_GetMore.pm ↑ Summary MongoDB/Role/_WriteOp.pm »
1 # Copyright 2018 - present MongoDB, Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14  
15 59 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 59 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 package MongoDB::_ServerSession;
18  
19 # MongoDB Server Session object
20  
21 59 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 59 our $VERSION = 'v2.2.2';
23  
24 59 ▶use MongoDB::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 59 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 59 ▶use UUID::URandom;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 59 ▶use Math::BigInt;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 59 ▶use MongoDB::_Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
30 Document
31 59 );
32 59 ▶use Types::Standard qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
33 Maybe
34 InstanceOf
35 Int
36 Bool
37 59 );
38 59 ▶use constant UUID_TYPE => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 59 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 # session_id
43 #
44 # $server_session->session_id;
45 #
46 # Returns the session id for this server session as a L<BSON::Bytes> object
47 # containing a binary UUID V4. For lower network usage, if not provided on
48 # initialisation this class will generate a new UUID instead of consulting the
49 # server for a new session id.
50  
51 59 has session_id => (
52 is => 'lazy',
53 isa => Document,
54 builder => '_build_session_id',
55 );
56  
57 0 ▶sub _build_session_id {
Subroutine _build_session_id: not called CC=1 SCAR=6.9
58 0 my ( $self ) = @_;
59 0 my $uuid = BSON::Bytes->new(
60 data => UUID::URandom::create_uuid(),
61 subtype => UUID_TYPE,
62 );
63 0 return { id => $uuid };
64 }
65  
66 # last_use
67 #
68 # $server_session->last_use;
69 #
70 # Returns the unix time that this server session was last used. Used for checking
71 # expiry of a server session. If undefined, then the session has (probably) not
72 # been used on the server.
73  
74 59 has last_use => (
75 is => 'rwp',
76 init_arg => undef,
77 isa => Maybe[Int],
78 );
79  
80 # transaction_id
81 #
82 # $server_session->transaction_id
83 #
84 # Returns the current transaction id for this server session. This is a ratcheted
85 # incrementing ID number, which when combined with the session id allows for
86 # retrying transactions in the correct order.
87  
88 has transaction_id => (
89 is => 'rwp',
90 init_arg => undef,
91 0 ▶ default => sub { Math::BigInt->new('0') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 59 );
93  
94 # pool_epoch
95 #
96 # tracks which pool the session came from; sessions won't be checked into
97 # a newer pool
98  
99 59 has pool_epoch => (
100 is => 'ro',
101 default => -1,
102 );
103  
104 #
105 # Mark this session as dirty.
106 # A server session is marked dirty when a command fails with a network
107 # error. Dirty sessions are later discarded from the server session pool.
108 #
109  
110 59 has dirty => (
111 is => 'rwp',
112 isa => Bool,
113 default => 0,
114 );
115  
116 0 ▶sub mark_dirty {
Subroutine mark_dirty: not called CC=1 SCAR=6.9
Pod undocumented
117 0 my $self = shift;
118 0 $self->_set_dirty(1);
119 }
120  
121 # update_last_use
122 #
123 # $server_session->update_last_use;
124 #
125 # Updates the value of L</last_use> to the current unix time.
126  
127 0 ▶sub update_last_use {
Subroutine update_last_use: not called CC=1 SCAR=6.9
Pod undocumented
128 0 my ( $self ) = @_;
129 0 $self->_set_last_use( time() );
130 }
131  
132 0 ▶sub _is_expiring {
Subroutine _is_expiring: not called CC=4 SCAR=30.0
133 0 my ( $self, $session_timeout ) = @_;
134  
135 # if session_timeout is undef, then sessions arent actually supported (this
136 # value should be from logical_session_timeout_minutes).
137 0 ▶ return 1 unless defined $session_timeout;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $session_timeout 0 0 0
138  
139 0 my $timeout = time() - ( ( $session_timeout - 1 ) * 60 );
140  
141 # Undefined last_use means its never actually been used on the server
142 0 ▶ return 1 if defined $self->last_use && $self->last_use < $timeout;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->last_use and $self->last_use < $timeout 0 0 0
Condition0%0/3
defined $self->last_use and $self->last_use < $timeout
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->last_use and $self->last_use < $timeout
defined $self->last_use $self->last_use < $timeout
Truth table0%0/3
A and B
A= defined $self->last_useB= $self->last_use < $timeout
ABresult
0X0
100
111
143 0 return;
144 }
145  
146 59 1;
147  
148 # vim: set ts=4 sts=4 sw=4 et tw=75:
« MongoDB/Op/_GetMore.pm ↑ Summary MongoDB/Role/_WriteOp.pm »