Re: A little tie magic



* Bjarne Steinsbø <bosteins broadpark no> [2003-12-08 12:30]:
Maybe I should add proper sanity checks to this code and a
bunch of tests and up it to CPAN?

By all means do that.  Your solution might be exactly what
somebody else has been looking for.  There is already
Tie::Watch, which is somewhat close (in principle) to what you
are doing, but they are sufficiently different (IMO) that there
is room for both.

Ah, that's what it's called.. I overlooked that one. I think I'll
have another look before I make any moves, this is probably a
very commonly needed wheel. I don't particularly like the ::Watch
interface, either..

It's all a matter of design choices.  After all, TIMTOWTDI.
All of them (or least most of them :-) equally valid.  In this
case, compare the syntax of a specialized way:

 $button->bind_variable (\$but_state);

to the syntax of a generalized way:

 tie $but_state, 'Tie::NotifyScalar', sub { $button->set_active ($_[1] }, sub { $button->get_active };

Does the simplified syntax warrent the "pollution" of Gtk?  In
my view it probably does, but I have no problems accepting that
others might feel different.  Which is why I asked the list...

True enough that the generic syntax is unwieldly; how about a single
helper function that implements this mechanism in terms of a tied
variable? The syntax would change slightly -

  gtk2_bind_variable($button, \$but_state);

and the function would look at the class of $button to determine
which callbacks to use. You wouldn't need to inject any code in
the Gtk2 classes and the syntax is just as concise.

-- 
Regards,
Aristotle
 
"If you can't laugh at yourself, you don't take life seriously enough."



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