in reply to Re: How do I package up a Perl-TK app for macOS?
in thread How do I package up a Perl-TK app for macOS?

Thanks for the reply, perlbrew definitely sounds interesting, but how does it work in order to build Tk and other Perl modules, are Macports or Homebrew packages still needed for the various FOSS libraries like libjpeg and so on that Tk and other Perl modules depend on or is Perlbrew self contained from this point of view too?
  • Comment on Re^2: How do I package up a Perl-TK app for macOS?

Replies are listed 'Best First'.
Re^3: How do I package up a Perl-TK app for macOS?
by starX (Chaplain) on Nov 14, 2025 at 21:31 UTC

    Obligatory disclaimer that I only used it the one time, so there are some gaps in my knowledge on this, but perlbrew lets you build a private perl environment (or multiple private perl environments) separate from your system perl environment, and everything in that environment is essentially its own sandbox, with its own bin/, lib/, and man./ directories. Any modules need to be installed for the perlbrew environment through cpan inside of perlbrew. Perl/Tk is a wrapper around Tcl/Tk and may reference system libraries (i.e. X11 or image libraries) that are not part of perlbrew, and perlbrew does not provide them.

    In practice, if you install XQuartz, Perl/Tk build scripts should detect X11 headers and libraries installed in /opt/X11 as normal. I believe XQuartz will install libjpeg for you, but if not, installing those through Homebrew or Macports should work. Modules like Tk will compile against the system libraries that they find -- which is something you might have to be careful about if there are multiple instances of those installed on your system.

    The advantage to the perlbrew method was to build an isolated perl environment for the .app bundle that would not rely on the presence of whatever perl environment comes on a mac, which will let you ensure cpan module compatibility for the private environment in your app bundle. But this is why you would want your .app bundle to check for the presence of XQuartz and direct users to install it if they don't have it, as those system resources still need to be installed at the system level.

Re^3: How do I package up a Perl-TK app for macOS?
by cavac (Prior) on Nov 18, 2025 at 12:20 UTC

    SCNR, but if you are lucky the target system has the required tools (compiler etc) to do the module installation, so you might not need to bundle Tk, but could just automagically run the CPAN install when needed. Of course, you could also run the commands to install the compiler first.

    Visual Studio and Android Studio do the same thing, so if anyone asks, you can always say you are following industry standard practices ;-)

    #!/usr/bin/env perl use strict; use warnings; use CPAN; use Module::Load; BEGIN { my @extramodules = ('Tk', 'Net::Clacks::Client'); foreach my $extramodule (@extramodules) { my $firstrun = 1; eval { load $extramodule; $firstrun = 0; }; if($firstrun) { # Run some commands to install required system tools. IDK +macos, so *shrug* # `brew install --yes gcc` print "Installing $extramodule...\n"; CPAN::Shell->install($extramodule); # Tk install runs a lot of tests that pop of weird windows +, but you could install without the tests #CPAN::Shell->notest('install', $extramodule); print "Installation complete, calling use again...\n"; load $extramodule; } else { print "Module loaded\n"; } } } my $top = MainWindow->new(); print "Done\n";

    Edit: There are more than one ways to pack a camel. Your BEGIN block could just download&unzip a copy of your own lib directory and make sure it is in @INC. Or something along those lines.

    PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
    Also check out my sisters artwork and my weekly webcomics