File Coverage

blib/lib/MongoDB/ReadConcern.pm
Criterion Covered Total %
statement 28 28 100.0
branch 6 8 75.0
condition 2 6 33.3
subroutine 9 9 100.0
pod 0 2 0.0
total 45 53 84.9


line stmt bran cond sub pod time code
1             # Copyright 2015 - 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 58     58   409 use strict;
  58         122  
  58         1725  
16 58     58   337 use warnings;
  58         127  
  58         1871  
17             package MongoDB::ReadConcern;
18              
19             # ABSTRACT: Encapsulate and validate a read concern
20              
21 58     58   287 use version;
  58         130  
  58         301  
22             our $VERSION = 'v2.2.0';
23              
24 58     58   4074 use Moo;
  58         129  
  58         329  
25 58     58   17239 use MongoDB::Error;
  58         168  
  58         5895  
26 58         488 use Types::Standard qw(
27             Maybe
28             Str
29             ArrayRef
30 58     58   431 );
  58         139  
31              
32 58     58   41557 use namespace::clean;
  58         123  
  58         958  
33              
34             #pod =attr level
35             #pod
36             #pod The read concern level determines the consistency level required
37             #pod of data being read.
38             #pod
39             #pod The default level is C, which means the server will use its configured
40             #pod default.
41             #pod
42             #pod If the level is set to "local", reads will return the latest data a server has
43             #pod locally.
44             #pod
45             #pod Additional levels are storage engine specific. See L
46             #pod Concern|http://docs.mongodb.org/manual/search/?query=readConcern> in the MongoDB
47             #pod documentation for more details.
48             #pod
49             #pod This may be set in a connection string with the the C option.
50             #pod
51             #pod =cut
52              
53             has level => (
54             is => 'ro',
55             isa => Maybe [Str],
56             predicate => 'has_level',
57             );
58              
59             sub BUILD {
60 11     11 0 7896 my $self = shift;
61 11 100       99 if ( defined $self->{level} ) {
62 9         110 $self->{level} = lc $self->{level};
63             }
64             }
65              
66             # public interface for compatibility, but undocumented
67             sub as_args {
68 6     6 0 16 my ( $self, $session ) = @_;
69              
70             # if session is defined and operation_time is not, then either the
71             # operation_time was not sent on the response from the server for this
72             # session or the session has causal consistency disabled.
73 6 100       15 if ( $self->{level} ) {
74             return [
75             readConcern => {
76             level => $self->{level},
77 5 50 33     32 ( defined $session && defined $session->operation_time
78             ? ( afterClusterTime => $session->operation_time )
79             : () ),
80             }
81             ];
82             }
83             else {
84             return [
85 1 50 33     7 ( defined $session && defined $session->operation_time
86             ? ( readConcern => { afterClusterTime => $session->operation_time } )
87             : ()
88             )
89             ];
90             }
91             }
92              
93             1;
94              
95             __END__