[PATCH] testbot: Make it possible to get an unfiltered clone of a collection.

Francois Gouget fgouget at codeweavers.com
Mon Jun 11 11:44:16 CDT 2018


Once a filter has been applied to a collection it cannot be removed.
This is particularly a problem on Detailref collections (such as
$Job->Steps) as the code that has set the filter may be anywhere.
So Clone() makes it possible to get an unfiltered copy of the
collection without modifying the original collection's filter, and
thus without impacting the code using it.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
 testbot/lib/ObjectModel/Collection.pm | 34 ++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/testbot/lib/ObjectModel/Collection.pm b/testbot/lib/ObjectModel/Collection.pm
index 712172bca..c110c98b5 100644
--- a/testbot/lib/ObjectModel/Collection.pm
+++ b/testbot/lib/ObjectModel/Collection.pm
@@ -40,7 +40,7 @@ criteria.
 use Exporter 'import';
 our @EXPORT_OK = qw(new ComputeMasterKey);
 
-use Scalar::Util qw(weaken);
+use Scalar::Util qw(blessed weaken);
 use ObjectModel::BackEnd;
 use ObjectModel::Item;
 
@@ -114,6 +114,38 @@ sub _initialize($;$)
   $self->{AllScopeItems}->{ref($self)} ||= {};
 }
 
+=pod
+=over 12
+
+=item C<Clone()>
+
+Clones the collection, omitting the filters that were applied to it.
+
+=back
+=cut
+
+sub Clone($)
+{
+  my ($self) = @_;
+
+  my $Copy = {TableName           => $self->{TableName},
+              CollectionName      => $self->{CollectionName},
+              ItemName            => $self->{ItemName},
+              PropertyDescriptors => $self->{PropertyDescriptors},
+              MasterColNames      => $self->{MasterColNames},
+              MasterColValues     => $self->{MasterColValues},
+              MasterKey           => $self->{MasterKey},
+              Filters             => {},
+              AllScopeItems       => $self->{AllScopeItems},
+              Items               => undef};
+  # See Collection::new()
+  weaken($Copy->{AllScopeItems});
+
+  $Copy = bless $Copy, blessed($self);
+  $Copy->_initialize(@_);
+  return $Copy;
+}
+
 sub GetPropertyDescriptors($)
 {
   my ($self) = @_;
-- 
2.17.1



More information about the wine-devel mailing list