igoryonya has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to learn Prima and trying to make a window menu by writing the code from the Prima's official book example:
#!/usr/bin/env perl use Prima qw(Application Buttons MsgBox); my $window = Prima::MainWindow->new( text=>'Hello world!', menuItems=>[ '~File', [ ['~Open', 'Ctrl+O', '^O', sub{message('open!')}], ['~Save as...', sub{message('save as!')}] ] ], size=>[200, 200] ); $window->insert(Button=> text=>'Click me', growMode=>gm::Center, onClick=>sub{message("Hello!")} ); run Prima;
But the menu doesn't appear on the window and in console, there is an error message:

menu build error: submenu is not an array at /usr/local/lib/x86_64-linux-gnu/perl/5.30.0/Prima/Classes.pm line 180.

I've broke my head, trying to figure it out. I don't see any problem with the Array structure, building the menu.

Replies are listed 'Best First'.
Re: Prima Menu
by bliako (Abbot) on Aug 25, 2021 at 06:01 UTC

    don't break your head, that's painful!

    Try to spot the difference with the example from the synopsis (hint: menuItems):

    use Prima; use Prima::Application; my $window = Prima::Window-> new( menuItems => [ [ '~File' => [ [ '~Open', 'Ctrl+O', '^O', \&open_file ], [ '-save_file', '~Save', km::Ctrl | ord('s'), sub { save_fi +le() } ], [], [ '~Exit', 'Alt+X', '@X', sub { exit } ], ]], [ '~Options' => [ [ '*option1' => 'Checkable option' => sub { $_[0]-> menu-> + toggle( $_[1]) }], [ '*@option2' => 'Checkable option' => sub {}], # same ]], [], [ '~Help' => [ [ 'Show help' => sub { $::application-> open_help("file://$ +0"); }], ]], ], ); sub open_file { # enable 'save' menu item $window-> menu-> save_file-> enable; } $window-> popupItems( $window-> menuItems);

    bw, bliako