|Title:||Extensible Object Copying|
|Version:||$Revision: 1.4 $|
|Author:||Donal K. Fellows <donal dot k dot fellows at manchester dot ac dot uk>|
|Created:||Monday, 13 February 2012|
|Keywords:||Tcl, TclOO, copy, clone|
This TIP proposes a mechanism whereby an object or class can provide additional control over how it gets copied to a new one by the oo::copy command.
I always knew that TclOO's oo::copy command was not particularly complete, in that only the C-level state was copied. The vast majority of state associated with an object (notably including its variables) was not copied on the grounds that the caller of oo::copy could do that for themselves. However, this has not proved particularly workable in practice once someone actually started to use the mechanism. It turns out that the callers of oo::copy expect a full copy of the object to be created.
This is quite challenging because some things associated with an object are tricky to copy correctly. For example, if an object has a number of Tk widgets under its control, or has timer callbacks set up, these are very challenging for a generic object copying scheme to detect (and generic copying of Tcl commands is difficult anyway). Fortunately, we already have a mechanism for handling such per-object variation: methods.
I propose that the oo::copy command will internally call the newly created object's <cloned> method (passing in the name of the source object as the only argument) to allow for the customization of the copy. If the method fails (throws an exception), the copy will be destroyed and the error propagated.
copiedObject <cloned> sourceObject
Furthermore, a default implementation of the <cloned> method will be created in oo::object which will duplicate the variables and procedures (note, not other commands) of the source to the copy. This method will not be exported by default (nor should it be; the method is not intended to be called directly).
See the "development-rfe3485060" branch of the tcloo repository: https://core.tcl.tk/tcloo/timeline?r=development-rfe3485060
This document has been placed in the public domain.
[Index] [History] [HTML Format] [Source Format] [LaTeX Format] [Text Format] [XML Format] [*roff Format (experimental)] [RTF Format (experimental)]TIP AutoGenerator - written by Donal K. Fellows