From: dpvc v. a. <we...@ma...> - 2005-08-14 00:17:07
|
Log Message: ----------- Added a copy method that produces a deep copy of the given object. This probably should be used through the new() methods to ducplicate the data used when creating an object, otherwise changes to the sub-objects will cause changes to the outer one. For example, if an interval is used to create a union and then the internal data for the interval is changed by hand, the changes will also occur in the union. That is, Value objects contain their data by REFERENCE. This should probably be changed, but fortunately, no one should be adjusting the internal structure of the objects by hand. Modified Files: -------------- pg/lib: Value.pm Revision Data ------------- Index: Value.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value.pm,v retrieving revision 1.45 retrieving revision 1.46 diff -Llib/Value.pm -Llib/Value.pm -u -r1.45 -r1.46 --- lib/Value.pm +++ lib/Value.pm @@ -114,6 +114,13 @@ return shift; } +sub copy { + my $self = shift; + my $copy = {%{$self}}; $copy->{data} = [@{$self->{data}}]; + foreach my $x (@{$copy->{data}}) {$x = $x->copy if Value::isValue($x)} + return bless $copy, ref($self); +} + ############################################################# # |