[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Subclasses, tied hashes, {get,set}_property, undefined values
- From: Giuliano <g cioffi tiscali it>
- To: gtk-perl-list gnome org
- Subject: Subclasses, tied hashes, {get,set}_property, undefined values
- Date: Thu, 15 Nov 2007 16:56:40 +0100
Dear all,
I ran into a strange behaviour with Glib::Object::Subclass .
If I call set_property using a value stored in a tied hash, the
corresponding get_property returns undef. This doesn't happen if
scalar context is forced when calling set_property.
Please, see the attached test case.
If $hashref is a tied hash reference (of course the 'Title'key is
defined):
$w->set_property('title', $hashref->{Title});
then this returns undef:
$w->set_property('title', $hashref->{Title});
Whereas the following block returns a defined value:
$w->set_property('title', scalar($hashref->{Title}));
$w->set_property('title', $hashref->{Title});
Does anyone know why this happens?
thanks for your help,
ciao,
--
Giuliano
#!/usr/bin/perl
$i=$j=$r=$b=-16.0;while((print"\n"),$b++<15){foreach$a(0..78){print
+(split //,' .:-;!/>)|&IH%*#')[$k&15];for($i=$k=$r=0;$j=$r*$r-$i*$i
-2+$a/25,$i=2*$r*$i+$b/10,$j*$j+$i*$i<11&&$k++<111;$r=$j){}}}
#!/usr/bin/perl
package ClassFoo;
use strict;
use Gtk2;
use Glib::Object::Subclass
'Gtk2::Bin',
properties => [
Glib::ParamSpec->boxed('title',
'title',
'The button\'s title',
'Glib::Scalar',
[qw/writable readable/]),
];
sub INIT_INSTANCE {
my $self = shift;
$self->{prop_title} = undef;
}
sub SET_PROPERTY {
my ($self, $pspec, $val) = @_;
my $propname = $pspec->get_name;
if ($propname eq 'title') {
$self->{prop_title} = $val;
} else {
die "unknown property ``$propname''";
}
}
sub GET_PROPERTY {
my ($self, $pspec) = @_;
my $propname = $pspec->get_name;
if ($propname eq 'title') {
return $self->{prop_title};
} else {
die "unknown property ``$propname''";
}
}
package main;
use strict;
use Hash::Case::Preserve;
my $hashref = {};
tie %$hashref, 'Hash::Case::Preserve';
$hashref->{Title} = 'foo';
my $w;
sub subprint($) { my $a = shift; print "subprint \"$a\"\n"; }
subprint($hashref->{Title});
$w = new ClassFoo;
$w->set_property('title', $hashref->{Title});
print "get_property \"".$w->get_property('title')."\"\n";
$w->set_property('title', scalar($hashref->{Title}));
print "get_property scalar \"".$w->get_property('title')."\"\n";
my $hashref_untied = {};
$hashref_untied->{Title} = 'foo';
$w->set_property('title', $hashref_untied->{Title});
print "get_property untied \"".$w->get_property('title')."\"\n";
exit;
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]