Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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 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,

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

Update2: Fix extended class, thanks Anonymous Monk.

In reply to Different behavior for Moo and Moose with Wx? by stefbv

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (10)
    As of 2019-10-18 14:23 GMT
    Find Nodes?
      Voting Booth?