File Coverage

blib/lib/MongoDB/Op/_DropCollection.pm
Criterion Covered Total %
statement 24 37 64.8
branch 0 8 0.0
condition 0 5 0.0
subroutine 8 9 88.8
pod 0 1 0.0
total 32 60 53.3


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   403 use strict;
  59         129  
  59         1688  
16 59     59   285 use warnings;
  59         118  
  59         2358  
17             package MongoDB::Op::_DropCollection;
18              
19             # Implements a collection drop; returns a MongoDB::CommandResult
20              
21 59     59   281 use version;
  59         115  
  59         390  
22             our $VERSION = 'v2.2.2';
23              
24 59     59   4173 use Moo;
  59         117  
  59         312  
25              
26 59     59   16692 use MongoDB::Error;
  59         150  
  59         7010  
27 59     59   380 use MongoDB::Op::_Command;
  59         438  
  59         1334  
28 59     59   297 use Safe::Isa;
  59         133  
  59         7221  
29 59     59   400 use namespace::clean;
  59         117  
  59         423  
30              
31             with $_ for qw(
32             MongoDB::Role::_PrivateConstructor
33             MongoDB::Role::_CollectionOp
34             MongoDB::Role::_WriteOp
35             );
36              
37             sub execute {
38 0     0 0   my ( $self, $link ) = @_;
39              
40             my $op = MongoDB::Op::_Command->_new(
41             db_name => $self->db_name,
42             query => [
43             drop => $self->coll_name,
44 0 0         ( $link->supports_helper_write_concern ? ( @{ $self->write_concern->as_args } ) : () ),
  0            
45             ],
46             query_flags => {},
47             bson_codec => $self->bson_codec,
48             session => $self->session,
49             monitoring_callback => $self->monitoring_callback,
50             );
51              
52 0           my $res;
53             eval {
54 0           $res = $op->execute($link);
55 0           $res->assert_no_write_concern_error;
56 0           1;
57 0 0         } or do {
58 0   0       my $error = $@ || "Unknown error";
59 0 0         if ( $error->$_isa("MongoDB::DatabaseError") ) {
60 0 0 0       return undef if $error->code == NAMESPACE_NOT_FOUND() || $error->message =~ /^ns not found/; ## no critic: make $res undef
61             }
62 0           die $error;
63             };
64              
65 0           return $res;
66             }
67              
68             1;