From 73b0ca5c3ddfd8aabc04ae093605ffaefdf13412 Mon Sep 17 00:00:00 2001 From: Nigel Gregoire Date: Wed, 13 Jan 2016 15:02:41 -0800 Subject: [PATCH 1/2] Calculate "inserted_count" --- lib/MongoDB/InsertManyResult.pm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/MongoDB/InsertManyResult.pm b/lib/MongoDB/InsertManyResult.pm index 0f87a7c6..64f325b3 100644 --- a/lib/MongoDB/InsertManyResult.pm +++ b/lib/MongoDB/InsertManyResult.pm @@ -44,11 +44,17 @@ The number of documents inserted. =cut has inserted_count => ( - is => 'ro', - default => 0, + is => 'lazy', + builder => '_build_inserted_count', isa => Num, ); +sub _build_inserted_count +{ + my ($self) = @_; + return scalar @{ $self->inserted }; +} + =attr inserted An array reference containing information about inserted documents (if any). From f371b43cb8b4e96cd7ccdcfe21d0c5275ab52187 Mon Sep 17 00:00:00 2001 From: Nigel Gregoire Date: Wed, 13 Jan 2016 15:28:21 -0800 Subject: [PATCH 2/2] Add unit test for "inserted_count" --- t/crud.t | 1 + 1 file changed, 1 insertion(+) diff --git a/t/crud.t b/t/crud.t index 40c04b0e..3a00c8f3 100644 --- a/t/crud.t +++ b/t/crud.t @@ -116,6 +116,7 @@ subtest "insert_many" => sub { }, "inserted_ids contains correct keys/values" ); + is($res->inserted_count, 2, "Two docs inserted."); # ordered insert should halt on error $coll->drop;