MongoDB/_TransactionOptions.pm

filter: Statementstmt 60.0% 42 / 70 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 73.3% 11 / 15 Podpod n/a totaltotal 43.8% 53 / 121 CC 11 SCAR 24.5
CC
11
Cov
44%
_build_read_preference
30.0
_build_write_concern
20.0
_build_read_concern
12.0
CRAP 11.6
« MongoDB/Op/_ListIndexes.pm ↑ Summary MongoDB/Cursor.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::_TransactionOptions;
18  
19 # MongoDB options for transactions
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 MongoDB::ReadConcern;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 59 ▶use MongoDB::WriteConcern;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 59 ▶use MongoDB::ReadPreference;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 59 ▶use MongoDB::_Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
31 MongoDBClient
32 WriteConcern
33 ReadConcern
34 ReadPreference
35 59 );
36 59 ▶use Types::Standard qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
37 HashRef
38 Any
39 Maybe
40 Int
41 59 );
42 59 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 # Options provided during start transaction
45 59 has options => (
46 is => 'ro',
47 required => 1,
48 isa => HashRef,
49 );
50  
51 # Options provided during start session
52 59 has default_options => (
53 is => 'ro',
54 required => 1,
55 isa => HashRef,
56 );
57  
58 # needed for defaults
59 59 has client => (
60 is => 'ro',
61 required => 1,
62 isa => MongoDBClient,
63 );
64  
65 59 has write_concern => (
66 # must error on start_transaction, so is built immediately
67 is => 'ro',
68 isa => WriteConcern,
69 init_arg => undef,
70 builder => '_build_write_concern',
71 );
72  
73 0 ▶sub _build_write_concern {
Subroutine _build_write_concern: not called CC=4 SCAR=30.0
74 0 my $self = shift;
75  
76 0 my $options = $self->options->{writeConcern};
77 0 ▶ $options ||= $self->default_options->{writeConcern};
Condition0%0/3
$options ||= $self->default_options->{"writeConcern"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$options ||= $self->default_options->{"writeConcern"}
$options $self->default_options->{"writeConcern"}
Truth table0%0/3
A ||= B
A= $optionsB= $self->default_options->{"writeConcern"}
ABresult
1X1
011
000
78 0 ▶ $options ||= {};
Condition0%0/2
$options ||= {}
l!l
00
MC/DC0%0/1
$options ||= {}
$options
Truth table0%0/2
A
A= $options
Aresult
11
00
79  
80 # Merge in client default to pass through forced undef wtimeout etc.
81 0 $options = {
82 $self->client->_write_concern_options,
83 %$options,
84 };
85 0 my $write_concern = MongoDB::WriteConcern->new( $options );
86  
87 0 ▶ unless ( $write_concern->is_acknowledged ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($write_concern->is_acknowledged) 0 0 0
88 0 MongoDB::ConfigurationError->throw(
89 'transactions do not support unacknowledged write concerns' );
90 }
91  
92 0 return $write_concern;
93 }
94  
95 59 has read_concern => (
96 is => 'lazy',
97 isa => ReadConcern,
98 init_arg => undef,
99 builder => '_build_read_concern',
100 );
101  
102 # Read concern errors are returned by the database, so no need to check for
103 # errors
104 0 ▶sub _build_read_concern {
Subroutine _build_read_concern: not called CC=3 SCAR=24.8
105 0 my $self = shift;
106  
107 0 my $options = $self->options->{readConcern};
108 0 ▶ $options ||= $self->default_options->{readConcern};
Condition0%0/3
$options ||= $self->default_options->{"readConcern"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$options ||= $self->default_options->{"readConcern"}
$options $self->default_options->{"readConcern"}
Truth table0%0/3
A ||= B
A= $optionsB= $self->default_options->{"readConcern"}
ABresult
1X1
011
000
109  
110 0 ▶ return MongoDB::ReadConcern->new( $options ) if defined $options;
Branch: 1 branch
BranchTrueFalseTotal
if defined $options 0 0 0
111 0 return $self->client->read_concern;
112 }
113  
114 59 has read_preference => (
115 is => 'lazy',
116 isa => ReadPreference,
117 init_arg => undef,
118 builder => '_build_read_preference',
119 );
120  
121 # Read preferences must be primary at present, so check after building it
122 0 ▶sub _build_read_preference {
Subroutine _build_read_preference: not called CC=5 SCAR=34.0
123 0 my $self = shift;
124  
125 0 my $options = $self->options->{readPreference};
126 0 ▶ $options ||= $self->default_options->{readPreference};
Condition0%0/3
$options ||= $self->default_options->{"readPreference"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$options ||= $self->default_options->{"readPreference"}
$options $self->default_options->{"readPreference"}
Truth table0%0/3
A ||= B
A= $optionsB= $self->default_options->{"readPreference"}
ABresult
1X1
011
000
127  
128 0 my $read_pref;
129 0 ▶ $read_pref = MongoDB::ReadPreference->new( $options ) if defined $options;
Branch: 1 branch
BranchTrueFalseTotal
if defined $options 0 0 0
130 0 ▶ $read_pref ||= $self->client->read_preference;
Condition0%0/3
$read_pref ||= $self->client->read_preference
l!l&&r!l&&!r
000
MC/DC0%0/2
$read_pref ||= $self->client->read_preference
$read_pref $self->client->read_preference
Truth table0%0/3
A ||= B
A= $read_prefB= $self->client->read_preference
ABresult
1X1
011
000
131  
132 0 ▶ if ( $read_pref->mode ne 'primary' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($read_pref->mode ne "primary") 0 0 0
133 0 MongoDB::ConfigurationError->throw(
134 "read preference in a transaction must be primary" );
135 }
136  
137 0 return $read_pref;
138 }
139  
140 59 has max_commit_time_ms => (
141 is => 'lazy',
142 isa => Maybe[Int],
143 init_arg => undef,
144 builder => '_build_max_commit_time_ms',
145 );
146  
147 0 ▶sub _build_max_commit_time_ms {
Subroutine _build_max_commit_time_ms: not called CC=2 SCAR=17.9
148 0 my $self = shift;
149 0 my ( $opts, $default_opts ) = ( $self->options, $self->default_options );
150 0 my $max_time_ms = $opts->{'maxCommitTimeMS'};
151 0 ▶ $max_time_ms ||= $default_opts->{'maxCommitTimeMS'};
Condition0%0/3
$max_time_ms ||= $default_opts->{"maxCommitTimeMS"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$max_time_ms ||= $default_opts->{"maxCommitTimeMS"}
$max_time_ms $default_opts->{"maxCommitTimeMS"}
Truth table0%0/3
A ||= B
A= $max_time_msB= $default_opts->{"maxCommitTimeMS"}
ABresult
1X1
011
000
152 0 return $max_time_ms;
153 }
154  
155 59 1;
« MongoDB/Op/_ListIndexes.pm ↑ Summary MongoDB/Cursor.pm »