http://www.perlmonks.org?node_id=1129292
stefbv has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on porting a wxPerl GUI application from Moose to Moo. All works just fine, excepting the Menu, here is the code to show the problem:

### MyMenuBar package MyMenuBar; use Moo; #use Moose; #use MooseX::NonMoose::InsideOut; use Wx qw(:everything); extends 'Wx::MenuBar'; sub FOREIGNBUILDARGS { return (); } sub BUILD { my $self = shift; $self->Append( MenuBar::Item->new, 'Item'); # comment this line to # get the object info return $self; } ### MenuBar::Item package MenuBar::Item; use Moo; #use Moose; #use MooseX::NonMoose::InsideOut; use Wx qw(:everything); extends 'Wx::MenuItem'; has 'item_quit' => ( is => 'ro', lazy => 1, builder => '_build_item_quit', ); sub _build_item_quit { my $self = shift; return Wx::MenuItem->new( $self, wxID_EXIT, '&Quit', 'Quit', wxITEM_NORMAL, undef # if defined, this is a sub-menu ); } sub FOREIGNBUILDARGS { return (); # Wx::Menu->new() takes no arguments } sub BUILD { my $self = shift; $self->Append( $self->item_quit ); return $self; } ### MyStatusBar package MyStatusBar; use Moo; #use Moose; #use MooseX::NonMoose::InsideOut; use Wx qw(:everything); extends 'Wx::StatusBar'; sub FOREIGNBUILDARGS { my $self = shift; my %args = @_; return ( $args{parent}, -1, $args{style}, $args{name}, ); } ### MyFrame package MyFrame; use Moo; #use Moose; #use MooseX::NonMoose::InsideOut; use Data::Printer; use Wx qw(:everything); extends 'Wx::Frame'; use MyStatusBar; use MyMenuBar; sub FOREIGNBUILDARGS { my $self = shift; my %args = @_; return ( undef, -1, 'Wx with Moo', [ -1, -1 ], [ -1, -1 ], wxDEFAULT_FRAME_STYLE, ); } sub BUILD { my $self = shift; my $panel = Wx::Panel->new( $self, -1, [ -1, -1 ], [ -1, -1 ] ); my $sizer = Wx::BoxSizer->new(wxVERTICAL); my $status_bar = MyStatusBar->new( parent => $self, name => 'sb', style => 0, ); p $status_bar; $status_bar->SetStatusText('Status', 0); my $menu_bar = MyMenuBar->new; p $menu_bar; $self->SetMenuBar($menu_bar); $panel->SetSizerAndFit($sizer); return $self; } ### main package main; use 5.010; use strict; use warnings; use Wx; my $app = Wx::SimpleApp->new; my $frame = MyFrame->new; $frame->Show(1); $app->MainLoop;

and the output is:

MyStatusBar { Parents Wx::StatusBar public methods (2) : FOREIGNBUILDARGS, new private methods (0) internals: {} } Can't locate object method "item_quit" via package "Wx::Menu" at wx-mo +o-menu-problem.pl line 58.

If I comment the line 18, it gets to the point to also dump the object info for the menu:

Wx::MenuBar { Parents Wx::Window public methods (28) : Append, Check, Enable, EnableTop, FindItem, +FindMenu, FindMenuItem, ... private methods (0) internals: 49230256 }

The problem is obvious, the class should be MyMenuBar not Wx::MenuBar, but with Wx::StatusBar is all OK, what I'm doing wrong?

It also works fine if instead of Moo, I use Moose and MooseX::NonMoose::InsideOut.

Thank you,
Stefan

Update: Environment: Citrus Perl 5.016003, Wx 0,9927, wxWidgets 2.9.4

Update2: Fix extended class, thanks Anonymous Monk.