Re: Glib::Object::Subclass and properties

On 2011/11/20 at 01:34 AM, Torsten Schoenfeld <kaffeetisch gmx de> wrote:
On 17.11.2011 12:59, Martin Schlemmer wrote:
I have a Glib::Object::Subclass derived class, with a
Glib::ParamSpec->boolean() property named 'symbols' that has a
default value of TRUE. If I try to access it via $self->{symbols}, it
does not exist. If I however do a $self->set( symbols =>
$self->get('symbols') ) it does exist ...

Feature or bug?

Well, I'd say it's an implementation detail that leaked.

If you don't overwrite them, G:O:Subclass gives you default 
implementations of the GET_PROPERTY and SET_PROPERTY vfuncs that 
retrieve/store property values inside the object hash.  (See 'perldoc 
Glib::Object::Subclass' for more details.)  But if you haven't called 
set() yet, then nothing will be stored in the object hash.  You could 
argue that G:O:Subclass should make sure that the value in the hash is 
initially set to the default value if there is one.  But that doesn't 
sound too robust.  So I think you, as the class implementor, should 
handle initializing these values yourself.

Or you could just always go through get()/set() instead of direct hash 

I do not mind either way, just wanted to verify that it was due to some reason, and not maybe oversight.

On a bit different topic - I guess that if you make something readonly, the correct way is to use hash 
access? The reason I am asking, is because I am not sure if you do that, whether you should signal a notify 
on the property?



Vrywaringsklousule / Disclaimer: 

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