Re: Glib::Object::Subclass and properties



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 access.



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