File Coverage

blib/lib/MongoDB/Op/_RenameCollection.pm
Criterion Covered Total %
statement 21 27 77.7
branch 0 2 0.0
condition n/a
subroutine 7 8 87.5
pod 0 1 0.0
total 28 38 73.6


line stmt bran cond sub pod time code
1             # Copyright 2016 - 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     59   477 use strict;
  59         161  
  59         1866  
16 59     59   374 use warnings;
  59         140  
  59         2171  
17             package MongoDB::Op::_RenameCollection;
18              
19             # Implements a collection move/rename; returns a MongoDB::CommandResult
20              
21 59     59   406 use version;
  59         142  
  59         385  
22             our $VERSION = 'v2.2.1';
23              
24 59     59   4790 use Moo;
  59         152  
  59         329  
25              
26 59     59   17645 use MongoDB::Op::_Command;
  59         160  
  59         1503  
27 59         407 use Types::Standard qw(
28             Str
29 59     59   334 );
  59         148  
30              
31 59     59   28543 use namespace::clean;
  59         162  
  59         364  
32              
33             has [ 'src_ns', 'dst_ns' ] => (
34             is => 'ro',
35             required => 1,
36             isa => Str,
37             );
38              
39             with $_ for qw(
40             MongoDB::Role::_PrivateConstructor
41             MongoDB::Role::_DatabaseOp
42             MongoDB::Role::_WriteOp
43             );
44              
45             sub execute {
46 0     0 0   my ( $self, $link ) = @_;
47              
48             my $op = MongoDB::Op::_Command->_new(
49             db_name => 'admin', # special for this command -- not the db_name attribute
50             query => [
51             renameCollection => $self->src_ns,
52             to => $self->dst_ns,
53 0 0         ( $link->supports_helper_write_concern ? ( @{ $self->write_concern->as_args } ) : () ),
  0            
54             ],
55             query_flags => {},
56             bson_codec => $self->bson_codec,
57             session => $self->session,
58             monitoring_callback => $self->monitoring_callback,
59             );
60              
61 0           my $res = $op->execute($link);
62 0           $res->assert_no_write_concern_error;
63              
64 0           return $res;
65             }
66              
67             1;