Rewriting a script for the Homebrew package managertaught me how the Goprogramming language’s design choices align with platform-ready tools.
The problem with brew upgrade
By default, the brew upgradecommand updates every formula(terminal utility or library). It also updates every cask(GUI application) it manages. All are upgraded to the latest version — major, minor, and patch. That’s convenient when you want the newest features, but disruptive when you only want quiet patch-level fixes.
Last weekI solved this in Perlwith brew-patch-upgrade.pl, a script that parsed brew upgrade’s JSON output, compared semantic versions, and upgraded only when the patch number changed. It worked, but it also reminded me how much Perl leans on implicit structures and runtime flexibility.
This week I ported the script to Go, the lingua francaof DevOps. The goal wasn’t feature parity — it was to see how Go’s design choices map onto platform engineering concerns.
Why port to Go?
Portfolio practice: I’m building a body of work that demonstrates platform engineeringskills.
Operational focus: Go is widely used for tooling in infrastructure and cloud environments.
Learning by contrast: Rewriting a working Perl script in Go forces me to confront differences in error handling, type safety, and distribution.
The Go version is noisier, but it forces explicit decisions. That’s a feature in production tooling: no silent failures.
Dependency management
Perl: cpanfile+ CPAN modules. Distribution means “install Perl(if it’s not already), install modules, run script.” Tools like cartonand the cpanor cpanmcommands help automate this. Additionally, one can use further tooling like fatpackand ppto build more self-contained packages. But those are neither common nor (except for cpan) distributed with Perl.
Go: go.mod+ go build. Distribution is a single (platform-specific) binary.
For operational tools, that’s a massive simplification. No runtime interpreter, no dependency dance.
type Formula struct {
Name string `json:"name"`
CurrentVersion string `json:"current_version"`
InstalledVersions []string `json:"installed_versions"`
}
The compiler enforces assumptions that Perl left implicit. That friction is valuable — it surfaces errors early.
Binary distribution
This is where Go shines. Instead of telling colleagues “install Perlv5.34 and CPAN modules,” I can hand them a binary. No need to worry about scripting runtime environments — just grab the right file for your system.
Available on the release page. Download, run, done.
Semantic versioning logic
In Perl, I manually compared arrays of version numbers. In Go, I imported golang.org/x/mod/semver:
import (
golang.org/x/mod/semver
)
...
if semver.MajorMinor(toSemver(formula.InstalledVersions[0])) !=
semver.MajorMinor(toSemver(formula.CurrentVersion)) {
log.Printf("%s is not a patch upgrade", formula.Name)
results.skipped++
continue
}
Cleaner, more legible, and less error-prone. The library encodes the convention, so I don’t have to.
Deliberate simplification
I didn’t port every feature. Logging adapters,signalhandlers, and edge-case diagnostics remained in Perl. The Go version focuses on the core logic: parse JSON, compare versions, run upgrades. That restraint was intentional — I wanted to learn Go’s idioms, not replicate every Perl flourish.
Platform engineering insights
Three lessons stood out:
Binary distribution matters.Operational tools should be installable with a single copy step. Go makes that trivial.
Semantic versioningis an operational practice.It’s not just a convention for library authors — it’s a contract that tooling can enforce.
Go’s design aligns with platform needs.Explicit errors, type safety, and static binaries all reduce surprises in production.
Bringing it home
This isn’t a “Perl vs. Go” story. It’s a story about deliberate simplification, taking a working Perl script and recasting it in Go. The aim is to see how the language’s choices shape a solution to the same problem.
The result is homebrew-semver-guardv0.1.0, a small but sturdy tool. It’s not feature-finished, but it’s production-ready in the ways that matter.
Next up: I’m considering more Go tools, maybe even Kubernetes for services on my home server. This port was practice, an artifact demonstrating platform engineering in action.
At first, I just wanted Homebrewto behave a little more politely. Formulaeshould upgrade only on patch changes, without being dragged through minor and major bumps. That itch became a small(ish) Perl script, brew-patch-upgrade.pl.
Along the way, I discovered another patch was needed. My own logging adapter, Log::Any::Adapter::MacOS::OSLog, wasn’t building and installing its bundle correctly. Before the script can shine in the Mac Console app, I had to fix the adapter itself.
What follows is how those two threads came together. One is a tool that keeps Homebrew upgrades patch-perfect. The other is a logging adapter that finally behaves as a first-class Perl module.
What is Homebrew?
Not to be confused with perlbrew,Homebrewis a free and open-source package manager for macOS (and Linux). It makes it easy to install and update software from the command line. You don’t have to hunt down installers on websites. Instead, you can type commands like brew install wget. Homebrew will then fetch, build, and link the tool into place.
Everything is organized under /opt/homebrew(on Apple Silicon-based Macs) or /usr/local(on Intel). Homebrew can even manage both command‑line utilities (“formulae”) and desktop apps (“casks”).
In short: it’s the missing package manager Apple never shipped, and it’s become an essential part of many developers’ workflows.
Homebrew makes it easy to stay up to date — sometimes tooeasy. By default, brew upgradejumps to the latest version of everything, even across minor and major releases.
That’s fine when you want the newest features. Yet, it can be disruptive if all you really need are the quiet, patch-level fixes.
Scripted patch-only upgrades
My brew‑patch‑upgrade.pltakes a narrower view: it parses brew outdatedcommand, compares semantic versions, and upgrades only when the patch number changes.
That means:
3.2.1→ 3.2.4will be upgraded.
3.2.1→ 3.3.0will be skipped.
3.2.1→ 4.0.0will be skipped.
Normally, the script’s output is comparable to brew upgrade, streaming the familiar Homebrew output to your terminal for any patch-level updates while noting any skipped versions:
% brew-patch-upgrade.pl
Skipping harfbuzz, needs manual review before upgrade at /Users/mjg/.local/bin/brew-patch-upgrade.pl line 178.
main::process_formula(HASH(0x7c075dc90)) called at /Users/mjg/.local/bin/brew-patch-upgrade.pl line 121
Skipping woodpecker-cli, needs manual review before upgrade at /Users/mjg/.local/bin/brew-patch-upgrade.pl line 178.
main::process_formula(HASH(0x7c0c1a180)) called at /Users/mjg/.local/bin/brew-patch-upgrade.pl line 121
==> Upgrading 1 outdated package:
zstd 1.5.6 -> 1.5.7
==> Fetching downloads for: zstd
==> Fetching zstd
==> Downloading https://ghcr.io/v2/homebrew/core/zstd/blobs/sha256:ddb0c145060bc2366ce5d58d95aa205bb15cb4c66948f20bb85e23fdb5eba7e9
Already downloaded: /Users/mjg/Library/Caches/Homebrew/downloads/eb865576547e163ef6908f1e5762f4dc4d7fb548940f7b896ae12c0d5b202362--zstd--1.5.7.arm64_tahoe.bottle.1.tar.gz
==> Upgrading zstd
1.5.6 -> 1.5.7
==> Pouring zstd--1.5.7.arm64_tahoe.bottle.1.tar.gz
🍺 /opt/homebrew/Cellar/zstd/1.5.7: 32 files, 2.2MB
==> Running `brew cleanup zstd`...
Disable this behaviour by setting `HOMEBREW_NO_INSTALL_CLEANUP=1`.
Hide these hints with `HOMEBREW_NO_ENV_HINTS=1` (see `man brew`).
Removing: /opt/homebrew/Cellar/zstd/1.5.6... (32 files, 2.1MB)
Removing: /Users/mjg/Library/Caches/Homebrew/zstd_bottle_manifest--1.5.6... (11.9KB)
Removing: /Users/mjg/Library/Caches/Homebrew/zstd--1.5.6... (753.9KB)
==> No outdated dependents to upgrade!
But since I intended this to run unattended on a schedule, you can also tell it to log to a different destination using the environment variable LOG_ANY_DEFAULT_ADAPTER:
% LOG_ANY_DEFAULT_ADAPTER=Stderr brew-patch-upgrade.pl
using log adapter Log::Any::Adapter::Stderr
outdated formulae: {casks => [],formulae => [{current_version => "12.0.0",installed_versions => ["11.5.1"],name => "harfbuzz",pinned => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ),pinned_version => undef},{current_version => "3.10.0",installed_versions => ["3.9.0"],name => "woodpecker-cli",pinned => $VAR1->{formulae}[0]{pinned},pinned_version => undef},{current_version => "1.5.7",installed_versions => ["1.5.6","1.5.7"],name => "zstd",pinned => $VAR1->{formulae}[0]{pinned},pinned_version => undef}]}
Skipping harfbuzz, needs manual review before upgrade at /Users/mjg/.local/bin/brew-patch-upgrade.pl line 178.
main::process_formula(HASH(0xa1a01f510)) called at /Users/mjg/.local/bin/brew-patch-upgrade.pl line 121
Skipping woodpecker-cli, needs manual review before upgrade at /Users/mjg/.local/bin/brew-patch-upgrade.pl line 178.
main::process_formula(HASH(0xa1acbcf30)) called at /Users/mjg/.local/bin/brew-patch-upgrade.pl line 121
Starting brew upgrade for zstd...
==> Upgrading 1 outdated package:
zstd 1.5.6 -> 1.5.7
Finished brew upgrade for zstd
Summary: upgraded 1, skipped 2, failed 0
That’s useful for debugging. But, the real payoff comes when you send logs to a more sophisticated adapter. A good example is my Log::Any::Adapter::MacOS::OSLogpackage. It tags different levels of log messages in macOS’ unified logging system. These messages can then be filtered and searched in the Console utility app.
And produces results that can be viewed in Console:
Or using the macOS log showcommand:
At the end, the script logs a summary of upgraded, skipped, and failed formulae. On failure, it exits non-zero to make it easy to use in automation.
Highlights from the script source code
For those curious about the internals, here are a few highlights from the source.
Skipping major and minor version bumps
use version;
...
sub process_formula ($formula_ref) {
my $name = $formula_ref->{name};
my ( $current, $installed ) = map { defined and qv($_) } (
$formula_ref->{current_version},
$formula_ref->{installed_versions}->[0] );
unless ( $current and $installed ) {
$logger->debug(
'no current and/or installed version detected for',
$name );
return 'skipped';
}
my $result = 'failed'; # default
my @current = $current->{version}->@*;
my @installed = $installed->{version}->@*;
#<<<
unless (@current >= 3
and @installed >= 3
and $installed[0] == $current[0]
and $installed[1] == $current[1]
and $installed[2] < $current[2] )
#>>>
{
carp "Skipping $name, needs manual review before upgrade";
return 'skipped';
}
...
At the start, process_formulachecks whether a formula from brew outdatedhas a valid semantic version. Only then does it compare patch numbers.
To that end, it uses the core Perl versionmodule’s qvfunction. This parses the current and latest installed version, avoiding a complicated regular expression. The resulting version objects can be treated as hash references with a versionkey. This key is itself a reference to an array containing the major, minor, and patch version numbers. If the major or minor version numbers differ between installed and current, the script calls for a manual review. Then it returns a “skipped” status.
Setting up the loggers
use Log::Any qw($logger);
use Log::Any::Adapter;
...
use constant {
MAC_LOG_ADAPTER_CLASS => 'Log::Any::Adapter::MacOS::OSLog',
MAC_LOG_SUBSYSTEM => 'com.phoenixtrap.brew-patch-upgrade',
};
my %brew_log;
if ( $ENV{LOG_ANY_DEFAULT_ADAPTER} ) {
my $adapter = Log::Any::Adapter->get(__PACKAGE__);
Log::Any::Adapter->set( q(+) . ref $adapter,
subsystem => MAC_LOG_SUBSYSTEM )
if $adapter->isa(MAC_LOG_ADAPTER_CLASS);
$logger->debug( 'using log adapter', ref $adapter );
$SIG{__WARN__} = sub ($message) { $logger->alert($message) };
$SIG{__DIE__} = sub ($message) { $logger->fatal($message) };
foreach my $stdio (qw(stdout stderr)) {
Log::Any::Adapter->set(
{ category => "brew.$stdio" },
q(+) . ref $adapter,
( subsystem => MAC_LOG_SUBSYSTEM,
os_category => "brew-$stdio",
)x!!$adapter->isa(MAC_LOG_ADAPTER_CLASS),
);
$brew_log{$stdio}
= Log::Any->get_logger( category => "brew.$stdio" );
}
}
If LOG_ANY_DEFAULT_ADAPTERis set, the script creates three loggers: one for the program itself, one for brew.stdout, and one for brew.stderr. All three have logic to check if the default logger class is Log::Any::Adapter::MacOS::OSLog. If it is, an appropriate OS-level logging category is set. A unique subsystem name for the script, “com.phoenixtrap.brew-patch-upgrade”, is also assigned.
Unfortunately, while working on this macOS-specific logging code, I made a discovery. I realized that I needed to fix my log adapter class with a patch of its own.
OSLog revisited
I was proud of my earlier workon the MacOS::OSLoglog adapter — a clever wrapper around macOS’ logging functions using Perl foreign function interface (FFI). I even took a victory lap, converting the CPAN distribution to use Dist::Zilla for pluggable installer creation and documentation.
But outside the packaged maclogscript, the module didn’t work. Oops.
Once I tried using the MacOS::OSLogadapter in brew-patch-upgrade.pl, the cracks became obvious. The bundle wasn’t built or installed correctly. My _find_my_bundlehackwas brittle — not a foundation to build on.
The solution was to stop faking it and let the FFI::Platypustoolchain do its job. Using Dist::Zilla::Plugin::MakeMaker::Awesomein my dist.inifile, I rewrote the build process to use FFI::Build::MMin the generated Makefile.PLinstaller. This meant that the bundle would compile and install in the right place instead of relying on my _find_my_bundlehack:
The location of the C source code as well as compilation flags moved to a separate ffi/OSLog.fbxfile, which FFI::Build::MMwould infer the name of based on the arguments passed to its mm_argsmethod.
I also updated the C source codewith an #include <ffi_platypus_bundle.h>line, giving the resulting code bundle a proper entry point that FFI::Platypuscould recognize.
With those fixes, the adapter now works as a native-grade component. No hacks. No guessing. Just clean, structured logs flowing into the unified logging system.
Each run of brew-patch-upgrade.plnow shows a clear subsystem, with categories for STDOUT, STDERR, and the script itself. This makes it easy to filter and review. And because the script exits with a summary line and proper exit code, it slots neatly into automation as well.
In other words, the logging side of brew-patch-upgrade.plis now as patch-perfect as the upgrade logic it supports.
Looking back, I realized that this project wasn’t just about taming Homebrew’s upgrades or fixing a stubborn Perl module. It was about creating a stronger connection between the tools I rely on and their expected behavior. I want them to be predictable, legible, and resilient. Both packages work together, keeping my upgrades quiet and intentional while surfacing them in the Console app.
Both the scriptand log adapterare on Codeberg, with the adapter also on CPAN. If you’d like to try them out, file issues, or suggest improvements, the repos are waiting.