Subject: | suggest object contents callback |
Date: | Thu, 05 Mar 2009 11:30:52 +1100 |
To: | bug-Test-Weaken [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
It'd be good if Test::Weaken had a callback to fetch the contents of an
object.
In Gtk, sub-widgets or sub-objects aren't in fields of the object hash,
only in gtk's structs, which you have to pick out from get_property(),
get_children(), etc. And I believe in the various "inside-out" class
schemes object property data is not in the object itself, but separate.
A callback would make it possible to traverse those things (or the parts
one thinks may be subject to leaks).
I'm not sure how it would look, maybe
sub my_gtk_container_children {
my ($obj) = @_;
return $obj->isa('Gtk2::Container') && $obj->get_children;
}
leaks ({ constructor => ...,
contents => \&my_gtk_container_children })
You can get the same effect in the constructor by recursing into the
objects yourself and returning all the parts. I've been doing that for
gtk container children. But leaks() makes exactly such a recursive
traversal, if it could be told about extra contents/fields/properties in
the objects it visits.
As with the ignore option I can imagine multiple contents fetching funcs
intended for different classes. So a way to pass different bits could
be good.
contents => [\>k_container_children,
\&gobject_properties,
\&inside_out_contents,
Fetching might often be a single method like get_children() above, so a
shorthand giving a class and method could be handy,
contents => [ ['Gtk2::Container','get_children'],
...