In Playing with TclOO, Richard Suchenwirth provided a method to dump the class and variables of an object:
define oo::object method dump {{pat *}} { set res [list class [info object class [self]]] foreach i [info object vars [self] $pat] { my variable $i lappend res $i [set $i] } set res }
This page should explore ways to serialize/unserialize TclOO objects.
My first thought would be to check if the self's variables themselves are objects:
define oo::object method serialize {{pat *}} { set res [list class [info object class [self]]] foreach i [info object vars [self] $pat] { my variable $i if {[info object isa object [set $i]]} { set value [[set $i] serialize] } else { set value [set $i] } lappend res $i $value } set res }
RS 2009-05-08: This is however dangerous when cycles are in the object graph: say, a genealogy application, where a has father:b and b has children:a ...