Properties as hash keys, damn perl is cool!

accessing GObject properties as keys in the object hash sould cool to you,
$button->{label} = 'This is the text on the button', then read on.

for various reasons, not the least of which is that it's really cool. i'd been
thinking about ways of doing this which would of been really complicated,
really ulgy and required non-trivial overhead for just about everything.
though it all i kept saying to my self i just want to tie certian keys, not
the whole hash. well fast forward to this morning when i realized, hey i can
just tie the certian keys i don't have to tie the whole hash, duh. so here it
is. some of the coding done for the documentation project came in handy as
well, namely list_properties.

it makes the following possible:

my $button = Gtk2::Button->new ('foo');
print $button->{label}."\n"; # prints foo
$button->{label} = 'bar';    # now when text label on the button will be bar.
print $button->{label}."\n"; # prints bar

just run the attached script on a system with Glib/Gtk2 installed and you'll
see demonstrations. take a look at it to see how 'simple' it really is.

consider this a request for comments, let me know what you think. assumming no
one comes up with major issues with it then this will be rolled into Glib
somewhere and be avaiable in the next release, which as muppet said will be
pretty soon.

all it takes is 76 lines of code, counting whitespace, that's pretty cool.


Description: Binary data

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