view release on metacpan or search on metacpan
preserved, with two inherent adjustments: no true parallelism
(callbacks run interleaved) and no force-kill of a running routine
(cooperative cancel instead).
- Migrate the SSL frontend to pump-driven client state machines and
run the system menu in its own worker process instead of a GoRoutine.
- Rewrite the thirteen goroutine test files to the new semantics.
6.30 2026-11-08
- Allow headless Linux CPAN builds to omit the optional GTK/Ayatana System
Menu helper with a visible notice; keep Linux CI strict and skip only the
helper-binary assertion when its development modules are unavailable.
- Add configure regression coverage for available and unavailable native
dependencies and document the CPAN tester behavior.
6.29 2026-11-06
- Install the GTK and Ayatana development packages required by the Linux
coverage workflow before building the native System Menu helper.
- Refresh workflow regression contracts for the five-platform coverage
chain and document its Linux native build dependencies.
6.28 2026-11-03
- Replace an ineffective Scalar::Util monkeypatch in the GoRoutine coverage
test with an unsupported regexp-reference contract assertion, and remove
the unreachable reftype fallback so coverage remains behavior-driven.
- Document the local act runner's init option for process cleanup tests.
verify that prerequisite before installing the distribution.
- Pin the full blank-environment install to the same threaded Perl 5.44
build, check `Config{useithreads}`, and provide GTK/Ayatana build headers.
6.20 2026-11-01
- Export the complete GoRoutine API, including process_exited, beside d2
through use Developer::Dashboard. Preserve the GoRoutine source syntax
filter for callers and add Docker coverage for the imported routines,
shared values, channels, and child-process lifecycle.
- Wire the opt-in native System Menu into the foreground web-service
lifecycle. The staged runtime now supplies merged configuration and the
indicator store to SystemMenu::Runner; GoRoutine-managed menu workers are
stopped and joined on service return or error. Add Docker lifecycle and
runtime-wiring regression tests, and document that native visibility still
requires hosted platform verification.
- Repair hosted native builds: install GTK/Ayatana development packages on
Linux workflow runners and the published image; build the macOS helper
with ARC and deprecated-API diagnostics as errors; and omit unsupported
Devel::Cover installation from Windows test dependencies.
- Keep the CPAN audit tool installation running after an earlier build-gate
failure, so the always-run declared dependency-chain audit reports its own
result instead of failing only because CPAN::Audit was never installed.
HtmlEscape.xs view on Meta::CPAN
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <string.h>
#include "Native.h"
#include "GoRoutineProcessNative.h"
#include "SystemMenuNative.h"
#include "GoRoutineEvent.h"
/* Native.xs is included at the end to keep every XSUB in one boot module. */
MODULE = Developer::Dashboard PACKAGE = Developer::Dashboard::HtmlEscape
PROTOTYPES: DISABLE
# _xs_escape_html(input)
# Escapes the three HTML body-sensitive ASCII bytes in one native pass.
# Input: an undefined or non-reference Perl scalar.
HtmlEscape.xs view on Meta::CPAN
if (SvTAINTED(input)) {
SvTAINTED_on(RETVAL);
}
}
OUTPUT:
RETVAL
INCLUDE: Native.xs
INCLUDE: GoRoutine012.xs
INCLUDE: GoRoutineProcess.xs
INCLUDE: SystemMenu.xs
MANIFEST.SKIP
META.json
META.yml
Makefile.PL
Native.h
Native.xs
README
README.md
SECURITY.md
SECURITY.pod
SystemMenu.xs
SystemMenuNative.h
apkfile
app.psgi
aptfile
bin/d2
brewfile
cpan-audit-exclusions.txt
cpanfile
dist.ini
dnfile
doc/architecture.md
lib/Developer/Dashboard/ProcessSupervision.pm
lib/Developer/Dashboard/Prompt.pm
lib/Developer/Dashboard/Runtime/Result.pm
lib/Developer/Dashboard/RuntimeManager.pm
lib/Developer/Dashboard/SKILLS.pm
lib/Developer/Dashboard/SeedSync.pm
lib/Developer/Dashboard/SessionStore.pm
lib/Developer/Dashboard/SkillDispatcher.pm
lib/Developer/Dashboard/SkillManager.pm
lib/Developer/Dashboard/StreamDrain.pm
lib/Developer/Dashboard/System/Menu.pm
lib/Developer/Dashboard/SystemMenu.pm
lib/Developer/Dashboard/SystemMenu/Runner.pm
lib/Developer/Dashboard/TextUtils.pm
lib/Developer/Dashboard/TimeUtils.pm
lib/Developer/Dashboard/UpdateManager.pm
lib/Developer/Dashboard/Version.pm
lib/Developer/Dashboard/Web/App.pm
lib/Developer/Dashboard/Web/DancerApp.pm
lib/Developer/Dashboard/Web/Server.pm
lib/Developer/Dashboard/Web/Server/Daemon.pm
lib/Developer/Dashboard/Zipper.pm
native/system_menu_helper_linux.c
"version" : "6.31"
},
"Developer::Dashboard::SkillManager" : {
"file" : "lib/Developer/Dashboard/SkillManager.pm",
"version" : "6.31"
},
"Developer::Dashboard::StreamDrain" : {
"file" : "lib/Developer/Dashboard/StreamDrain.pm",
"version" : "6.31"
},
"Developer::Dashboard::System::Menu" : {
"file" : "lib/Developer/Dashboard/System/Menu.pm",
"version" : "6.31"
},
"Developer::Dashboard::System::Menu::Item" : {
"file" : "lib/Developer/Dashboard/System/Menu.pm",
"version" : "6.31"
},
"Developer::Dashboard::SystemMenu" : {
"file" : "lib/Developer/Dashboard/SystemMenu.pm",
"version" : "6.31"
},
"Developer::Dashboard::SystemMenu::Runner" : {
"file" : "lib/Developer/Dashboard/SystemMenu/Runner.pm",
"version" : "6.31"
},
"Developer::Dashboard::TextUtils" : {
"file" : "lib/Developer/Dashboard/TextUtils.pm",
"version" : "6.31"
},
"Developer::Dashboard::TimeUtils" : {
"file" : "lib/Developer/Dashboard/TimeUtils.pm",
"version" : "6.31"
},
version: '6.31'
Developer::Dashboard::SkillDispatcher:
file: lib/Developer/Dashboard/SkillDispatcher.pm
version: '6.31'
Developer::Dashboard::SkillManager:
file: lib/Developer/Dashboard/SkillManager.pm
version: '6.31'
Developer::Dashboard::StreamDrain:
file: lib/Developer/Dashboard/StreamDrain.pm
version: '6.31'
Developer::Dashboard::System::Menu:
file: lib/Developer/Dashboard/System/Menu.pm
version: '6.31'
Developer::Dashboard::System::Menu::Item:
file: lib/Developer/Dashboard/System/Menu.pm
version: '6.31'
Developer::Dashboard::SystemMenu:
file: lib/Developer/Dashboard/SystemMenu.pm
version: '6.31'
Developer::Dashboard::SystemMenu::Runner:
file: lib/Developer/Dashboard/SystemMenu/Runner.pm
version: '6.31'
Developer::Dashboard::TextUtils:
file: lib/Developer/Dashboard/TextUtils.pm
version: '6.31'
Developer::Dashboard::TimeUtils:
file: lib/Developer/Dashboard/TimeUtils.pm
version: '6.31'
Developer::Dashboard::UpdateManager:
file: lib/Developer/Dashboard/UpdateManager.pm
version: '6.31'
Makefile.PL view on Meta::CPAN
my %test_requires = ( 'Test::Harness' => '3.48' );
$test_requires{'Devel::Cover'} = 0 if $^O ne 'MSWin32';
WriteMakefile(
NAME => 'Developer::Dashboard',
MIN_PERL_VERSION => '5.038',
VERSION_FROM => 'lib/Developer/Dashboard/Version.pm',
XS => { 'HtmlEscape.xs' => 'HtmlEscape.c' },
OBJECT => 'HtmlEscape$(OBJ_EXT)',
depend => {
'HtmlEscape.c' => 'GoRoutine012.xs GoRoutineProcess.xs GoRoutineEvent.h GoRoutineProcessNative.h Native.xs SystemMenu.xs SystemMenuNative.h',
'HtmlEscape$(OBJ_EXT)' => 'GoRoutineEvent.h SystemMenuNative.h',
},
LIBS => [ $^O eq 'linux' ? '-ldl' : q{} ],
CCFLAGS => $Config{ccflags} . ( $^O eq 'MSWin32' ? q{} : ' -pthread' ),
ABSTRACT => 'Project-neutral local developer dashboard runtime',
AUTHOR => 'Developer Dashboard Contributors',
EXE_FILES => [
'bin/d2',
],
PREREQ_PM => {
'strict' => 0,
Makefile.PL view on Meta::CPAN
my ($name) = @_;
for my $directory ( File::Spec->path ) {
next if !defined $directory || $directory eq q{};
my $candidate = File::Spec->catfile( $directory, $name );
return $candidate if -f $candidate && -x $candidate;
}
return;
}
# _linux_menu_helper_unavailable_reason()
# Checks whether the Linux System Menu helper's compile-time pkg-config modules exist.
# Input: none; reads PATH and runs pkg-config when available.
# Output: a visible reason string when the optional helper cannot be built, or undef.
sub _linux_menu_helper_unavailable_reason {
my $pkg_config = _program_in_path('pkg-config');
return 'pkg-config was not found on PATH' if !defined $pkg_config;
my $status = system { $pkg_config } $pkg_config, '--exists',
'ayatana-appindicator3-0.1', 'gtk+-3.0';
die "Unable to execute pkg-config at '$pkg_config': $!\n" if $status == -1;
die "pkg-config terminated by signal " . ( $status & 127 ) . "\n"
Makefile.PL view on Meta::CPAN
}
elsif ( $^O eq 'darwin' ) {
$helper_source = 'native/system_menu_helper_mac.m';
$helper_compile = q{$(CC) $(CCFLAGS) -fobjc-arc -Werror=deprecated-declarations -o "$@" native/system_menu_helper_mac.m -framework AppKit -framework Foundation};
}
elsif ( $^O eq 'MSWin32' ) {
$helper_source = 'native/system_menu_helper_win.c';
$helper_compile = q{$(CC) $(CCFLAGS) -o "$@" native/system_menu_helper_win.c -lshell32 -luser32 -lgdi32};
}
else {
die "System Menu native helper is unsupported on $^O\n";
}
my $helper_rules = q{};
if ( defined $helper_unavailable_reason ) {
my $install_hint = 'Install pkg-config, libayatana-appindicator3-dev, and libgtk-3-dev.';
if ( ( $ENV{DD_REQUIRE_SYSTEM_MENU_HELPER} // q{} ) eq '1' ) {
die "Required Linux System Menu helper cannot be built: "
. "$helper_unavailable_reason. $install_hint\n";
}
print "Optional Linux System Menu helper was not built: "
. "$helper_unavailable_reason. $install_hint\n";
}
else {
my $helper_target = '$(INST_ARCHAUTODIR)/' . $helper_name;
$helper_rules = join "\n",
'.PHONY: build-system-menu-helper clean-system-menu-helper',
'all :: build-system-menu-helper',
"build-system-menu-helper: $helper_target",
"$helper_target: $helper_source",
"\t\$(MKPATH) \$(INST_ARCHAUTODIR)",
Makefile.PL view on Meta::CPAN
Makefile.PL - configure and generate the Developer::Dashboard build Makefile
=head1 DESCRIPTION
This script configures the Developer::Dashboard Perl distribution with
ExtUtils::MakeMaker. It declares runtime and configuration prerequisites,
version metadata, executable scripts, XS extension sources, shared assets, and
repository metadata. Its MakeMaker postamble installs private command helpers
and removes its generated local-library launcher during C<make clean>.
On Linux, the System Menu helper is built when C<pkg-config> can find the
Ayatana AppIndicator3 and GTK3 development modules. If either module is absent,
configuration prints a notice and omits that optional helper target so CPAN
testers can build and test the distribution without desktop development
headers. The System Menu feature still reports a missing helper when invoked.
Set C<DD_REQUIRE_SYSTEM_MENU_HELPER=1> to make missing modules a configuration
failure; the Linux coverage workflow uses this setting so its native helper
check cannot be skipped.
When local::lib modules are present under C<.perl5> or the current user's
C<perl5> directory, the generated Makefile runs Perl commands through a small
generated launcher. The user's directory is resolved from C<HOME> on Unix or
C<USERPROFILE> on Windows; if neither variable exists, only C<.perl5> is
considered. The launcher adds the active local-library directories to
C<PERL5LIB> before running Perl and forwarding the original arguments. Child
If `indicator.icon` contains Template Toolkit syntax such as `[% a %]`, the
collector runner now treats collector `stdout` as JSON, decodes it through
`JSON::XS`, exposes hash keys as direct template variables plus `data`, and
persists the rendered icon as the live indicator value. Invalid JSON or TT
render failures are explicit collector errors: the collector `stderr` records
the template problem and the indicator stays red instead of silently falling
back.
### System menu indicator configuration
`Developer::Dashboard::SystemMenu->items_for_platform` projects
configured indicator names and their current icons for the `macos`,
`windows`, or `ubuntu` selector. Each platform selector is opt-in; a missing
or false value disables that item. Invalid values for any supported selector
are rejected even when the current host is another platform. The projection
preserves configuration order and does not start a native menu by itself. The
private `web-foreground` runtime supplies merged configuration and the shared
indicator store to `Developer::Dashboard::SystemMenu::Runner`. The runner
starts the menu only when an indicator is enabled for the current host and
keeps the helper active for the foreground web-service lifetime. It stops and
joins the GoRoutine worker when the service returns or fails; disabled or
unsupported platform settings do not load the native adapter. The existing
`d2 ps1` output remains unchanged.
The native System::Menu adapter starts the platform helper in a controlled
GoRoutine worker. On Ubuntu, the helper uses Ayatana AppIndicator3 and a GTK
menu; rendered status icons are kept in a private temporary icon-theme
directory and removed when the helper shuts down. Building from source
requires the Ayatana AppIndicator3 and GTK3 development packages; runtime
requires a desktop session with AppIndicator support. The helper reports a
clear error when no desktop session is available. Source and compile tests do
not prove that a desktop shell visibly displayed the menu; hosted platform
verification is required for each supported operating system. Linux CI and
the published Docker image install those native development packages before
building the helper. The macOS helper uses ARC and treats deprecated AppKit APIs
coverage suite. Unix build and coverage steps use Bash; Windows amd64 uses
PowerShell, and Windows arm64 uses the native CLANGARM64 Perl and toolchain. The
Windows jobs check their runner architectures and fail if the native target is
not available; they do not report skipped native tests as a pass.
Checkout dependencies are installed into `local/lib/perl5`. The Linux
workflow adds that directory to `PERL5LIB` before invoking `perl Makefile.PL`,
because the configure-time `File::ShareDir::Install` dependency is needed
before MakeMaker can create `blib`. Linux also installs
`libayatana-appindicator3-dev` and `libgtk-3-dev` before building the native
System Menu helper; these provide the pkg-config libraries and headers required
by `native/system_menu_helper_linux.c`. On Linux, `Makefile.PL` checks for
both pkg-config modules. If either is unavailable, it prints a notice and omits
the optional helper target so CPAN testers without desktop headers can still
build and test the distribution; invoking the System Menu without its helper
still fails clearly. Set `DD_REQUIRE_SYSTEM_MENU_HELPER=1` to require the
native helper, as the Linux coverage workflow does. The Windows builds use
Perl's configured path separator when assembling the same local library path.
Workflow regression tests check these setup requirements.
The Linux coverage gate passes `blib/arch` and the local dependency library
through `PERL5LIB` after compiling the extension. It instruments `lib/` rather
than copied `blib/lib` sources. This ensures child Perl processes load the
native extension built by the current checkout and keeps coverage from counting
duplicate source copies.
SystemMenu.xs view on Meta::CPAN
#include "SystemMenuNative.h"
MODULE = Developer::Dashboard PACKAGE = Developer::Dashboard::System::Menu
PROTOTYPES: DISABLE
int
_start()
PREINIT:
#ifdef _WIN32
SECURITY_ATTRIBUTES sa;
HANDLE child_stdin_read = NULL;
HANDLE parent_stdin_write = NULL;
SystemMenu.xs view on Meta::CPAN
ok = 1;
}
else {
#ifdef _WIN32
ZeroMemory(&sa, sizeof(sa));
sa.nLength = sizeof(sa);
sa.bInheritHandle = TRUE;
if (!find_helper_path(helper_path, sizeof(helper_path)/sizeof(helper_path[0]))) {
unlock_helper();
croak("cannot locate system_menu_helper.exe next to System::Menu bundle");
}
if (!CreatePipe(&child_stdin_read, &parent_stdin_write, &sa, 0) ||
!SetHandleInformation(parent_stdin_write, HANDLE_FLAG_INHERIT, 0) ||
!CreatePipe(&parent_stdout_read, &child_stdout_write, &sa, 0) ||
!SetHandleInformation(parent_stdout_read, HANDLE_FLAG_INHERIT, 0)) {
if (child_stdin_read) CloseHandle(child_stdin_read);
if (parent_stdin_write) CloseHandle(parent_stdin_write);
if (parent_stdout_read) CloseHandle(parent_stdout_read);
if (child_stdout_write) CloseHandle(child_stdout_write);
SystemMenu.xs view on Meta::CPAN
CloseHandle(pi.hThread);
CloseHandle(child_stdin_read);
CloseHandle(child_stdout_write);
helper_process = pi.hProcess;
helper_write = parent_stdin_write;
helper_read = parent_stdout_read;
ok = 1;
#else
if (!find_helper_path(helper_path, sizeof(helper_path))) {
unlock_helper();
croak("cannot locate system_menu_helper next to System::Menu bundle");
}
if (pipe(command_pipe) != 0) {
unlock_helper();
croak("command pipe() failed: %s", strerror(errno));
}
if (pipe(events_pipe) != 0) {
close(command_pipe[0]); close(command_pipe[1]);
unlock_helper();
croak("event pipe() failed: %s", strerror(errno));
}
SystemMenu.xs view on Meta::CPAN
if (helper_is_running_unlocked()) {
len = strlen(value);
#ifdef _WIN32
ok = write_all_win(helper_write, value, len) && write_all_win(helper_write, "\n", 1);
#else
ok = write_all_posix(helper_fd, value, len) && write_all_posix(helper_fd, "\n", 1);
#endif
if (!ok) close_helper_state_unlocked();
}
unlock_helper();
if (!ok) croak("System::Menu helper is not running or command write failed");
RETVAL = 1;
OUTPUT:
RETVAL
SV *
_read_events()
PREINIT:
char buf[8192];
SV *out;
#ifdef _WIN32
doc/native-xs-platform-workflow.md view on Meta::CPAN
from Git Bash selected its MSYS Perl, whose @INC lacks ExtUtils::MakeMaker,
even though the workflow's Windows Perl was installed correctly. Separate
Windows and Unix steps now keep each platform on its configured Perl and path
separator. The next hosted run exposed a separate Makefile.PL portability
defect: Windows supplied USERPROFILE but no HOME, and Makefile.PL interpolated
the missing HOME while searching for local::lib. Makefile.PL now prefers HOME,
falls back to USERPROFILE, and safely uses only `.perl5` if neither is set. The
Docker regression covers all three cases. Hosted verification of this fix is
pending.
The active Linux coverage job builds the Linux System Menu helper as part of
the native XS extension. Before `make`, it installs both
`libayatana-appindicator3-dev` and `libgtk-3-dev`; these packages provide the
`ayatana-appindicator3-0.1` and `gtk+-3.0` pkg-config metadata and headers used
by `native/system_menu_helper_linux.c`. This strict setting keeps CI from
silently omitting the helper if dependency installation or pkg-config
detection fails. Ordinary Linux source-distribution builds may omit this
optional desktop helper with an explicit configure notice when the modules are
unavailable, allowing headless CPAN testers to run the rest of the test suite.
macOS continues to install Mac::FSEvents as its platform-specific event
doc/system-menu-indicators.md view on Meta::CPAN
# System menu indicator configuration
`Developer::Dashboard::SystemMenu->items_for_platform` is a deterministic
configuration projection. The private `web-foreground` runtime passes its
merged configuration and shared indicator store to
`Developer::Dashboard::SystemMenu::Runner`; the runner starts the menu only
when at least one current indicator is enabled for the host platform.
The method accepts the merged dashboard configuration, an array of current
indicator records, and a platform key. For each configured indicator it reads
the matching opt-in selector from `indicator`:
1. `macos`
2. `windows`
3. `ubuntu`
doc/system-menu-indicators.md view on Meta::CPAN
{ "name": "tests", "indicator": { "ubuntu": true } }
]
}
```
The projection is independent of AppKit, Windows notification-area APIs, and
GTK. It does not launch the native UI by itself. `d2 serve` launches its
foreground web-service process, which owns the menu worker for the service's
lifetime and stops and joins that worker on normal server exit or error. A
disabled or unsupported host selection does not load the native adapter, and
the existing `d2 ps1` output is unchanged. The native System::Menu
adapter starts the platform helper in a controlled GoRoutine worker and
forwards the projected entries while owning helper shutdown. On Ubuntu,
the helper uses Ayatana AppIndicator3 and a GTK menu; rendered status icons are
kept in a private temporary icon-theme directory and removed when the helper
shuts down. Building the helper requires the Ayatana AppIndicator3 and GTK3
development packages, and runtime requires a desktop session with AppIndicator
support. On Linux, `Makefile.PL` checks for both pkg-config modules and omits
the optional helper target with a visible notice when they are missing. This
allows CPAN testers without desktop development headers to build and test the
distribution; invoking the System Menu without its helper still reports a
clear error. Set `DD_REQUIRE_SYSTEM_MENU_HELPER=1` to make missing modules
fatal, as the Linux coverage workflow does.
The helper reports a clear error when no desktop session is available.
Source-contract and compile tests do not prove that a desktop shell visibly
displayed the menu.
The focused test runs inside the project development container:
```sh
d2 docker compose exec --workdir /work dev prove -lv t/239-system-menu-config.t t/241-system-menu-runner.t t/242-system-menu-bundle.t t/243-system-menu-linux-indicator-api.t
lib/Developer/Dashboard.pm view on Meta::CPAN
If C<indicator.icon> contains Template Toolkit syntax such as C<[% a %]>, the
collector runner now treats collector C<stdout> as JSON, decodes it through
C<JSON::XS>, exposes hash keys as direct template variables plus C<data>, and
persists the rendered icon as the live indicator value. Invalid JSON or TT
render failures are explicit collector errors: the collector C<stderr> records
the template problem and the indicator stays red instead of silently falling
back.
=head3 System menu indicator configuration
C<Developer::Dashboard::SystemMenu-E<gt>items_for_platform> projects
configured indicator names and their current icons for the C<macos>,
C<windows>, or C<ubuntu> selector. Each platform selector is opt-in; a missing
or false value disables that item. Invalid values for any supported selector
are rejected even when the current host is another platform. The projection
preserves configuration order and does not start a native menu by itself. The
private C<web-foreground> runtime supplies merged configuration and the shared
indicator store to C<Developer::Dashboard::SystemMenu::Runner>. The runner
starts the menu only when an indicator is enabled for the current host and
keeps the helper active for the foreground web-service lifetime. It stops and
joins the GoRoutine worker when the service returns or fails; disabled or
unsupported platform settings do not load the native adapter. The existing
C<d2 ps1> output remains unchanged.
The native System::Menu adapter starts the platform helper in a controlled
GoRoutine worker. On Ubuntu, the helper uses Ayatana AppIndicator3 and a GTK
menu; rendered status icons are kept in a private temporary icon-theme
directory and removed when the helper shuts down. Building from source
requires the Ayatana AppIndicator3 and GTK3 development packages; runtime
requires a desktop session with AppIndicator support. The helper reports a
clear error when no desktop session is available. Source and compile tests do
not prove that a desktop shell visibly displayed the menu; hosted platform
verification is required for each supported operating system. Linux CI and
the published Docker image install those native development packages before
building the helper. The macOS helper uses ARC and treats deprecated AppKit APIs
lib/Developer/Dashboard.pm view on Meta::CPAN
coverage suite. Unix build and coverage steps use Bash; Windows amd64 uses
PowerShell, and Windows arm64 uses the native CLANGARM64 Perl and toolchain. The
Windows jobs check their runner architectures and fail if the native target is
not available; they do not report skipped native tests as a pass.
Checkout dependencies are installed into C<local/lib/perl5>. The Linux
workflow adds that directory to C<PERL5LIB> before invoking C<perl Makefile.PL>,
because the configure-time C<File::ShareDir::Install> dependency is needed
before MakeMaker can create C<blib>. Linux also installs
C<libayatana-appindicator3-dev> and C<libgtk-3-dev> before building the native
System Menu helper; these provide the pkg-config libraries and headers required
by C<native/system_menu_helper_linux.c>. On Linux, C<Makefile.PL> checks for
both pkg-config modules. If either is unavailable, it prints a notice and omits
the optional helper target so CPAN testers without desktop headers can still
build and test the distribution; invoking the System Menu without its helper
still fails clearly. Set C<DD_REQUIRE_SYSTEM_MENU_HELPER=1> to require the
native helper, as the Linux coverage workflow does. The Windows builds use
Perl's configured path separator when assembling the same local library path.
Workflow regression tests check these setup requirements.
The Linux coverage gate passes C<blib/arch> and the local dependency library
through C<PERL5LIB> after compiling the extension. It instruments C<lib/> rather
than copied C<blib/lib> sources. This ensures child Perl processes load the
native extension built by the current checkout and keeps coverage from counting
duplicate source copies.
lib/Developer/Dashboard/System/Menu.pm view on Meta::CPAN
package Developer::Dashboard::System::Menu;
use strict;
use warnings;
use Exporter 'import';
use Encode ();
use JSON::XS ();
use Developer::Dashboard::Version ();
our $VERSION = '6.31';
our @EXPORT = qw(menu);
require Developer::Dashboard::HtmlEscape;
die "Developer::Dashboard XS bundle lacks System::Menu support\n"
unless $Developer::Dashboard::HtmlEscape::XS_LOADED
&& __PACKAGE__->can('_start');
my $DEFAULT;
my $NEXT_ID = 1;
my %RUNTIME;
sub menu {
if (!$DEFAULT) {
my $id = join('-', $$, $NEXT_ID++);
$DEFAULT = bless { id => $id }, __PACKAGE__;
}
return $DEFAULT;
}
sub _id {
my ($self) = @_;
die "invalid System::Menu object\n"
unless ref($self) && defined($self->{id}) && length("$self->{id}");
return "$self->{id}";
}
sub _runtime {
my ($self) = @_;
return $RUNTIME{ $self->_id };
}
sub _text {
lib/Developer/Dashboard/System/Menu.pm view on Meta::CPAN
my $item = bless {
root => $self,
parent => $parent,
name => $name,
icon => $icon,
click => $click,
click_stay => $click_stay,
children => [],
removed => 0,
}, 'Developer::Dashboard::System::Menu::Item';
$items->{$name} = $item;
my %native = (
name => $name,
icon => $icon,
click_stay => $click_stay ? JSON::XS::true : JSON::XS::false,
);
if (exists $spec->{click}) {
lib/Developer/Dashboard/System/Menu.pm view on Meta::CPAN
$rt->{event_buffer} .= $chunk;
while ($rt->{event_buffer} =~ s/\A([^\n]*)\n//) {
my $line = $1;
$line =~ s/\r\z//;
next unless length $line;
my $event = eval { JSON::XS->new->utf8->decode($line) };
if (!$event || ref($event) ne 'HASH') {
warn "Developer::Dashboard::System::Menu: invalid helper event\n";
next;
}
next unless ($event->{event} // '') eq 'click';
my $name = $event->{name};
next unless defined $name;
my $item = $rt->{items}{$name};
next unless $item && !$item->{removed};
my $click = $item->{click};
next unless defined $click;
if (ref($click) eq 'CODE') {
my $ok = eval { $click->($item); 1 };
warn "Developer::Dashboard::System::Menu: click '$name' failed: $@"
unless $ok;
}
else {
my $ok = eval { $item->icon($click); 1 };
warn "Developer::Dashboard::System::Menu: click '$name' update failed: $@"
unless $ok;
}
last unless $rt->{active};
}
return 1;
}
# Purpose: stop the native helper when Perl exits with a menu runtime still active.
# Input: none; reads the module's active runtime registry and native helper state.
# Output: true when active-runtime cleanup was attempted, otherwise false.
sub _shutdown_active_helpers {
return 0 if !grep { $_->{active} } values %RUNTIME;
my $ok = eval {
_stop() if _running();
1;
};
warn "Developer::Dashboard::System::Menu: shutdown cleanup failed: $@"
if !$ok;
return 1;
}
END {
_shutdown_active_helpers();
}
package Developer::Dashboard::System::Menu::Item;
use strict;
use warnings;
sub name { return $_[0]{name} }
sub icon {
my ($self, @args) = @_;
return $self->{icon} unless @args;
die "icon() takes exactly one value\n" unless @args == 1;
lib/Developer/Dashboard/System/Menu.pm view on Meta::CPAN
}
1;
__END__
=encoding UTF-8
=head1 NAME
Developer::Dashboard::System::Menu - native system-menu adapter
=head1 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.
=head1 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.
=head1 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 C<Developer::Dashboard::SystemMenu>
adapter and its runner rather than constructing this low-level menu directly.
=head1 HOW TO USE
Load the module after the Dashboard XS bundle is built. Call C<menu> to obtain
the process-local menu object, then call C<run> with an array reference of menu
item definitions. Each item is a hash reference with required C<name> and
C<icon> scalar values and optional C<click>, C<click_stay>, or nested C<menu>
items. A nested C<menu> may be an array reference or a hash reference with
C<items> and an optional default C<click_stay> value. Names must be unique in
lib/Developer/Dashboard/System/Menu.pm view on Meta::CPAN
terminates. A C<click> code reference is called with its item object. A plain
scalar C<click> value is treated as the replacement icon name on activation.
Callback errors are reported as Perl warnings and do not silently disappear.
Item C<icon> reads the current icon with no arguments and updates it with one
scalar argument. C<remove> deletes a named item, and item C<remove> removes
that item by name. Invalid settings, duplicate names, helper failures, and
invalid item operations raise explicit errors.
=head1 WHAT USES IT
C<Developer::Dashboard::SystemMenu> builds menu data from configured
indicators. C<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.
=head1 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('â³');
},
lib/Developer/Dashboard/SystemMenu.pm view on Meta::CPAN
package Developer::Dashboard::SystemMenu;
use strict;
use warnings;
use JSON::XS ();
our $VERSION = '6.31';
# items_for_platform(%args)
# Projects configured indicator declarations and current indicator states into
# the platform menu entries, without loading any native UI dependency.
lib/Developer/Dashboard/SystemMenu.pm view on Meta::CPAN
return \@items;
}
1;
__END__
=head1 NAME
Developer::Dashboard::SystemMenu - project indicators into an operating-system menu
=head1 PURPOSE
This module is the configuration and presentation boundary between the
Developer Dashboard indicator store and an operating-system menu adapter. It
keeps menu selection deterministic and testable without loading a native
framework during ordinary command startup.
=head1 WHY IT EXISTS
The Dashboard already records named indicators and their current display
icons. The foreground web service can show the enabled indicators in a native
operating-system menu while leaving the existing terminal prompt indicator
path unchanged. Separating this configuration projection from the native
adapter keeps Linux tests able to validate selection without pretending to
display a desktop menu.
=head1 WHEN TO USE
Use C<items_for_platform> from C<Developer::Dashboard::SystemMenu::Runner>
after loading merged Dashboard configuration and current indicator records.
The runner supports C<macos>, C<windows>, and C<ubuntu> selectors and owns the
native menu's blocking event loop on a controlled GoRoutine worker. The
foreground service must stop and join that worker during shutdown. Ordinary
commands must not start a blocking menu loop.
=head1 HOW TO USE
my $items = Developer::Dashboard::SystemMenu->items_for_platform(
config => $config,
indicators => \@indicator_states,
platform => 'windows',
);
The method returns an ordered array reference containing C<name> and C<icon>
for each configured indicator whose selector for the requested C<macos>,
C<windows>, or C<ubuntu> platform is enabled and has a current state. A missing
or false selector disables that item. Other platform names return an empty
array reference. Invalid configuration types and non-boolean values for any
supported platform selector are errors, even when the current host is not that
platform.
Pass the already merged configuration, current indicator records from
C<Developer::Dashboard::IndicatorStore>, and the platform key. The returned
array preserves declaration order and contains only currently available,
enabled indicators. To run a native menu, pass the merged configuration and
indicator store to C<Developer::Dashboard::SystemMenu::Runner> and use
C<run_with> around the foreground service callback.
=head1 EXAMPLES
{
indicators => [
{ name => 'build', indicator => { macos => 1, windows => 1 } },
{ name => 'tests', indicator => { ubuntu => 1 } },
],
}
lib/Developer/Dashboard/SystemMenu.pm view on Meta::CPAN
C<{ name =E<gt> 'tests', icon =E<gt> 'FAIL' }>, a C<macos> or C<windows> call
contains the C<build> entry, while an C<ubuntu> call contains C<tests>. This is
configuration projection only; it does not assert that any native menu is
started or visible. Native integration is opt-in per platform; Ubuntu requires
Ayatana AppIndicator3 and GTK3 development packages to build its helper.
=head1 WHAT USES IT
Configuration tests use this module on Linux to verify platform selection and
validation without launching a graphical process. The foreground service's
SystemMenu runner uses the projection before starting the bundled native
adapter. The projection module itself has no native dependencies and can be
loaded by commands on every platform.
=cut
lib/Developer/Dashboard/SystemMenu/Runner.pm view on Meta::CPAN
package Developer::Dashboard::SystemMenu::Runner;
use strict;
use warnings;
our $VERSION = '6.31';
use File::Basename qw(dirname);
use File::Spec;
use File::Temp qw(tempfile);
use JSON::XS ();
use Developer::Dashboard::GoRoutine qw(
process_running
spawn
terminate_process
wait_process
);
use Developer::Dashboard::SystemMenu;
# new(%args)
# Builds a platform-specific menu runner using the current indicator store.
# Input: config hash reference, store object, platform name, and optional
# worker command array reference for tests or specialized
# integrations (defaults to the private system-menu-foreground
# helper, which runs the native menu in its own process).
# Output: runner object; invalid dependencies are rejected with an error.
sub new {
my ( $class, %args ) = @_;
lib/Developer/Dashboard/SystemMenu/Runner.pm view on Meta::CPAN
# system-menu-foreground helper): the items are plain data, so they travel
# as JSON on the worker's stdin, and the parent never needs to pump an
# engine while the foreground web service blocks in its server loop.
# Input: runner object.
# Output: worker process id when started, or undef when the menu is disabled.
sub start {
my ($self) = @_;
die "system menu runner is already active\n" if $self->{menu_pid};
my $states = [ $self->{store}->list_indicators ];
my $items = Developer::Dashboard::SystemMenu->items_for_platform(
config => $self->{config},
indicators => $states,
platform => $self->{platform},
);
return if !@{$items};
my $items_json = JSON::XS->new->utf8->canonical->encode($items);
my ( $fh, $items_file ) = tempfile( UNLINK => 0 );
print {$fh} $items_json or die "Unable to write menu items file: $!";
close $fh or die "Unable to close menu items file: $!";
lib/Developer/Dashboard/SystemMenu/Runner.pm view on Meta::CPAN
my $helper = File::Spec->catfile( dirname($running_helper), '_dashboard-core' );
return [ $^X, $helper, 'system-menu-foreground' ];
}
1;
__END__
=head1 NAME
Developer::Dashboard::SystemMenu::Runner - opt-in native indicator menu lifecycle
=head1 PURPOSE
This module maps the configured Dashboard indicators for one operating system
and runs the native System Menu adapter in its own worker process. It keeps
the blocking native event loop out of the command's main execution path and
out of the GoRoutine engine: the menu worker is a plain process, so the
foreground web service never has to pump an engine while it blocks in its
server loop.
=head1 WHY IT EXISTS
System Menu's C<run> method owns a blocking native event loop. Running that loop
directly would prevent the Dashboard process from continuing its normal work.
This runner starts no native adapter when the current platform has no enabled
indicator, and it retains one explicit stop-and-wait lifecycle for enabled
menus. The worker is a separate process because the foreground callback blocks
in the web server (Starman for plain HTTP, the SSL frontend for HTTPS), and
neither server loop pumps the GoRoutine engine: a timer routine driving the
menu would never fire. The menu items are plain data (name and icon only, no
code references), so they travel to the worker as JSON on its stdin.
=head1 WHEN TO USE
Use this runner from the private C<web-foreground> runtime after configuration
layers and current indicator state have been loaded. Do not instantiate it
from lightweight CLI commands. Native desktop visibility and shutdown still
require hosted checks on each supported operating system.
=head1 HOW TO USE
my $runner = Developer::Dashboard::SystemMenu::Runner->new(
config => $config,
store => $indicator_store,
platform => 'macos',
);
my $worker = $runner->start;
# ... normal Dashboard runtime ...
$runner->stop if $worker;
C<start> returns undef and does not load the native adapter when there are no
visible configured indicators. When enabled, it projects current states in
lib/Developer/Dashboard/SystemMenu/Runner.pm view on Meta::CPAN
instead of the private helper; production callers omit it. A disabled
configuration returns no worker and does not spawn a process.
The foreground web service uses the wrapper form:
my $status = $runner->run_with(sub { $server->run });
=head1 WHAT USES IT
The runtime menu integration uses this class to connect merged configuration,
IndicatorStore state, the pure SystemMenu projection, and the native event loop.
The focused Docker regression test injects a fake worker command to verify
selection and lifecycle without claiming native UI behavior.
=cut
native/system_menu_helper_linux.c view on Meta::CPAN
{
size_t i;
if (!item) return;
for (i = 0; i < item->child_count; i++) item_free(item->children[i]);
if (item->indicator) {
app_indicator_set_status(item->indicator, APP_INDICATOR_STATUS_PASSIVE);
g_object_unref(item->indicator);
}
for (i = 0; i < item->icon_file_count; i++) {
if (item->icon_files[i] && unlink(item->icon_files[i]) != 0 && errno != ENOENT)
fprintf(stderr, "System::Menu: unable to remove indicator icon '%s': %s\n",
item->icon_files[i], strerror(errno));
free(item->icon_files[i]);
}
free(item->icon_files);
free(item->icon_file_times);
if (item->icon_theme_dir) {
if (rmdir(item->icon_theme_dir) != 0 && errno != ENOENT)
fprintf(stderr, "System::Menu: unable to remove icon directory '%s': %s\n",
item->icon_theme_dir, strerror(errno));
g_free(item->icon_theme_dir);
}
free(item->children);
free(item->name_utf8);
free(item->icon_utf8);
free(item);
}
static DDItem *find_item_rec(DDItem *item, const char *name)
native/system_menu_helper_linux.c view on Meta::CPAN
GError *error = NULL;
char *filename;
char *icon_name;
size_t i;
time_t now = time(NULL);
if (!item || !item->indicator) return;
if (!item->icon_theme_dir) {
item->icon_theme_dir = g_dir_make_tmp("developer-dashboard-menu-XXXXXX", &error);
if (!item->icon_theme_dir) {
fprintf(stderr, "System::Menu: unable to create indicator icon directory: %s\n",
error ? error->message : "unknown error");
if (error) g_error_free(error);
exit(2);
}
app_indicator_set_icon_theme_path(item->indicator, item->icon_theme_dir);
}
/* Remove icon assets only after a generous grace period: desktop shells
* request theme-path images asynchronously after the D-Bus update. */
for (i = 0; i < item->icon_file_count; ) {
if (now - item->icon_file_times[i] > 60) {
if (unlink(item->icon_files[i]) != 0 && errno != ENOENT)
fprintf(stderr, "System::Menu: unable to remove stale indicator icon '%s': %s\n",
item->icon_files[i], strerror(errno));
free(item->icon_files[i]);
item->icon_file_count--;
item->icon_files[i] = item->icon_files[item->icon_file_count];
item->icon_file_times[i] = item->icon_file_times[item->icon_file_count];
}
else {
i++;
}
}
pixbuf = render_text_icon(item->icon_utf8);
if (pixbuf) {
item->icon_sequence++;
g_icon_sequence++;
icon_name = g_strdup_printf("dd-icon-%lu", g_icon_sequence);
filename = g_strdup_printf("%s/%s.png", item->icon_theme_dir,
icon_name);
if (!gdk_pixbuf_save(pixbuf, filename, "png", &error, NULL)) {
fprintf(stderr, "System::Menu: unable to save indicator icon: %s\n",
error ? error->message : "unknown error");
if (error) g_error_free(error);
g_free(filename);
g_free(icon_name);
g_object_unref(pixbuf);
exit(2);
}
item->icon_files = (char **)xrealloc(item->icon_files,
sizeof(char *) * (item->icon_file_count + 1));
item->icon_file_times = (time_t *)xrealloc(item->icon_file_times,
native/system_menu_helper_linux.c view on Meta::CPAN
item->icon_file_count++;
app_indicator_set_icon_full(item->indicator, icon_name, item->name_utf8);
g_free(filename);
g_free(icon_name);
g_object_unref(pixbuf);
}
}
/* ------------------------------ menus ------------------------------------ */
static void on_menu_activate(GtkMenuItem *menu_item, gpointer data)
{
(void)menu_item;
emit_click((DDItem *)data);
}
static gboolean on_stay_button_press(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
DDItem *item = (DDItem *)data;
(void)widget;
if (event && event->button == 1) {
emit_click(item);
/* Stop GtkMenuShell from turning this into normal menu-item activation.
* That keeps the current menu/submenu tracking session visible. */
return TRUE;
}
return FALSE;
}
static GtkWidget *build_menu(DDItem *owner)
{
GtkWidget *menu = gtk_menu_new();
size_t i;
native/system_menu_helper_linux.c view on Meta::CPAN
/* The package's public convenience constructors are deprecated;
* initialize the same documented GObject properties directly. */
root->indicator = APP_INDICATOR(g_object_new(
APP_INDICATOR_TYPE,
"id", indicator_id,
"icon-name", "applications-system",
"category", APP_INDICATOR_CATEGORY_APPLICATION_STATUS,
NULL));
g_free(indicator_id);
if (!root->indicator) {
fprintf(stderr, "System::Menu: unable to create Ubuntu AppIndicator\n");
item_free(root);
continue;
}
app_indicator_set_menu(root->indicator, GTK_MENU(root->menu));
update_status_icon(root);
app_indicator_set_status(root->indicator, APP_INDICATOR_STATUS_ACTIVE);
g_roots[g_root_count++] = root;
}
}
native/system_menu_helper_linux.c view on Meta::CPAN
return TRUE;
}
int main(int argc, char **argv)
{
GError *error = NULL;
GIOFlags flags;
if (!gtk_init_check(&argc, &argv)) {
fprintf(stderr,
"Developer::Dashboard::System::Menu: GTK could not connect to the Ubuntu desktop session. "
"A graphical session with AppIndicator support is required.\n");
return 2;
}
g_stdin_channel = g_io_channel_unix_new(STDIN_FILENO);
g_io_channel_set_encoding(g_stdin_channel, NULL, &error);
if (error) {
fprintf(stderr, "System::Menu: stdin encoding setup failed: %s\n", error->message);
g_error_free(error);
return 2;
}
flags = g_io_channel_get_flags(g_stdin_channel);
g_io_channel_set_flags(g_stdin_channel, flags | G_IO_FLAG_NONBLOCK, NULL);
g_io_add_watch(g_stdin_channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
on_stdin_ready, NULL);
gtk_main();
native/system_menu_helper_mac.m view on Meta::CPAN
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <unistd.h>
@class DDSystemMenuController;
@interface DDStayMenuItemView : NSView
@property(nonatomic, copy) NSString *itemName;
@property(nonatomic, copy) NSString *displayTitle;
@property(nonatomic, weak) DDSystemMenuController *controller;
@property(nonatomic, assign) BOOL highlighted;
@property(nonatomic, strong) NSTrackingArea *trackingArea;
- (instancetype)initWithName:(NSString *)name
title:(NSString *)title
controller:(DDSystemMenuController *)controller;
- (void)setMenuTitle:(NSString *)title;
@end
@interface DDSystemMenuController : NSObject
@property(nonatomic, strong) NSMutableData *inputBuffer;
@property(nonatomic, strong) NSMutableDictionary<NSString *, id> *objectsByName;
@property(nonatomic, strong) NSMutableSet<NSString *> *topLevelNames;
- (void)emitClick:(NSString *)name;
@end
static const void *DDSystemMenuNameKey = &DDSystemMenuNameKey;
static DDSystemMenuController *DDSystemMenuControllerInstance = nil;
@implementation DDStayMenuItemView
- (instancetype)initWithName:(NSString *)name
title:(NSString *)title
controller:(DDSystemMenuController *)controller
{
NSFont *font = [NSFont menuFontOfSize:0.0];
NSDictionary *attrs = @{ NSFontAttributeName: font };
CGFloat textWidth = ceil([title sizeWithAttributes:attrs].width);
CGFloat width = MAX(120.0, textWidth + 34.0);
self = [super initWithFrame:NSMakeRect(0.0, 0.0, width, 22.0)];
if (!self) return nil;
_itemName = [name copy];
native/system_menu_helper_mac.m view on Meta::CPAN
}
- (void)mouseDown:(NSEvent *)event
{
NSPoint p = [self convertPoint:event.locationInWindow fromView:nil];
if (NSPointInRect(p, self.bounds)) {
[self.controller emitClick:self.itemName];
}
}
- (void)setMenuTitle:(NSString *)title
{
self.displayTitle = title ?: @"";
NSFont *font = [NSFont menuFontOfSize:0.0];
NSDictionary *attrs = @{ NSFontAttributeName: font };
CGFloat textWidth = ceil([self.displayTitle sizeWithAttributes:attrs].width);
NSRect frame = self.frame;
frame.size.width = MAX(120.0, textWidth + 34.0);
self.frame = frame;
self.needsDisplay = YES;
}
native/system_menu_helper_mac.m view on Meta::CPAN
- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
if (self.highlighted) {
[[NSColor selectedContentBackgroundColor] setFill];
NSRectFill(self.bounds);
}
NSColor *textColor = self.highlighted
? [NSColor selectedMenuItemTextColor]
: [NSColor textColor];
NSDictionary *attrs = @{
NSFontAttributeName: [NSFont menuFontOfSize:0.0],
NSForegroundColorAttributeName: textColor,
};
NSSize textSize = [self.displayTitle sizeWithAttributes:attrs];
CGFloat y = floor((NSHeight(self.bounds) - textSize.height) / 2.0);
[self.displayTitle drawAtPoint:NSMakePoint(22.0, y)
withAttributes:attrs];
}
@end
@implementation DDSystemMenuController
- (instancetype)init
{
self = [super init];
if (!self) return nil;
_inputBuffer = [NSMutableData data];
_objectsByName = [NSMutableDictionary dictionary];
_topLevelNames = [NSMutableSet set];
return self;
}
native/system_menu_helper_mac.m view on Meta::CPAN
- (void)setVisibleText:(NSString *)text onStatusButton:(NSStatusBarButton *)button
{
button.image = nil;
button.font = [NSFont menuBarFontOfSize:0.0];
button.title = text ?: @"";
}
- (void)statusItemButtonClicked:(NSStatusBarButton *)sender
{
NSString *name = objc_getAssociatedObject(sender, DDSystemMenuNameKey);
[self emitClick:name];
}
- (void)menuItemClicked:(NSMenuItem *)sender
{
NSString *name = [sender.representedObject isKindOfClass:[NSString class]]
? sender.representedObject : nil;
[self emitClick:name];
}
- (void)removeAllStatusItems
{
for (NSString *name in [self.topLevelNames allObjects]) {
id object = self.objectsByName[name];
if ([object isKindOfClass:[NSStatusItem class]]) {
[[NSStatusBar systemStatusBar] removeStatusItem:(NSStatusItem *)object];
}
}
[self.objectsByName removeAllObjects];
[self.topLevelNames removeAllObjects];
}
- (NSMenu *)buildMenu:(NSArray *)specs
{
NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
menu.autoenablesItems = NO;
for (id raw in specs) {
if (![raw isKindOfClass:[NSDictionary class]]) continue;
NSDictionary *spec = (NSDictionary *)raw;
NSString *name = [spec[@"name"] isKindOfClass:[NSString class]] ? spec[@"name"] : nil;
NSString *icon = [spec[@"icon"] isKindOfClass:[NSString class]] ? spec[@"icon"] : @"";
BOOL clickStay = [spec[@"click_stay"] boolValue];
if (!name.length) continue;
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:icon action:nil keyEquivalent:@""];
self.objectsByName[name] = item;
NSArray *children = [spec[@"menu"] isKindOfClass:[NSArray class]] ? spec[@"menu"] : nil;
if (children) {
item.submenu = [self buildMenu:children];
item.enabled = YES;
}
else if ([spec[@"click"] isKindOfClass:[NSString class]]) {
item.enabled = YES;
if (clickStay) {
DDStayMenuItemView *view = [[DDStayMenuItemView alloc]
initWithName:name title:icon controller:self];
item.view = view;
}
else {
item.target = self;
item.action = @selector(menuItemClicked:);
item.representedObject = name;
}
}
else {
native/system_menu_helper_mac.m view on Meta::CPAN
NSDictionary *spec = (NSDictionary *)raw;
NSString *name = [spec[@"name"] isKindOfClass:[NSString class]] ? spec[@"name"] : nil;
NSString *icon = [spec[@"icon"] isKindOfClass:[NSString class]] ? spec[@"icon"] : @"";
if (!name.length) continue;
NSStatusItem *statusItem = [[NSStatusBar systemStatusBar]
statusItemWithLength:NSVariableStatusItemLength];
NSStatusBarButton *button = statusItem.button;
[self setVisibleText:icon onStatusButton:button];
objc_setAssociatedObject(button, DDSystemMenuNameKey, name, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.objectsByName[name] = statusItem;
[self.topLevelNames addObject:name];
NSArray *children = [spec[@"menu"] isKindOfClass:[NSArray class]] ? spec[@"menu"] : nil;
if (children) {
statusItem.menu = [self buildMenu:children];
}
else if ([spec[@"click"] isKindOfClass:[NSString class]]) {
button.enabled = YES;
button.target = self;
button.action = @selector(statusItemButtonClicked:);
[button sendActionOn:NSEventMaskLeftMouseUp];
}
}
}
- (void)setIcon:(NSString *)icon forName:(NSString *)name
{
id object = self.objectsByName[name];
if ([object isKindOfClass:[NSStatusItem class]]) {
[self setVisibleText:(icon ?: @"") onStatusButton:((NSStatusItem *)object).button];
}
else if ([object isKindOfClass:[NSMenuItem class]]) {
NSMenuItem *item = (NSMenuItem *)object;
if ([item.view isKindOfClass:[DDStayMenuItemView class]]) {
[(DDStayMenuItemView *)item.view setMenuTitle:(icon ?: @"")];
}
else {
item.title = icon ?: @"";
}
}
}
- (void)removeName:(NSString *)name
{
id object = self.objectsByName[name];
if (!object) return;
if ([object isKindOfClass:[NSStatusItem class]]) {
[[NSStatusBar systemStatusBar] removeStatusItem:(NSStatusItem *)object];
[self.topLevelNames removeObject:name];
}
else if ([object isKindOfClass:[NSMenuItem class]]) {
NSMenuItem *item = (NSMenuItem *)object;
if (item.menu) [item.menu removeItem:item];
}
[self.objectsByName removeObjectForKey:name];
}
- (void)handleCommand:(NSDictionary *)command
{
NSString *op = [command[@"op"] isKindOfClass:[NSString class]] ? command[@"op"] : @"";
if ([op isEqualToString:@"run"]) {
native/system_menu_helper_mac.m view on Meta::CPAN
@end
int main(int argc, const char *argv[])
{
@autoreleasepool {
(void)argc;
(void)argv;
NSApplication *app = [NSApplication sharedApplication];
[app setActivationPolicy:NSApplicationActivationPolicyAccessory];
DDSystemMenuControllerInstance = [[DDSystemMenuController alloc] init];
[DDSystemMenuControllerInstance start];
[app run];
DDSystemMenuControllerInstance = nil;
}
return 0;
}
native/system_menu_helper_win.c view on Meta::CPAN
static HANDLE g_stdout = NULL;
static DDItem **g_roots = NULL;
static size_t g_root_count = 0;
static UINT g_next_tray_id = 1;
static UINT g_taskbar_created = 0;
static DDPopup *g_popups[DD_MAX_POPUPS];
static int g_popup_count = 0;
static int g_closing_popups = 0;
static HFONT g_menu_font = NULL;
static const wchar_t *HOST_CLASS = L"DeveloperDashboardSystemMenuHost";
static const wchar_t *POPUP_CLASS = L"DeveloperDashboardSystemMenuPopup";
/* ---------------------------- small JSON parser ---------------------------- */
typedef struct {
const char *p;
const char *end;
const char *error;
} JParser;
static void *xcalloc(size_t n, size_t s)
native/system_menu_helper_win.c view on Meta::CPAN
HANDLE thread;
NONCLIENTMETRICSW ncm;
g_instance = GetModuleHandleW(NULL);
g_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
if (!register_classes()) return 2;
ZeroMemory(&ncm, sizeof(ncm));
ncm.cbSize = sizeof(ncm);
if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0))
g_menu_font = CreateFontIndirectW(&ncm.lfMenuFont);
if (!g_menu_font) g_menu_font = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
g_host = CreateWindowExW(0, HOST_CLASS, L"", 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, g_instance, NULL);
if (!g_host) return 3;
g_taskbar_created = RegisterWindowMessageW(L"TaskbarCreated");
thread = CreateThread(NULL, 0, stdin_reader, NULL, 0, NULL);
if (thread) CloseHandle(thread);
while (GetMessageW(&msg, NULL, 0, 0) > 0) {
share/private-cli/_dashboard-core view on Meta::CPAN
my $workers = $settings->{workers};
my $ssl = $settings->{ssl};
GetOptionsFromArray(
\@ARGV,
'host=s' => \$host,
'port=i' => \$port,
'workers=i' => \$workers,
'ssl!' => \$ssl,
);
die "Usage: d2 web-foreground [--host HOST] [--port PORT] [--workers N] [--ssl|--no-ssl]\n" if @ARGV;
require Developer::Dashboard::SystemMenu::Runner;
my $menu_platform = $^O eq 'darwin' ? 'macos'
: $^O eq 'MSWin32' ? 'windows'
: $^O eq 'linux' ? 'ubuntu'
: 'unsupported';
my $menu_runner = Developer::Dashboard::SystemMenu::Runner->new(
config => $config->merged,
store => $indicators,
platform => $menu_platform,
);
$menu_runner->run_with( sub {
return $runtime->start_web(
foreground => 1,
host => $host,
port => $port,
workers => $workers,
ssl => $ssl,
);
} );
exit 0;
}
elsif ( $cmd eq 'system-menu-foreground' ) {
die "Usage: d2 system-menu-foreground\n" if @ARGV;
require JSON::XS;
require Developer::Dashboard::System::Menu;
local $/;
my $items_json = <STDIN>;
die "system-menu-foreground requires menu items JSON on stdin\n"
if !defined $items_json || $items_json eq '';
my $items = JSON::XS->new->utf8->decode($items_json);
die "system-menu-foreground requires a menu items array\n"
if ref($items) ne 'ARRAY';
my $menu = Developer::Dashboard::System::Menu::menu();
# A TERM/INT from the parent (the menu runner stopping the worker)
# asks the menu to stop cleanly: the run loop sees active=0, exits,
# and the native helper is stopped. Without this the child would die
# at once and leave the helper running.
local $SIG{TERM} = sub { $menu->stop; };
local $SIG{INT} = sub { $menu->stop; };
$menu->run($items);
exit 0;
}
elsif ( $cmd eq 'web-ssl-backend-foreground' ) {
t/15-release-metadata.t view on Meta::CPAN
'MakeMaker obtains the version from the lightweight version module without warnings' );
my $mymeta_path = File::Spec->catfile( $fixture, 'MYMETA.json' );
ok( -f $mymeta_path, 'Makefile.PL writes MYMETA.json' );
my $generated_meta = JSON::XS->new->decode( _slurp($mymeta_path) );
is_deeply( $generated_meta->{license}, ['mit'], 'generated MakeMaker metadata declares only the canonical MIT license' );
my $generated_makefile = _slurp( File::Spec->catfile( $fixture, 'Makefile' ) );
if ( $^O eq 'linux' ) {
unlike( $generated_makefile, qr/^build-system-menu-helper:/m,
'Linux Makefile omits the native helper build when pkg-config reports missing GTK/Ayatana modules' );
like( $configure_stdout, qr/System Menu helper.*not built.*pkg-config/is,
'Linux Makefile.PL visibly explains why the optional helper was not built' );
}
else {
pass('Linux-only optional GTK helper assertions are not applicable on this platform');
pass('Linux-only optional GTK helper notice is not applicable on this platform');
}
if ( $^O eq 'linux' ) {
my ( $available_stdout, $available_stderr, $available_exit ) = capture {
my $original = Cwd::cwd();
t/15-release-metadata.t view on Meta::CPAN
local $ENV{DD_TEST_PKG_CONFIG_STATUS} = 1;
local $ENV{DD_REQUIRE_SYSTEM_MENU_HELPER} = 1;
system( $^X, 'Makefile.PL' );
my $exit = $? >> 8;
chdir $original or die "Unable to return to $original: $!";
return $exit;
};
isnt( $required_exit, 0,
'Linux configure fails when the required native helper dependencies are missing' );
like( "$required_stdout\n$required_stderr",
qr/Required Linux System Menu helper cannot be built.*gtk/i,
'required-helper failure names the missing native dependency setup' );
}
}
like( $makefile, qr/VERSION_FROM\s*=>\s*'lib\/Developer\/Dashboard\/Version\.pm'/,
'Makefile.PL reads version metadata from the lightweight version module' );
like( $dist, qr/^skip = \^Module::CPANTS::Analyse\$$/m, 'dist.ini skips release-only Module::CPANTS::Analyse from generated install-time prereqs' );
like( $dist, qr/^skip = \^Module::CPANTS::Kwalitee\$$/m, 'dist.ini skips release-only Module::CPANTS::Kwalitee from generated install-time prereqs' );
like(
$dist,
qr/^skip = \^\(\?:Inline\|MCE::Map\|SPVM\|SPVM::Digest::SHA\)\$$/m,
t/15-release-metadata.t view on Meta::CPAN
15-release-metadata.t - verify release metadata and repository documentation records
=head1 DESCRIPTION
This test keeps the shipped version metadata, public executable list, core
documentation, and numbered problem-report index aligned for the private-helper
and isolated-skill packaging model. It also pins the declared runtime dependency floors, so a
distribution carrying a published advisory cannot be permitted by the manifests
even where no current advisory database is installed to notice.
It configures isolated MakeMaker fixtures with mocked pkg-config results to
verify optional Linux System Menu helper handling, including the strict mode
used by CI.
It also resolves every C<t/NN-name.t> path cited in the README, the markdown under
C<doc/> and C<docs/>, and the POD of every Perl file, so a renamed test file
cannot leave a stale citation behind in the documentation. The collector cron
assertions distinguish a once-hourly expression from a wildcard-minute,
per-minute expression in the plain reference, canonical POD, and generated
README.
=for comment FULL-POD-DOC START
t/228-docker-image-build-files.t view on Meta::CPAN
like( $dockerfile, qr/Dist::Zilla::Plugin::ManifestSkip/, 'the build installs the repository Dist::Zilla plugin set' );
like( $dockerfile, qr/dzil\s+build/, 'the checked-out current source is built into a tarball' );
like( $dockerfile, qr/archive\s*=\s*"Developer-Dashboard-\$\{DIST_VERSION\}\.tar\.gz"/, 'the image names the archive from the checked-out distribution version' );
like( $dockerfile, qr/cpanm\s+(?:--verbose\s+)?--notest\s+--reinstall\s+--local-lib=\/root\/perl5\s+"\$\{archive\}"/, 'the image installs the newly built tarball without repeating the full test suite already covered by repository gates' );
like( $dockerfile, qr/ENTRYPOINT\s+\[\s*"d2"\s*\]/, 'the published image starts the installed d2 command' );
like( $dockerfile, qr/arm64.*Apple Silicon|Apple Silicon.*arm64/is, 'the Dockerfile documents arm64 use on Apple Silicon without claiming a macOS container platform' );
like( $dist, qr/^version\s*=\s*\d+\.\d{2}\s*$/m, 'the source distribution has the X.XX version that supplies the image tag' );
like( $dockerignore, qr/^!Developer-Dashboard-\*\.tar\.gz\s*$/m, 'the shared Docker context re-includes release archives after build-artifact exclusions for d2 docker.images.build' );
like( $dockerignore, qr/^\.env(?:\.\*)?\s*$/m, 'local environment files stay out of Docker build contexts' );
like( $makefile_text, qr/-fobjc-arc/,
'the macOS System Menu helper compiles with ARC for weak Objective-C references' );
done_testing();
__END__
=head1 NAME
t/228-docker-image-build-files.t - protect the files the Docker image is built from
=head1 PURPOSE
t/239-system-menu-config.t view on Meta::CPAN
# rejected(%args)
# Calls the adapter with a malformed input and reports whether its error names
# the expected validation rule.
# Input: adapter arguments plus a regex and test description.
# Output: no value; adds one Test::More assertion.
sub rejected {
my (%case) = @_;
my $pattern = delete $case{pattern};
my $name = delete $case{name};
my $ok = eval {
Developer::Dashboard::SystemMenu->items_for_platform(%case);
1;
};
ok( !$ok && $@ =~ $pattern, $name );
}
my $paths = Developer::Dashboard::PathRegistry->new;
my $config = Developer::Dashboard::Config->for_paths($paths);
my $merged = $config->_merge_hashes(
{
t/239-system-menu-config.t view on Meta::CPAN
} ) or die "Unable to write config payload to $global_file: $!";
close $fh or die "Unable to close $global_file: $!";
$loaded = $layered_config->load_global( skill_config_entries => [] );
is_deeply(
$loaded->{indicators},
[ { name => 'build', indicator => { macos => 1, ubuntu => 1 } } ],
'global indicator entries are normalized and merged by name when no skill config overlays them',
);
}
my $module_loaded = eval { require Developer::Dashboard::SystemMenu; 1 };
ok( $module_loaded, 'SystemMenu adapter module loads without AppKit at compile time' )
or diag($@ || 'module load failed without an exception');
SKIP: {
skip 'SystemMenu adapter is not implemented yet', 5 if !$module_loaded;
my @states = (
{ name => 'build', icon => 'â
', status => 'ok' },
{ name => 'tests', icon => 'â', status => 'failed' },
{ name => 'hidden', icon => 'H', status => 'ok' },
);
my $valid_config = { indicators => [ { name => 'build', indicator => { macos => 1 } } ] };
rejected(
config => 'not-a-config', indicators => \@states, platform => 'macos',
pattern => qr/config must be a hash reference/, name => 'non-hash config is rejected',
t/239-system-menu-config.t view on Meta::CPAN
rejected(
config => $valid_config, indicators => \@states, platform => [],
pattern => qr/platform must be a non-empty string/, name => 'reference platform is rejected',
);
rejected(
config => $valid_config, indicators => \@states, platform => '',
pattern => qr/platform must be a non-empty string/, name => 'empty platform is rejected',
);
is_deeply(
Developer::Dashboard::SystemMenu->items_for_platform(
config => {}, indicators => \@states, platform => 'macos',
),
[], 'missing indicator configuration produces an empty menu',
);
my $items = Developer::Dashboard::SystemMenu->items_for_platform(
config => $merged,
indicators => \@states,
platform => 'macos',
);
is_deeply(
$items,
[
{ name => 'build', icon => 'â
' },
{ name => 'tests', icon => 'â' },
],
'macOS menu projection contains only enabled configured indicators and current icons',
);
is_deeply(
Developer::Dashboard::SystemMenu->items_for_platform(
config => $merged,
indicators => \@states,
platform => 'linux',
),
[],
'non-macOS platforms do not select the AppKit menu',
);
for my $platform (qw(windows ubuntu)) {
my $platform_config = {
indicators => [
{ name => 'build', indicator => { $platform => JSON::XS->new->decode('true') } },
{ name => 'tests', indicator => { $platform => 0 } },
],
};
is_deeply(
Developer::Dashboard::SystemMenu->items_for_platform(
config => $platform_config,
indicators => \@states,
platform => $platform,
),
[ { name => 'build', icon => 'â
' } ],
"$platform menu projection selects enabled configured indicators",
);
is_deeply(
$platform_config->{indicators}[0]{indicator}{$platform},
JSON::XS->new->decode('true'),
t/239-system-menu-config.t view on Meta::CPAN
],
},
indicators => \@states,
platform => $platform,
pattern => qr/\Q$platform\E selector must be boolean/,
name => "$platform selector rejects non-boolean values",
);
}
is_deeply(
Developer::Dashboard::SystemMenu->items_for_platform(
config => {
indicators => [
{ name => 'build', indicator => { macos => JSON::XS->new->decode('true') } },
],
},
indicators => \@states,
platform => 'macos',
),
[ { name => 'build', icon => 'â
' } ],
'JSON true boolean enables a macOS item',
);
is_deeply(
Developer::Dashboard::SystemMenu->items_for_platform(
config => {
indicators => [
{ name => 'build', indicator => { macos => JSON::XS->new->decode('false') } },
],
},
indicators => \@states,
platform => 'macos',
),
[],
'JSON false boolean disables a macOS item',
);
is_deeply(
Developer::Dashboard::SystemMenu->items_for_platform(
config => { indicators => [ { name => 'missing', indicator => { macos => 1 } } ] },
indicators => \@states,
platform => 'macos',
),
[],
'enabled config without current state produces no menu item',
);
my $invalid = eval {
Developer::Dashboard::SystemMenu->items_for_platform(
config => { indicators => 'not-an-array' },
indicators => \@states,
platform => 'macos',
);
1;
};
ok( !$invalid, 'invalid top-level indicator configuration is refused' );
like( $@, qr/indicators.*array/i, 'invalid configuration error names the expected array' );
my $invalid_platform_config = eval {
Developer::Dashboard::SystemMenu->items_for_platform(
config => { indicators => [ { name => 'build', indicator => 'yes' } ] },
indicators => \@states,
platform => 'linux',
);
1;
};
ok( !$invalid_platform_config, 'invalid platform indicator settings are refused on Linux too' );
like( $@, qr/settings must be a hash reference/i, 'invalid settings error names the expected hash' );
my $invalid_state = eval {
Developer::Dashboard::SystemMenu->items_for_platform(
config => $merged,
indicators => [ 'not-a-state' ],
platform => 'macos',
);
1;
};
ok( !$invalid_state, 'invalid indicator state entries are refused' );
like( $@, qr/state entries must be hash references/i, 'invalid state error identifies the entry shape' );
my $duplicate_name = eval {
Developer::Dashboard::SystemMenu->items_for_platform(
config => {
indicators => [
{ name => 'build', indicator => { macos => 1 } },
{ name => 'build', indicator => { macos => 0 } },
],
},
indicators => \@states,
platform => 'macos',
);
1;
};
ok( !$duplicate_name, 'duplicate indicator names are refused' );
like( $@, qr/duplicate indicator configuration name/i, 'duplicate-name error identifies the conflict' );
my $bad_platform_flag = eval {
Developer::Dashboard::SystemMenu->items_for_platform(
config => {
indicators => [
{ name => 'build', indicator => { macos => 'yes' } },
],
},
indicators => \@states,
platform => 'macos',
);
1;
};
t/239-system-menu-config.t view on Meta::CPAN
config => { indicators => [ { name => 'build', indicator => [] } ] },
indicators => \@states, platform => 'macos',
pattern => qr/settings must be a hash reference/, name => 'non-hash platform settings are rejected',
);
rejected(
config => { indicators => [ { name => 'build', indicator => { macos => [] } } ] },
indicators => \@states, platform => 'macos',
pattern => qr/macos selector must be boolean/, name => 'reference platform selector is rejected',
);
is_deeply(
Developer::Dashboard::SystemMenu->items_for_platform(
config => { indicators => [ { name => 'build', indicator => { macos => undef } } ] },
indicators => \@states, platform => 'macos',
),
[], 'undefined selector follows the disabled path',
);
is_deeply(
Developer::Dashboard::SystemMenu->items_for_platform(
config => { indicators => [ { name => 'build', indicator => { macos => '0' } } ] },
indicators => \@states, platform => 'macos',
),
[], 'string zero is accepted as a false selector',
);
rejected(
config => $valid_config, indicators => ['not-a-state'], platform => 'macos',
pattern => qr/state entries must be hash references/, name => 'non-hash state entry is rejected',
);
t/239-system-menu-config.t view on Meta::CPAN
__END__
=head1 NAME
t/239-system-menu-config.t - system-menu configuration and platform selection
=head1 PURPOSE
This test protects the configuration contract for optional operating-system
menu indicators. It verifies that named indicator declarations merge across
configuration layers and that the SystemMenu adapter selects only the enabled
indicators for macOS, leaving unsupported platforms and invalid settings
visible and safe.
=head1 WHY IT EXISTS
Configuration overlays must add or change a platform selector without
discarding inherited settings for the same named indicator. The adapter must
then project only explicitly enabled macOS items, and malformed declarations
must fail visibly instead of producing a misleading partial menu. A valid
global configuration without the optional system-menu section remains
unchanged, while configured global indicator entries are normalized by name.
=head1 WHEN TO USE
Run this test in the project C<dev> Docker service whenever configuration
merging, indicator settings, or the SystemMenu adapter changes:
d2 docker compose exec dev prove -lv t/239-system-menu-config.t
The focused suite runs with the project paths mounted in the container, so it
checks the merge and selection contracts without relying on the host Perl
environment. Pair it with the existing config and indicator-store suites.
=head1 HOW TO USE
Run the focused command from the project root. When changing configuration
t/241-system-menu-runner.t view on Meta::CPAN
use File::Spec;
use File::Temp qw(tempdir);
use FindBin qw($RealBin);
use Test::More;
use JSON::XS qw(decode_json);
use lib 'lib';
use Developer::Dashboard::GoRoutine;
my $runner_loaded = eval { require Developer::Dashboard::SystemMenu::Runner; 1 };
ok( $runner_loaded, 'system-menu runner module loads without starting a native menu' )
or diag( $@ || 'runner module failed to load' );
# _fake_worker_command($state_dir)
# Writes a fake menu worker script (a small Perl program that reads menu
# items JSON from stdin, records them, and waits for TERM) and returns the
# argv to spawn it. The worker records its lifecycle in files under the
# state directory because a child process cannot share the test's memory.
# Input: state directory path.
# Output: argv array reference for the fake worker.
t/241-system-menu-runner.t view on Meta::CPAN
return 1 if -f $path;
select undef, undef, undef, 0.05;
}
return -f $path ? 1 : 0;
}
SKIP: {
skip 'system-menu runner is not implemented yet', 14 if !$runner_loaded;
my $disabled_dir = tempdir( CLEANUP => 1 );
my $disabled = Developer::Dashboard::SystemMenu::Runner->new(
config => { indicators => [
{ name => 'build', indicator => { macos => 0 } },
] },
platform => 'macos',
store => Local::SystemMenuTestStore->new,
worker_command => _fake_worker_command($disabled_dir),
);
ok( !$disabled->start, 'disabled platform setting does not launch a menu worker' );
ok( !_wait_for_file( File::Spec->catfile( $disabled_dir, 'entered.json' ), 1 ),
'disabled setting spawns no worker process' );
my $enabled_dir = tempdir( CLEANUP => 1 );
my $enabled = Developer::Dashboard::SystemMenu::Runner->new(
config => { indicators => [
{ name => 'build', indicator => { macos => 1 } },
{ name => 'hidden', indicator => { macos => 0 } },
] },
platform => 'macos',
store => Local::SystemMenuTestStore->new,
worker_command => _fake_worker_command($enabled_dir),
);
my $pid = $enabled->start;
ok( $pid && $pid =~ /\A[0-9]+\z/, 'enabled setting starts a controlled menu worker process' );
my $entered_file = File::Spec->catfile( $enabled_dir, 'entered.json' );
ok( _wait_for_file( $entered_file, 10 ), 'worker enters the native menu run loop' );
my $entered_json = do { local $/; open my $efh, '<', $entered_file or die "Unable to read entered file: $!"; <$efh> };
is 0 + utf8::is_utf8( decode_json($entered_json)->[0]{icon} ), 1,
t/241-system-menu-runner.t view on Meta::CPAN
is_deeply(
decode_json($entered_json), [ { name => 'build', icon => 'â
' } ],
'menu receives only enabled indicators and their latest stored icons',
);
ok( $enabled->stop, 'stop requests clean menu shutdown and waits for the worker' );
ok( !process_running($pid), 'menu worker process exits after stop' );
_worker_stopped_ok( $enabled, $enabled_dir, 'menu worker stops cleanly on TERM' );
my $service_dir = tempdir( CLEANUP => 1 );
my $service_runner = Developer::Dashboard::SystemMenu::Runner->new(
config => { indicators => [
{ name => 'build', indicator => { macos => 1 } },
] },
platform => 'macos',
store => Local::SystemMenuTestStore->new,
worker_command => _fake_worker_command($service_dir),
);
my $served = $service_runner->run_with( sub {
_wait_for_file( File::Spec->catfile( $service_dir, 'entered.json' ), 10 );
return 'server-exit';
} );
is( $served, 'server-exit', 'foreground service return value is preserved' );
_worker_stopped_ok( $service_runner, $service_dir,
'foreground service exit stops and joins the enabled menu worker' );
my $failure_dir = tempdir( CLEANUP => 1 );
my $failure_runner = Developer::Dashboard::SystemMenu::Runner->new(
config => { indicators => [
{ name => 'build', indicator => { macos => 1 } },
] },
platform => 'macos',
store => Local::SystemMenuTestStore->new,
worker_command => _fake_worker_command($failure_dir),
);
my $failure_ok = eval {
$failure_runner->run_with( sub {
_wait_for_file( File::Spec->catfile( $failure_dir, 'entered.json' ), 10 );
die "server failed\n";
} );
1;
};
ok( !$failure_ok, 'foreground service exception is propagated' );
like( $@, qr/server failed/, 'foreground service preserves the original failure text' );
_worker_stopped_ok( $failure_runner, $failure_dir,
'foreground service failure still stops and joins the menu worker' );
}
my $core_path = File::Spec->catfile( $RealBin, File::Spec->updir, 'share', 'private-cli', '_dashboard-core' );
open my $core_fh, '<', $core_path or die "Unable to read private dashboard runtime '$core_path': $!";
my $core_source = do { local $/; <$core_fh> };
close $core_fh or die "Unable to close private dashboard runtime '$core_path': $!";
like( $core_source,
qr/elsif\s*\(\s*\$cmd\s+eq\s+'web-foreground'.*?SystemMenu::Runner->new\(.*?config\s*=>\s*\$config->merged.*?store\s*=>\s*\$indicators.*?->run_with\(/s,
'web-foreground starts the configured native menu around the long-lived service' );
done_testing;
package Local::SystemMenuTestStore;
# new()
# Creates the test indicator store.
# Input: class name.
# Output: in-memory store object.
sub new { bless {}, shift }
# list_indicators()
# Returns the current in-memory indicator snapshot.
# Input: store object.
t/241-system-menu-runner.t view on Meta::CPAN
This test specifies the opt-in boundary between configured Dashboard indicators,
the current indicator store, the platform menu adapter, and the menu worker
process. It uses an injected fake worker command (a small Perl program that
reads the items JSON from stdin and records its lifecycle in files), so Linux
Docker can test selection and shutdown without claiming that a native desktop
menu is visible.
=head1 WHY IT EXISTS
The System Menu integration must not launch a helper when no indicator is
enabled for the current platform. When enabled, it must pass the current
indicator projection to one controlled worker and stop that worker cleanly.
These checks protect the runtime contract independently of AppKit, Windows
notification-area, or Ubuntu desktop availability.
=head1 WHEN TO USE
Run this file in the dev Docker container when changing the system-menu runner,
its indicator-store integration, or menu worker lifecycle handling. Native
platform visibility still requires the corresponding hosted platform workflow.
=head1 HOW TO USE
d2 docker compose exec dev prove -lv t/241-system-menu-runner.t
The test loads C<Developer::Dashboard::SystemMenu::Runner>, verifies that a
disabled platform setting is inert, starts an enabled fake menu worker, checks
the projected indicator data, then requests stop and verifies worker exit.
It also verifies that the staged private runtime wraps the long-lived
C<web-foreground> service in this lifecycle using merged configuration and the
shared indicator store.
=head1 EXAMPLES
The disabled case configures C<macos =E<gt> 0> and proves that no worker
process is started. The enabled case configures one visible and one hidden
indicator, verifies the visible entry carries the stored icon, then calls
C<stop> and checks the worker process exits. The service wrapper example
returns a value from a short server callback and proves the value is preserved
while the menu worker is joined. A second callback throws an error and the test
checks both that the original error remains visible and that menu shutdown
still occurs.
=head1 WHAT USES IT
The Docker unit suite uses this test as the platform-independent contract for
C<Developer::Dashboard::SystemMenu::Runner> and its private service wiring. It
does not replace the native macOS, Windows, and Ubuntu integration workflows,
which must exercise each platform-specific adapter on an appropriate host.
=cut
t/242-system-menu-bundle.t view on Meta::CPAN
use strict;
use warnings;
use File::Spec;
use Test::More;
use Developer::Dashboard::Version ();
my $loaded = eval { require Developer::Dashboard::System::Menu; 1 };
plan skip_all => 'system-menu XS bundle is unavailable or out of date'
if !$loaded;
pass('system-menu API loads through the Dashboard XS bundle');
SKIP: {
skip 'system-menu API is not loadable yet', 6 if !$loaded;
is(
$Developer::Dashboard::System::Menu::VERSION,
$Developer::Dashboard::Version::VERSION,
'system-menu module shares the distribution version',
);
for my $xs_method (qw(_start _command_json _read_events _stop _running)) {
ok(
Developer::Dashboard::System::Menu->can($xs_method),
"$xs_method is registered in the shared Dashboard XS bundle",
);
}
}
SKIP: {
my $helper_name = $^O eq 'MSWin32' ? 'system_menu_helper.exe' : 'system_menu_helper';
# The helper is built beside the loaded Dashboard XS bundle, not
# necessarily beside the current directory: prove may run from a
t/242-system-menu-bundle.t view on Meta::CPAN
done_testing;
__END__
=head1 NAME
t/242-system-menu-bundle.t - shared XS bundle registration tests
=head1 PURPOSE
Verifies that the native System Menu API loads through the existing
Developer::Dashboard XS extension rather than requiring a second extension
object with a separately versioned ABI. It also checks that platform helpers
are built when required; the Linux helper-file assertion is skipped only when
the optional GTK/Ayatana development modules are unavailable.
=head1 WHY IT EXISTS
System Menu owns native helper-process startup, command transport, event reads,
shutdown, and running-state checks. These XSUBs must be installed under the
System::Menu package by the Dashboard shared extension so normal Perl callers
can use the existing Developer::Dashboard::* module namespace. Headless CPAN
test environments may not have GTK development headers, so the Linux helper
build is optional there while the native API and XSUB checks still run.
=head1 WHEN TO USE
Run this test after changing the System Menu XS source, the main XS include
list, or the Perl module's XS loading path. It is intended to catch accidental
creation of a second XS bundle or missing XSUB registration before any native
helper is started. On Linux without GTK/Ayatana pkg-config modules, only the
helper-file existence assertion is skipped; Linux CI sets
C<DD_REQUIRE_SYSTEM_MENU_HELPER=1>, so its helper build remains mandatory.
=head1 HOW TO USE
Run inside the project dev container after generating the Makefile and building
the XS extension:
prove -Iblib/lib -Iblib/arch -Ilib -lv t/242-system-menu-bundle.t
=head1 WHAT USES IT
The distribution test suite runs this contract alongside configuration and
runner lifecycle tests. The installed System::Menu module relies on the same
Dashboard XS object as HtmlEscape and GoRoutine. The Linux helper binary is
available when the system development packages were installed before
configuration.
=head1 EXAMPLES
Check the test through the Docker dev service:
d2 docker compose exec dev prove -Iblib/lib -Iblib/arch -Ilib -lv t/242-system-menu-bundle.t
Load the module after building the distribution:
perl -Iblib/lib -Iblib/arch -Ilib -MDeveloper::Dashboard::System::Menu -e 'print "$Developer::Dashboard::System::Menu::VERSION\n"'
=cut
t/243-system-menu-linux-indicator-api.t view on Meta::CPAN
not claim that a desktop shell visibly displayed the indicator.
=head1 HOW TO USE
Run inside the dev Docker service from the CODE directory:
d2 docker compose exec dev prove -lv t/243-system-menu-linux-indicator-api.t
=head1 WHAT USES IT
The distribution test suite runs this contract alongside System::Menu
configuration, worker lifecycle, and XS bundle tests. The Linux helper is
compiled and launched by the Dashboard System::Menu adapter.
=head1 EXAMPLES
Run the focused source contract:
prove -lv t/243-system-menu-linux-indicator-api.t
Run the source contract together with native bundle checks:
prove -Iblib/lib -Iblib/arch -Ilib -lv t/242-system-menu-bundle.t t/243-system-menu-linux-indicator-api.t
t/250-system-menu-coverage.t view on Meta::CPAN
use warnings;
use utf8;
use Test::More;
use JSON::XS ();
use File::Spec;
use File::Temp qw(tempdir);
use lib 'lib';
use Developer::Dashboard::GoRoutine qw(spawn wait_process);
use Developer::Dashboard::System::Menu;
my $menu = Developer::Dashboard::System::Menu::menu();
is( Developer::Dashboard::System::Menu::menu(), $menu,
'menu returns the process-local singleton' );
for my $case (
[ sub { Developer::Dashboard::System::Menu::_id( {} ) }, qr/invalid System::Menu object/ ],
[ sub { Developer::Dashboard::System::Menu::_id('not-an-object') }, qr/invalid System::Menu object/ ],
[ sub { Developer::Dashboard::System::Menu::_id( bless { id => '' }, 'Developer::Dashboard::System::Menu' ) }, qr/invalid System::Menu object/ ],
[ sub { $menu->run( {} ) }, qr/requires an arrayref/ ],
[ sub { Developer::Dashboard::System::Menu::_text( undef, 'value' ) }, qr/plain scalar/ ],
[ sub { Developer::Dashboard::System::Menu::_text( [] , 'value' ) }, qr/plain scalar/ ],
[ sub { Developer::Dashboard::System::Menu::_click_stay( 'yes', 'setting' ) }, qr/0 or 1/ ],
[ sub { Developer::Dashboard::System::Menu::_click_stay( undef, 'setting' ) }, qr/0 or 1/ ],
[ sub { Developer::Dashboard::System::Menu::_click_stay( [], 'setting' ) }, qr/0 or 1/ ],
[ sub { Developer::Dashboard::System::Menu::_menu_spec( {}, 'menu' ) }, qr/requires items/ ],
[ sub { Developer::Dashboard::System::Menu::_menu_spec( { items => [], wrong => 1 }, 'menu' ) }, qr/unknown option/ ],
[ sub { Developer::Dashboard::System::Menu::_menu_spec( { items => {} }, 'menu' ) }, qr/requires items/ ],
[ sub { Developer::Dashboard::System::Menu::_menu_spec( 'items', 'menu' ) }, qr/arrayref or hashref/ ],
) {
my $ok = eval { $case->[0]->(); 1 };
ok( !$ok, 'invalid input throws' );
like( $@, $case->[1], 'invalid input identifies the contract' );
}
is( Developer::Dashboard::System::Menu::_id( bless { id => 'named-menu' }, 'Developer::Dashboard::System::Menu' ),
'named-menu', 'menu identity accepts a non-empty identifier' );
is( Developer::Dashboard::System::Menu::_text( 'plain ASCII', 'value' ), 'plain ASCII',
'plain scalar text without UTF-8 bytes is preserved' );
my $unicode_text = 'café';
is( Developer::Dashboard::System::Menu::_text( $unicode_text, 'value' ), $unicode_text,
'UTF-8-flagged text is preserved without byte decoding' );
is( Developer::Dashboard::System::Menu::_click_stay(0, 'setting'), 0,
'click_stay preserves the valid false setting' );
my ( $default_click_stay, $empty_menu_items ) =
Developer::Dashboard::System::Menu::_menu_spec( { items => [] }, 'menu' );
is( $default_click_stay, 0, 'menu hash defaults click_stay to false when omitted' );
is_deeply( $empty_menu_items, [], 'menu hash returns its items array' );
my $builder = bless { id => 'coverage-menu' }, 'Developer::Dashboard::System::Menu';
for my $case (
[ [], qr/each menu setting must be a hashref/ ],
[ {}, qr/requires name/ ],
[ { name => 'a' }, qr/requires icon/ ],
[ { name => '', icon => 'x' }, qr/non-empty name/ ],
[ { name => 'a', icon => 'x', unknown => 1 }, qr/unknown menu setting/ ],
[ { name => 'a', icon => 'x', menu => [], click => 'x' }, qr/both menu and click/ ],
[ { name => 'a', icon => 'x', menu => 'x' }, qr/menu must be/ ],
[ { name => 'a', icon => 'x', click_stay => 2 }, qr/0 or 1/ ],
[ { name => 'a', icon => 'x', click => [] }, qr/click must be/ ],
t/250-system-menu-coverage.t view on Meta::CPAN
};
ok( !$duplicate, 'duplicate item name is rejected across the menu tree' );
like( $@, qr/duplicate menu name/, 'duplicate-name diagnostic is explicit' );
is( $root->name, 'root', 'menu item exposes its name' );
is( $root->menu, $builder, 'menu item exposes its root menu' );
is( $root->icon, 'R', 'menu item exposes its current icon' );
my $bad_icon = eval { $root->icon( 'new', 'extra' ); 1 };
ok( !$bad_icon, 'menu item rejects extra icon arguments' );
like( $@, qr/exactly one value/, 'icon arity error is explicit' );
my $removed_icon = bless { root => $builder, name => 'gone', removed => 1 },
'Developer::Dashboard::System::Menu::Item';
my $removed_update = eval { $removed_icon->icon('x'); 1 };
ok( !$removed_update, 'removed menu item cannot be updated' );
like( $@, qr/cannot update removed menu item/, 'removed-item error is explicit' );
my $state = { running => 0, events => [] };
{
no warnings 'redefine';
local *Developer::Dashboard::System::Menu::_start = sub { $state->{started}++ };
local *Developer::Dashboard::System::Menu::_running = sub { $state->{running} };
local *Developer::Dashboard::System::Menu::_command_json = sub { push @{ $state->{commands} }, $_[0] };
local *Developer::Dashboard::System::Menu::_read_events = sub {
return shift @{ $state->{events} } if @{ $state->{events} };
$state->{running} = 0;
return '';
};
local *Developer::Dashboard::System::Menu::_stop = sub { $state->{stopped}++; $state->{running} = 0 };
my $callback_count = 0;
my $run_menu = bless { id => 'event-menu' }, 'Developer::Dashboard::System::Menu';
$state->{running} = 1;
$state->{events} = [
"{bad-json}\n",
JSON::XS->new->canonical->encode({ event => 'other', name => 'cb' }) . "\n",
JSON::XS->new->canonical->encode({ event => 'click', name => 'missing' }) . "\n",
JSON::XS->new->canonical->encode({ event => 'click', name => 'cb' }) . "\n",
JSON::XS->new->canonical->encode({ event => 'click', name => 'text' }) . "\n",
];
my $run_ok = eval {
$run_menu->run([
{ name => 'cb', icon => 'a', click => sub { $callback_count++ } },
{ name => 'text', icon => 'b', click => 'updated' },
]);
1;
};
ok( $run_ok, 'event loop accepts and processes helper event stream' ) or diag $@;
is( $callback_count, 1, 'callback click dispatches exactly once' );
is( $state->{running}, 0, 'event loop exits when the native helper stops' );
my $active_menu = bless { id => 'active-menu' }, 'Developer::Dashboard::System::Menu';
$state->{running} = 1;
my ( $built_item, $active_rt );
{
local *Developer::Dashboard::System::Menu::_read_events = sub {
return '' if $state->{active_actions_done}++;
$active_rt = $active_menu->_runtime;
$built_item = $active_rt->{items}{'remove-me'};
my $reentrant_ok = eval { $active_menu->run([]); 1 };
ok( !$reentrant_ok, 'active menu refuses a second simultaneous run' );
like( $@, qr/already active/, 'reentrant run error identifies the active lifecycle' );
$active_menu->remove('remove-me');
ok( !exists $active_rt->{items}{nested}, 'removing a parent recursively forgets descendants' );
ok( $built_item->{removed}, 'removed item is marked unavailable' );
$built_item->remove;
$active_menu->remove('not-present');
ok( Developer::Dashboard::System::Menu::_shutdown_active_helpers(),
'shutdown helper handles an active runtime explicitly' );
my @shutdown_warnings;
{
local *Developer::Dashboard::System::Menu::_stop = sub {
die "simulated shutdown failure\n";
};
local $SIG{__WARN__} = sub { push @shutdown_warnings, @_ };
$state->{running} = 1;
ok( Developer::Dashboard::System::Menu::_shutdown_active_helpers(),
'shutdown cleanup remains best-effort after a stop error' );
}
like( join( '', @shutdown_warnings ), qr/shutdown cleanup failed: simulated shutdown failure/,
'shutdown cleanup failure is reported visibly' );
$state->{running} = 0;
ok( Developer::Dashboard::System::Menu::_shutdown_active_helpers(),
'shutdown cleanup handles an active menu whose helper already stopped' );
my $empty_remove = eval { $active_menu->remove(''); 1 };
ok( !$empty_remove, 'remove refuses an empty name' );
like( $@, qr/non-empty name/, 'empty remove error is explicit' );
is( $active_menu->stop, $active_menu, 'stop returns the menu object' );
is( $active_rt->{active}, 0, 'stop marks active menu runtime inactive' );
my $restart_ok = eval { $active_menu->run([]); 1 };
ok( $restart_ok, 'menu can start a new run after stop during the prior event callback' )
or diag $@;
return '';
};
$active_menu->run([
{ name => 'remove-me', icon => 'x', menu => [ { name => 'nested', icon => 'y' } ] },
]);
}
ok( $state->{stopped} > 0, 'stop asks the running native helper to stop' );
my $event_stop_menu = bless { id => 'event-stop-menu' }, 'Developer::Dashboard::System::Menu';
$state->{running} = 1;
{
no warnings 'redefine';
local *Developer::Dashboard::System::Menu::_start = sub {};
local *Developer::Dashboard::System::Menu::_running = sub { $state->{running} };
local *Developer::Dashboard::System::Menu::_command_json = sub {};
local *Developer::Dashboard::System::Menu::_read_events = sub {
$event_stop_menu->stop;
return '';
};
local *Developer::Dashboard::System::Menu::_stop = sub {
$state->{event_stop_count}++;
$state->{running} = 0;
};
is( $event_stop_menu->run([]), $event_stop_menu,
'stop from the active event loop returns its menu object' );
is( $state->{event_stop_count}, 1,
'stop signals the native helper while it is running' );
}
my $error_menu = bless { id => 'error-menu' }, 'Developer::Dashboard::System::Menu';
$state->{running} = 1;
$state->{events} = [];
local *Developer::Dashboard::System::Menu::_command_json = sub { die "transport failed\n" };
my $error_ok = eval { $error_menu->run([]); 1 };
ok( !$error_ok, 'native command transport failure propagates from run' );
like( $@, qr/transport failed/, 'run preserves native transport failure text' );
my $start_error_menu = bless { id => 'start-error-menu' }, 'Developer::Dashboard::System::Menu';
local *Developer::Dashboard::System::Menu::_start = sub { die "start failed\n" };
local *Developer::Dashboard::System::Menu::_running = sub { 0 };
my $start_error_ok = eval { $start_error_menu->run([]); 1 };
ok( !$start_error_ok, 'native startup failure propagates from run' );
like( $@, qr/start failed/, 'run retains the native startup error' );
}
{
no warnings 'redefine';
my $idle_menu = bless { id => 'idle-menu' }, 'Developer::Dashboard::System::Menu';
my @commands;
my $stop_count = 0;
local *Developer::Dashboard::System::Menu::_running = sub { 0 };
local *Developer::Dashboard::System::Menu::_command_json = sub { push @commands, $_[0] };
local *Developer::Dashboard::System::Menu::_stop = sub { ++$stop_count };
ok( !Developer::Dashboard::System::Menu::_shutdown_active_helpers(),
'shutdown helper is a no-op when no menu runtime is active' );
is( $idle_menu->remove('not-running'), $idle_menu,
'remove without an active helper returns the menu object' );
is( scalar @commands, 0, 'remove does not send a command when the helper is stopped' );
is( $idle_menu->stop, $idle_menu, 'stop without an active helper returns the menu object' );
is( $stop_count, 0, 'stop does not signal a stopped helper' );
my $idle_run = bless { id => 'idle-run' }, 'Developer::Dashboard::System::Menu';
local *Developer::Dashboard::System::Menu::_start = sub {};
local *Developer::Dashboard::System::Menu::_command_json = sub { push @commands, $_[0] };
is( $idle_run->run([]), $idle_run,
'run returns normally when the native helper exits before entering its event loop' );
}
{
no warnings 'redefine';
my $post_loop_menu = bless { id => 'post-loop-dispatch' }, 'Developer::Dashboard::System::Menu';
my @running = (1, 0, 1);
my @events = (
'',
JSON::XS->new->canonical->encode({ event => 'click', name => 'late-click' }) . "\n",
);
my $late_click_count = 0;
local *Developer::Dashboard::System::Menu::_start = sub {};
local *Developer::Dashboard::System::Menu::_running = sub { shift @running // 0 };
local *Developer::Dashboard::System::Menu::_command_json = sub {};
local *Developer::Dashboard::System::Menu::_read_events = sub { shift @events };
is( $post_loop_menu->run([
{ name => 'late-click', icon => 'x', click => sub { ++$late_click_count } },
]), $post_loop_menu, 'run performs a final event drain after the native loop exits' );
is( $late_click_count, 1, 'the final event drain dispatches its pending callback once' );
}
{
my $forgotten = bless { name => 'leaf-without-children', children => undef },
'Developer::Dashboard::System::Menu::Item';
my $runtime = { items => { $forgotten->{name} => $forgotten }, roots => [$forgotten] };
Developer::Dashboard::System::Menu::_forget_item( $runtime, $forgotten );
ok( $forgotten->{removed}, 'forgetting a leaf without a child list marks it removed' );
is_deeply( $runtime->{roots}, [], 'forgetting a root leaf removes it from the roots list' );
}
{
my $scratch = tempdir( 'dd-system-menu-end-XXXXXX', CLEANUP => 1, TMPDIR => 1 );
my $marker = File::Spec->catfile( $scratch, 'end-cleanup-ran' );
my $child_source = q{
use strict;
use warnings;
use JSON::XS ();
use Developer::Dashboard::System::Menu;
{
no warnings 'redefine';
local *Developer::Dashboard::System::Menu::_start = sub {};
*Developer::Dashboard::System::Menu::_running = sub { 1 };
local *Developer::Dashboard::System::Menu::_command_json = sub {};
local *Developer::Dashboard::System::Menu::_read_events = sub {
return JSON::XS->new->canonical->encode({ event => 'click', name => 'exit' }) . "\n";
};
*Developer::Dashboard::System::Menu::_stop = sub {
open my $fh, '>', $ARGV[0] or die "Unable to write shutdown marker: $!";
print {$fh} "stopped\n";
close $fh or die "Unable to close shutdown marker: $!";
};
Developer::Dashboard::System::Menu::menu()->run([
{ name => 'exit', icon => 'x', click => sub { exit 0 } },
]);
}
};
my $pid = spawn( [ $^X, '-e', $child_source, '--', $marker ], {} );
is( wait_process($pid), 0, 'helper process exits normally after its menu callback exits' );
open my $fh, '<', $marker or die "Unable to read shutdown marker '$marker': $!";
my $marker_text = <$fh>;
close $fh or die "Unable to close shutdown marker '$marker': $!";
is( $marker_text, "stopped\n", 'END stops the native helper when Perl exits with an active menu' );
my $already_stopped_marker = File::Spec->catfile( $scratch, 'end-cleanup-already-stopped' );
my $already_stopped_source = q{
use strict;
use warnings;
use JSON::XS ();
use Developer::Dashboard::System::Menu;
{
no warnings 'redefine';
my $running_checks = 0;
local *Developer::Dashboard::System::Menu::_start = sub {};
*Developer::Dashboard::System::Menu::_running = sub { ++$running_checks == 1 };
local *Developer::Dashboard::System::Menu::_command_json = sub {};
local *Developer::Dashboard::System::Menu::_read_events = sub {
return JSON::XS->new->canonical->encode({ event => 'click', name => 'exit' }) . "\n";
};
*Developer::Dashboard::System::Menu::_stop = sub {
open my $fh, '>', $ARGV[0] or die "Unable to write shutdown marker: $!";
print {$fh} "stopped\n";
close $fh or die "Unable to close shutdown marker: $!";
};
Developer::Dashboard::System::Menu::menu()->run([
{ name => 'exit', icon => 'x', click => sub { exit 0 } },
]);
}
};
my $already_stopped_pid = spawn(
[ $^X, '-e', $already_stopped_source, '--', $already_stopped_marker ], {}
);
is( wait_process($already_stopped_pid), 0,
'helper process exits normally when its native helper has already stopped' );
ok( !-e $already_stopped_marker,
'END does not stop the native helper a second time after it has stopped' );
}
my $non_singleton = Developer::Dashboard::System::Menu::menu();
is( $non_singleton, $menu, 'repeated menu calls keep the same singleton' );
my $bad_text = eval { $builder->_build_item( { name => "\xFF", icon => 'x' }, undef, {}, {}, 0 ); 1 };
ok( $bad_text, 'invalid UTF-8 bytes are retained as plain text' );
my $valid_utf8_bytes = pack 'C*', 0xC3, 0xA9;
is( Developer::Dashboard::System::Menu::_text( $valid_utf8_bytes, 'value' ), "\x{e9}",
'valid UTF-8 bytes decode to their character value' );
{
no warnings 'redefine';
my @chunks = ( undef, '', "\n{bad-json}\n[]\n{}\r\n{\"event\":\"click\",\"name\":\"fragmented\"", "}\n" );
my $chunk_menu = bless { id => 'chunk-menu' }, 'Developer::Dashboard::System::Menu';
my $chunk_rt = {
active => 1,
items => {
fragmented => bless({ root => $chunk_menu, name => 'fragmented', icon => 'x', click => 'y', removed => 0 },
'Developer::Dashboard::System::Menu::Item'),
},
event_buffer => '',
};
local *Developer::Dashboard::System::Menu::_read_events = sub { shift @chunks };
local *Developer::Dashboard::System::Menu::_command_json = sub { $state->{fragmented_command} = $_[0] };
my @warnings;
{
local $SIG{__WARN__} = sub { push @warnings, @_ };
ok( !Developer::Dashboard::System::Menu::_dispatch_events( $chunk_menu, $chunk_rt ),
'undefined helper read returns without dispatch' );
ok( !Developer::Dashboard::System::Menu::_dispatch_events( $chunk_menu, $chunk_rt ),
'empty helper read returns without dispatch' );
ok( Developer::Dashboard::System::Menu::_dispatch_events( $chunk_menu, $chunk_rt ),
'event dispatcher accepts a non-empty chunk with malformed and empty lines' );
is( $chunk_rt->{event_buffer}, '{"event":"click","name":"fragmented"',
'incomplete helper event remains buffered until its newline arrives' );
ok( Developer::Dashboard::System::Menu::_dispatch_events( $chunk_menu, $chunk_rt ),
'event dispatcher completes a helper event split across reads' );
}
like( join( '', @warnings ), qr/invalid helper event/,
'invalid JSON and non-hash helper events are reported explicitly' );
is( JSON::XS->new->utf8->decode( $state->{fragmented_command} )->{op}, 'icon',
'fragmented click event is dispatched after the final chunk arrives' );
}
{
no warnings 'redefine';
my $stopped_by_click = bless { id => 'stop-click-menu' }, 'Developer::Dashboard::System::Menu';
my $stopped_rt = { active => 1, items => {}, event_buffer => '' };
my $stop_click_count = 0;
$stopped_rt->{items}{stop} = bless {
root => $stopped_by_click, name => 'stop', icon => 'x', removed => 0,
click => sub { ++$stop_click_count; $stopped_rt->{active} = 0 },
}, 'Developer::Dashboard::System::Menu::Item';
local *Developer::Dashboard::System::Menu::_read_events = sub {
return JSON::XS->new->canonical->encode({ event => 'click', name => 'stop' }) . "\n"
. JSON::XS->new->canonical->encode({ event => 'click', name => 'stop' }) . "\n";
};
ok( Developer::Dashboard::System::Menu::_dispatch_events( $stopped_by_click, $stopped_rt ),
'callback may stop the active event dispatch loop' );
is( $stop_click_count, 1, 'dispatch stops immediately after the callback disables the runtime' );
like( $stopped_rt->{event_buffer}, qr/\{"event":"click","name":"stop"\}/,
'later queued events remain buffered after the callback stops dispatch' );
}
my $dispatch_menu = bless { id => 'dispatch-menu' }, 'Developer::Dashboard::System::Menu';
my $dispatch_item = bless {
root => $dispatch_menu, name => 'callback-fails', icon => 'x',
click => sub { die "callback exploded\n" }, removed => 0,
}, 'Developer::Dashboard::System::Menu::Item';
my $dispatch_text = bless {
root => $dispatch_menu, name => 'text-click', icon => 'a',
click => 'b', removed => 0,
}, 'Developer::Dashboard::System::Menu::Item';
my $dispatch_removed = bless {
root => $dispatch_menu, name => 'removed', icon => 'r',
click => sub {}, removed => 1,
}, 'Developer::Dashboard::System::Menu::Item';
my $dispatch_rt = {
active => 1,
items => {
'callback-fails' => $dispatch_item,
'text-click' => $dispatch_text,
removed => $dispatch_removed,
'no-click' => bless({ root => $dispatch_menu, name => 'no-click', removed => 0 },
'Developer::Dashboard::System::Menu::Item'),
},
event_buffer => '',
};
{
no warnings 'redefine';
local *Developer::Dashboard::System::Menu::_read_events = sub {
return join '', map { JSON::XS->new->canonical->encode($_) . "\n" } (
{ event => 'click' },
{ event => 'click', name => 'absent' },
{ event => 'click', name => 'removed' },
{ event => 'click', name => 'no-click' },
{ event => 'click', name => 'callback-fails' },
{ event => 'click', name => 'text-click' },
);
};
local *Developer::Dashboard::System::Menu::_command_json = sub { $state->{last_command} = $_[0] };
local *Developer::Dashboard::System::Menu::_set_icon = sub { die "icon update failed\n" };
my @warnings;
ok( !Developer::Dashboard::System::Menu::_dispatch_events( $dispatch_menu, { active => 0 } ),
'inactive runtime ignores helper events' );
ok( !Developer::Dashboard::System::Menu::_dispatch_events( $dispatch_menu, undef ),
'missing runtime ignores helper events' );
my $dispatched;
{
local $SIG{__WARN__} = sub { push @warnings, @_ };
$dispatched = Developer::Dashboard::System::Menu::_dispatch_events(
$dispatch_menu, $dispatch_rt
);
}
ok( $dispatched, 'active runtime dispatches valid helper events' );
like( join( '', @warnings ), qr/Developer::Dashboard::System::Menu: click 'callback-fails' failed: callback exploded/s,
'callback exceptions are reported visibly' );
like( join( '', @warnings ), qr/click 'text-click' update failed: icon update failed/s,
'plain-text click update errors are reported visibly' );
}
done_testing;
END {
no warnings 'redefine';
my $running_checks = 0;
*Developer::Dashboard::System::Menu::_start = sub {};
*Developer::Dashboard::System::Menu::_running = sub { ++$running_checks == 1 };
*Developer::Dashboard::System::Menu::_command_json = sub {};
*Developer::Dashboard::System::Menu::_read_events = sub {
return JSON::XS->new->canonical->encode({ event => 'click', name => 'exit-at-end' }) . "\n";
};
*Developer::Dashboard::System::Menu::_stop = sub {};
Developer::Dashboard::System::Menu::menu()->run([
{ name => 'exit-at-end', icon => 'x', click => sub { exit 0 } },
]);
}
__END__
=head1 NAME
t/250-system-menu-coverage.t - exercise System::Menu validation and event paths
=head1 PURPOSE
Exercises the Perl validation, serialization, helper-event dispatch, and error
paths in C<Developer::Dashboard::System::Menu> without launching a desktop
native menu process.
=head1 WHY IT EXISTS
The native UI is unavailable in headless test containers, but the Perl adapter
contains meaningful branching that must remain covered. Replacing only the
native boundary with local stubs keeps these tests deterministic while still
testing the production adapter code.
=head1 WHEN TO USE
Run this file in the dev Docker service after changing System::Menu validation,
nested items, callback handling, or native event transport.
=head1 HOW TO USE
d2 docker compose exec dev prove -lv t/250-system-menu-coverage.t
The test covers malformed API input, plain and UTF-8-flagged text, nested menu
defaults, duplicate names, native event parsing, callback dispatch, and
transport failure propagation.
t/683-install-native-menu-prereqs.t view on Meta::CPAN
my $line = $_;
$line =~ s/\s*#.*$//;
$line =~ s/^\s+|\s+$//g;
$line;
} split /\n/, $text;
}
sub _has_package {
my ( $name, $package ) = @_;
my %packages = map { $_ => 1 } _manifest_lines($name);
ok( $packages{$package}, "$name includes $package for the Linux System Menu native helper" );
}
for my $manifest (qw(aptfile apkfile dnfile)) {
my @packages = _manifest_lines($manifest);
ok( !( grep { /(?:gtk|ayatana-appindicator)/i } @packages ),
"$manifest does not force optional GTK/Ayatana development packages" );
}
my $installer = _slurp( File::Spec->catfile( $ROOT, 'install.sh' ) );
unlike( $installer, qr/^(?:libgtk-3-dev|libayatana-appindicator3-dev|libayatana-appindicator-dev|libayatana-appindicator-gtk3-devel)$/m,
t/683-install-native-menu-prereqs.t view on Meta::CPAN
=head1 DESCRIPTION
Checks that Linux bootstrap manifests do not force GTK3/Ayatana development
packages on hosts that do not have them, and that C<Makefile.PL> gates the
optional native menu helper on the corresponding pkg-config modules.
=head1 PURPOSE
Keep source-checkout and streamed Linux installs independent of optional
native System Menu development packages.
=head1 WHY IT EXISTS
The native Linux menu helper is optional. Missing GTK3 or Ayatana development
packages must not prevent the Perl distribution from building or installing.
=head1 WHEN TO USE
Run this test whenever changing Linux installer manifests, C<install.sh>
embedded package fallbacks, or native System Menu build dependencies.
=head1 HOW TO USE
Run the focused regression with:
prove -lv t/683-install-native-menu-prereqs.t
=head1 WHAT USES IT
Debian/Ubuntu, Alpine, and Fedora bootstrap installs use these manifests before