From: Don Armstrong Date: Sat, 29 Jun 2019 23:44:16 +0000 (-0700) Subject: add combine method to Debbugs::Collection; fix keys_of_members bug X-Git-Url: https://git.donarmstrong.com/?p=debbugs.git;a=commitdiff_plain;h=c604b8914b9cbd3e8e6efafa6572cab9efbd35a5 add combine method to Debbugs::Collection; fix keys_of_members bug --- diff --git a/Debbugs/Collection.pm b/Debbugs/Collection.pm index 552c0f3..350a03f 100644 --- a/Debbugs/Collection.pm +++ b/Debbugs/Collection.pm @@ -79,7 +79,8 @@ Returns a clone of this collection with the same universe as this collection =head2 $collection->limit(@member_keys) -Returns a new collection limited to the list of member keys passed +Returns a new collection limited to the list of member keys passed. Will add new +members to the universe if they do not currently exist. =head2 $collection->add($member) @@ -89,6 +90,10 @@ Add a member to this collection Add a member to this collection by key +=head2 $collection->combine($collection2) or $collection + $collection2 + +Combines the members of both collections together and returns the new collection + =head2 $collection->get($member_key) Get member(s) by key, returning undef for keys which do not exist in the @@ -295,6 +300,16 @@ sub add { return @members_added; } +use overload '+' => "combine", + '""' => "CARP_TRACE"; + +sub combine { + my $self = shift; + my $return = $self->clone; + $return->add($_->members) for @_; + return $return; +} + sub get { my $self = shift; my @res = map {$self->_get_member($_)} @@ -309,7 +324,7 @@ sub member_key { sub keys_of_members { my $self = shift; - return $self->map(sub {$self->member_key($_[0])}); + return $self->map(sub {$self->member_key($_)}); } sub exists {