Re: Glib::Object::Subclass bug? or Misunderstanding?

muppet wrote:

On Mar 18, 2006, at 10:01 AM, James Muir wrote:

Is this a bug, or am I as usual missing something?

It's functioning correctly; your SET_PROPERTY isn't actually doing anything. See below:

# Comment out the SET_PROPERTY and get() works!!
my ($self, $pspec, $newval) = @_;

my $param_name = $pspec->get_name;

print "Item, SET_PROPERTY: name: $param_name value: $newval\n";

# actually do something with $newval. the default implementation
# of GET_PROPERTY will look for the value in $self->{$param_name}.
# the default implementation of SET_PROPERTY does this:
$self->{$param_name} = $newval;


So, GET_PROPERTY was looking for $self->{border}, which was undefined, because no value had ever been set to it.

I apologize for the posting error. In my attempt to get to the essence of the problem I went too far. Here's the simple example with the $self->{$param_name} = $newval in place. Now the get -- still -- fails, though I wouldn't have expected it to do so. If I uncomment the GET_PROPERTY in the example below all is well, but I would have expected the example below to work without it.

I'm using libgnomecanvas 2.10.2 and Gtk+2 2.8.11

Thanks for any help you can offer on this matter. Jaap Karssenberg has reported problems to me with the software I sent him after he upgraded his machine. So it's not just me that's having troubles after an upgrade. I'm trying to understand what's going wrong so I can fix this problem.

use Test::More tests => 3;

use Gtk2 '-init';

use Gnome2::Canvas;

my $view = Gnome2::Canvas->new_aa();

my $goober = Gnome2::Canvas::Item->new($view->root, 'Goober', border=>99);

isa_ok( $goober, 'Goober');

my $border = $goober->get('border');

is( defined($border), 1, 'border should be defined');

is ($border, 99, 'border should have value 99');

exit 0;

package Goober;

use warnings;
use strict;

use Gnome2::Canvas;

use Glib ':constants';

use Glib::Object::Subclass

properties => [
Glib::ParamSpec->scalar ('border', 'border', 'The border', G_PARAM_READWRITE),

# Comment out the SET_PROPERTY and get() works!!
my ($self, $pspec, $newval) = @_;

my $param_name = $pspec->get_name;

print "Item, SET_PROPERTY: name: $param_name value: $newval\n";

$self->{$param_name} = $newval;

# my ($self, $pspec) = @_;

# return ($self->{$pspec->get_name} || $pspec->get_default_value);

This is what I get for output:

(/home/james/bug)> perl
Item, SET_PROPERTY: name: border value: 99
ok 1 - The object isa Goober
not ok 2 - border should be defined
# Failed test 'border should be defined'
# in at line 15.
# got: ''
# expected: '1'
not ok 3 - border should have value 99
# Failed test 'border should have value 99'
# in at line 17.
# got: undef
# expected: '99'
# Looks like you failed 2 tests of 3.

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