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 58     58   436 use strict;
  58         158  
  58         1874  
16 58     58   322 use warnings;
  58         132  
  58         2186  
17             package MongoDB::Op::_DropCollection;
18              
19             # Implements a collection drop; returns a MongoDB::CommandResult
20              
21 58     58   327 use version;
  58         141  
  58         416  
22             our $VERSION = 'v2.2.0';
23              
24 58     58   4598 use Moo;
  58         139  
  58         338  
25              
26 58     58   18567 use MongoDB::Error;
  58         161  
  58         7203  
27 58     58   484 use MongoDB::Op::_Command;
  58         159  
  58         1381  
28 58     58   359 use Safe::Isa;
  58         166  
  58         8075  
29 58     58   465 use namespace::clean;
  58         153  
  58         441  
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;