Re: Stealing a good idea from Gtk#
- From: Torsten Schoenfeld <kaffeetisch gmx de>
- To: gtk-perl-list gnome org
- Subject: Re: Stealing a good idea from Gtk#
- Date: Mon, 27 Sep 2004 09:58:14 +0200
On Mon, 2004-09-27 at 02:00, A. Pagaltzis wrote:
$button -> Clicked += \&clicked;
It's definitely cool. Three things irk me, though:
Jeez, you all are one big bunch of critics.
a) += just isn't used that way in Perl, and I think
overloading its meaning the way its done here is too
idiosyncratic.
Point taken. The way I think about it is this: The installed method
represents a signal which in turn is a kind of container for all signal
handlers connected to it. So when you do +=, you add a handler to the
list of handlers.
b) There is no indication that we're doing something with a
signal here, not just using any old mutator.
"If it was hard to write, it should be hard to understand."
-- The Real Programmer
c) StudlyCaps, particularly as a vehicle to solve namespace
clashes.
Yeah, that irked me too.
It is completely untested, but if I didn't screw it up too
thoroughly, you should now be able to say
You'd need to at least get rid of the "return". perlsub says:
You can't use the return keyword, you must pass out the value
before falling out of subroutine scope. (see comment in example
above). This is usually not a problem, but it disallows an
explicit return out of a deeply nested loop, which is sometimes a
nice way out.
$window->SIGNAL::delete_event = sub {
Gtk2->main_quit();
return FALSE;
};
In addition to what muppet already said (using an assignment when you're
actually adding a handler to a list of handlers), I'm not fond of
introducing a global namespace for something that is Glib-specific.
Leaving that aside, I really do like your approach too. AUTOLOAD,
lvalue subs, tie -- all the cool magic in just a few lines of Perl.
--
Bye,
-Torsten
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]