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 58     58   438 use strict;
  58         152  
  58         1935  
16 58     58   330 use warnings;
  58         132  
  58         2233  
17             package MongoDB::Op::_RenameCollection;
18              
19             # Implements a collection move/rename; returns a MongoDB::CommandResult
20              
21 58     58   326 use version;
  58         130  
  58         367  
22             our $VERSION = 'v2.2.0';
23              
24 58     58   4575 use Moo;
  58         130  
  58         395  
25              
26 58     58   17760 use MongoDB::Op::_Command;
  58         188  
  58         1506  
27 58         496 use Types::Standard qw(
28             Str
29 58     58   372 );
  58         174  
30              
31 58     58   29138 use namespace::clean;
  58         164  
  58         383  
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;