Re: A little tie magic

Bjarne Steinsbø said:
Anyway, the attached version will probably be the last one unless
someone else takes an interest in this and wants it in the core
distribution.  It's now covering all my own needs, and then some.
Changes in the last iteration:

i have no objections to including this, since it is optional and the
functionality seems generally useful and perlish (especially given the
precendent in Tk).

it's also fairly unlikely that the name "bind_variable" will clash with
something that the upstream library will choose.  for complete safety and
clarity, however, i would probably choose a slightly ugly alternative such as
"_tie_variable" (leading _ because it's an extension, and 'tie' rather than
'bind' because it's using tie).

however, more than just the 't' sample you attached, we'd need a t-dir
non-interactive regression test and a nicely commented example to show how to
use it.  and remember that its API needs to be frozen by march, and all
releases after that must retain backwards compatibility.

I've still got a problem with garbage collection that I haven't managed
to figure out.  UNTIE/DESTROY isn't called when I expect them to be, so
a cyclic dependency introduced in the widget hash will prevent the
widget from being garbage collected by perl.  It shouldn't be a major
problem though, since widget destruction is relatively rare and the
amount of wasted memory is small.

not so fast --- widgets are destroyed every time you finish with a dialog and
don't keep it around.  for a complex and long-running program, that can add up
very quickly.  ... and i expect that the main use for the tied variables would
be to make it easier to sync data with widgets in dialogs.

since you are basing your implementation on widgets rather than normal
GObjects, you have at your disposal the GtkObject::destroy signal, which you
can use to break the circular references.

  $widget->signal_connect (destroy => sub {
                  delete $_[0]->{_BoundVariable_}

does that work?

muppet <scott at asofyet dot org>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]