need your help for Gtk3 and Moose



Hello, thank you for your help last time. Here is another question I need to ask.

I have been trying to use Moose for Gtk3, and I do not think Moose is happy with Builder. After Moose load ui file, has 'root_window' tries to get main_window object, and it seems this is where the problem gets generated.

has 'root_window'    => (
    is    => 'rw',
    isa    => 'Gtk3::Window',
    #isa    => 'Gtk3::Object',
    lazy_build    => 1,
    trigger    => sub {
        my ( $self ) = @_;
        $self->root_window->signal_connect( destroy => \&quit_app );
    }
);
sub _build_root_window {
    my ( $self ) = @_;
    $self->builder->get_object('main_window');
}
when $builder->get_object('blah'); gets executed, it gives me a following error:

Honestly I was not sure Moose mailing list is more suited or not.
Following is the error msg I got:
#Attribute (root_window) does not pass the type constraint because: Validation failed for 'Gtk3::Object' with value undef at /usr/local/lib/perl/5.14.2/Moose/Exception.pm line 37 # Moose::Exception::_build_trace('Moose::Exception::ValidationFailedForInlineTypeConstraint=HASH(0xa415b4c)') called at reader Moose::Exception::trace (defined at /usr/local/lib/perl/5.14.2/Moose/Exception.pm line 9) line 7 # Moose::Exception::trace('Moose::Exception::ValidationFailedForInlineTypeConstraint=HASH(0xa415b4c)') called at /usr/local/lib/perl/5.14.2/Moose/Exception.pm line 49 # Moose::Exception::BUILD('Moose::Exception::ValidationFailedForInlineTypeConstraint=HASH(0xa415b4c)', 'HASH(0xa3fd840)') called at /usr/local/lib/perl/5.14.2/Class/MOP/Method.pm line 128 # Class::MOP::Method::execute('Moose::Meta::Method=HASH(0xa450e7c)', 'Moose::Exception::ValidationFailedForInlineTypeConstraint=HASH(0xa415b4c)', 'HASH(0xa3fd840)') called at /usr/local/lib/perl/5.14.2/Moose/Object.pm line 56 # Moose::Object::BUILDALL('Moose::Exception::ValidationFailedForInlineTypeConstraint=HASH(0xa415b4c)', 'HASH(0xa3fd840)') called at /usr/local/lib/perl/5.14.2/Moose/Meta/Class.pm line 282 # Moose::Meta::Class::new_object('Moose::Meta::Class=HASH(0xa40afac)', 'HASH(0xa3fd840)') called at /usr/local/lib/perl/5.14.2/Moose/Object.pm line 27 # Moose::Object::new('Moose::Exception::ValidationFailedForInlineTypeConstraint', 'type_constraint_message', 'Validation failed for \'Gtk3::Object\' with value undef', 'class_name', 'Tsuyoshi::Gtk3', 'attribute_name', 'root_window', 'value', undef) called at /usr/local/lib/perl/5.14.2/Moose/Util.pm line 51 # Moose::Util::throw_exception('ValidationFailedForInlineTypeConstraint', 'type_constraint_message', 'Validation failed for \'Gtk3::Object\' with value undef', 'class_name', 'Tsuyoshi::Gtk3', 'attribute_name', 'root_window', 'value', undef) called at accessor Tsuyoshi::Gtk3::root_window (defined at ./gtk3_moose.pl line 44) line 22 # Tsuyoshi::Gtk3::root_window('Tsuyoshi::Gtk3=HASH(0x9508500)') called at gtk3_moose.pl line 13 # Tsuyoshi::Gtk3::BUILD('Tsuyoshi::Gtk3=HASH(0x9508500)', 'HASH(0x9b0d168)') called at constructor Tsuyoshi::Gtk3::new (defined at ./gtk3_moose.pl line 54) line 75
#    Tsuyoshi::Gtk3::new('Tsuyoshi::Gtk3') called at gtk3_moose.pl line 63

I tried withou Builder, and this worked fine:
has 'root_window'    => (
    is    => 'rw',
    isa    => 'Gtk3::Window',
    default    => sub { return Gtk3::Window->new; },
    trigger    => sub {
        my ( $self ) = @_;
        $self->root_window->signal_connect( destroy => \&quit_app );
    }
);

I attached two test cases, one with Builder, which does not work, and other without Builder, which works.
If you can give me any guidance, I would be grateful.
Thank you.

Tsuyoshi

Attachment: new_test.ui
Description: application/designer

Attachment: gtk3_moose_with_builder.pl
Description: Perl program

Attachment: gtk3_moose_without_builder.pl
Description: Perl program



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