A bag o' tricks from the Perlmeister
Creating Packages
CPAN accepts tarballs, but to give your users more convenience, you may want to convert the build into a package for the target distributions such as Debian or RPM. If you are not worried about downloading about half of all CPAN modules ever created as dependencies, you can go for Dist::Zilla. For those who prefer a more lightweight approach, I recommend the Ruby tool fpm
[7].
With a reasonably fresh Ruby version, the practical tool installs itself after you type gem install fpm
. It supports numerous options, but to bundle a number of files into a package using one of the supported formats (RPM, Debian, or OS X), you will only need to specify the package type with -t
and point fpm
to the source files under usr
to be included with -s usr
.
In the directory, as the tree
command in Figure 4 shows, the files are stored exactly as they will be placed on the system when installed, that is with the foo
script in usr/bin/foo
and the Perl module Foo.pm
in usr/lib/perl5/site_perl/Foo.pm
. The example specifies Debian as the package format (-t deb
); a .deb
file with the specified version number is thus created.
The tool is fantastically easy to use and shields developers from what are sometimes quite tragic implementations of specific package bundlers, such as rpmbuild
. It can also resolve dependencies on other packages, and it is certainly something that should not be missing from any tool box.
Into the Box
Some new projects may have dependencies on a whole bunch of CPAN modules, for which packages for the end user's distribution may not exist. The time-consuming workaround of opening a CPAN shell and initializing, followed by installing a few dozen modules, which in turn have dependencies on more modules, is something end users shouldn't be burdened with. This is especially true if the target group normally has nothing to do with Perl, and only wants to use a new command-line utility provided by the project.
In these cases, the Carton CPAN module provides invaluable services, because it automatically resolves dependencies stored in a cpanfile
with the following format:
requires 'Log::Log4perl', '1.0'; requires 'Pod::Usage', '0.01';
After onboarding indirectly dependent modules, with carton install, it launches a build process for the whole enchilada in a newly created local
directory. If you then push the results into the directory of the utility discussed in the previous section, fpm
, the tool puts together a package that will work on the target systems regardless of installed modules, thus resulting in a robust release.
Bugs? What Bugs?
All programmers make mistakes, and sometimes you need to put on your crime scene cleaner suit and trudge through the code with Perl's debugger to see where the problem lies. If the problem does not occur at the beginning of the script, but in the middle of a module, you can set a break point in the associated function, step through to the point in question manually, or use my favorite Perl trick: A statement planted at the desired location in the code, like this:
$DB::single = 1;
stops the debugger started with perl -d <script>
and c
at precisely this point. But, sometimes perl
rummages through code even before the actual show in the main program begins. For example, the ORM wrapper Rose::DB creates its data structures while a database module is being loaded with the use My::Data
command.
How can you launch a script that uses this module, so that the debugger stops in My::Data and not just in the first line of the main program? If you add the following line
BEGIN { $DB::single = 1 }
at the beginning of the script, the debugger stops at the first executable line, regardless of whether it's in the main program or somewhere else.
« Previous 1 2 3 4 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.