NAME
Developer::Dashboard::System::Menu - native system-menu adapter
PURPOSE
Provides the Perl-facing API for creating and controlling a native operating system menu through the Developer Dashboard XS bundle and its platform helper.
WHY IT EXISTS
Dashboard indicators need a persistent native menu on supported desktop platforms. This module validates menu definitions, projects callbacks and icons into a platform-neutral JSON protocol, dispatches native click events back to Perl, and owns the menu run-loop lifecycle without introducing a second extension or an external Perl package dependency.
WHEN TO USE
Use this module when an application already has a graphical desktop session and needs a native system-menu surface. It is not a browser widget and does not provide a useful visible interface in a headless process. Higher-level Dashboard code should normally use the Developer::Dashboard::SystemMenu adapter and its runner rather than constructing this low-level menu directly.
HOW TO USE
Load the module after the Dashboard XS bundle is built. Call menu to obtain the process-local menu object, then call run with an array reference of menu item definitions. Each item is a hash reference with required name and icon scalar values and optional click, click_stay, or nested menu items. A nested menu may be an array reference or a hash reference with items and an optional default click_stay value. Names must be unique in the complete menu tree. A menu entry cannot define both menu and click.
run owns the native event loop until stop is requested or the helper terminates. A click code reference is called with its item object. A plain scalar click value is treated as the replacement icon name on activation. Callback errors are reported as Perl warnings and do not silently disappear. Item icon reads the current icon with no arguments and updates it with one scalar argument. remove deletes a named item, and item remove removes that item by name. Invalid settings, duplicate names, helper failures, and invalid item operations raise explicit errors.
WHAT USES IT
Developer::Dashboard::SystemMenu builds menu data from configured indicators. Developer::Dashboard::SystemMenu::Runner starts this menu in a controlled GoRoutine worker and requests shutdown when the Dashboard runtime stops. The XSUBs are registered in the existing Dashboard XS bundle.
EXAMPLES
Create a basic menu with a callback and a nested entry:
use Developer::Dashboard::System::Menu;
my $menu = menu();
$menu->run([
{
name => 'build',
icon => '✅',
click => sub {
my ($item) = @_;
$item->icon('⏳');
},
},
{
name => 'project',
icon => '📁',
menu => [
{ name => 'tests', icon => '🧪', click => '🔄' },
],
},
]);
Request shutdown from another active control path while run is blocked:
my $menu = menu();
# The menu has already entered run() on its owning control path.
# A shutdown callback or supervisor then calls:
$menu->stop();
$menu->remove('sync');
Read or change an item icon from a callback:
my $current_icon = $item->icon();
$item->icon('✅');
INPUTS AND OUTPUTS
menu takes no arguments and returns the process-local menu object. run takes an array reference of menu definitions and returns the menu object after its run loop exits. remove takes a non-empty item name and returns the menu object. stop takes no arguments and returns the menu object. Item name, menu, remove, and icon methods return the item name, root menu object, item object, and current or updated icon respectively. Mutating methods report invalid input or native transport failures by dying.