Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://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 +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.


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

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-04-24 11:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found