An offering to the Perl enthusiasts among us
Soren
somian08@gmail.com
Tue Mar 24 16:17:06 GMT 2026
Greetings cygwinistas.
I've written a program in Perl that satisfies a desire I've had for a
while. I wanted to have a way to check out what Perl module distributions
have been made into cygwin packages installable with Setup, but outside of
Setup. The main feature of how the program works is the specification of
"namespace globs" like "IO-*" or "Module-*" used as the argument to my
script. This allows for surveying a manageable grouping of packages from
the Cygwin server, in the TMI (terminal, text mode interface, commandline).
I think it's best if I just show some representative output rather than
struggling to explain what I mean:
$ perl ~/Scripts-working/cygchk-perl-mods.pl 'perl-Module-*'
Matching distributions packaged for Cygwin:
Fetching setup.ini from cygwin.com...
perl-Module-Build Module::Build is installed as
/usr/local/share/perl5/site_perl/5.40/Module/Build.pm
perl-Module-Build-Tiny Module::Build::Tiny is installed as
/usr/local/share/perl5/site_perl/5.40/Module/Build/Tiny.pm
perl-Module-Build-XSUtil Module::Build::XSUtil is installed as
/usr/local/share/perl5/site_perl/5.40/Module/Build/XSUtil.pm
perl-Module-Implementation Module::Implementation is installed as
/usr/local/share/perl5/site_perl/5.40/Module/Implementation.pm
perl-Module-Install Module::Install is installed as
/usr/local/share/perl5/site_perl/5.40/Module/Install.pm
perl-Module-Metadata Module::Metadata is installed as
/usr/share/perl5/5.40/Module/Metadata.pm
perl-Module-Pluggable Module::Pluggable is installed as
/usr/local/share/perl5/site_perl/5.40/Module/Pluggable.pm
perl-Module-Runtime Module::Runtime is installed as
/usr/local/share/perl5/site_perl/5.40/Module/Runtime.pm
perl-Module-ScanDeps Module::ScanDeps is installed as
/usr/local/share/perl5/site_perl/5.40/Module/ScanDeps.pm
perl-Module-Signature Module::Signature is not installed
That's how it produces output. The point of this is twofold. One is that
there are hundreds of packaged modules in Setup and I find myself squinting
and getting a headache if I just try to scroll through the huge list that
matches "perl-". The other point is that the output allows me to check
whether I've built a module from CPAN and perl has installed it under
"site_perl/" (which has the consequence that it has precedence over modules
installed to "vendor_perl/" [which is called "shadowing"]).
I could possibly add features to this program: displaying the version of
the module installed would be one nice thing. But I believe in the unix
virtue of "small tools that do one thing well" (and I am a bit busy, yeah)
and so for now I'll avoid feeping creaturism and just show y'all the script:
(If you prefer to download rather than c&p I've made a gist for it at
https://gist.github.com/somian/22f6d1baae1b44c6c1e0cb0ea867e0a5)
#!/usr/bin/perl
# Last modified: Tue Mar 24 11:57:45 2026
use strict;
use v5.18;
use utf8;
use warnings;
use Carp qw/ carp croak /;
=head1 NAME
cygchk-perlmods.pl
=head1 SYNOPSIS
cygchk-perlmods.pl "IO-*" # "glob expression"
=head1 VERSION
0.10
=head1 AUTHOR
Soren Andersen C<somian08@gmail.com>
=cut
if ( @ARGV * 1 == 0 ) {
croak 'You must type an argument. Exiting.';
}
my ($globexpr) = @ARGV;
my $as_perl_says;
if ($globexpr !~/^perl-/) { # you may omit the "perl-" prefix in the
argument
$globexpr = 'perl-' . $globexpr;
}
$globexpr = lc $globexpr;
open( my $ok_fh, '-|', "cygcheck", "-e", $globexpr);
croak "Dying from no open on cygcheck" unless $ok_fh;
printf( "Matching distributions packaged for Cygwin:\n" );
my ( @dists, $mlen );
$mlen = 0;
while (<$ok_fh>) {
my $setup_name = $_;
my $nonly = (split( ' : ' ))[0];
$mlen = length($nonly) > $mlen ? length($nonly) : $mlen;
push @dists, $nonly;
}
for (@dists) {
my $e = substr($_,5);
$e =~s/-/::/g;
$as_perl_says = $e;
my $report_str = sprintf( "%-${mlen}s %s" =>
$_, $as_perl_says );
$report_str .= q[ ].chk_inst( $as_perl_says );
say $report_str;
}
sub chk_inst {
local $::pkgname = $_[0];
eval qq{require $::pkgname;};
unless ( $@ ) {
my $pm = $_[0];
$pm =~ s{::}{/}g;
$pm .= '.pm';
return 'is installed as '. $INC{ $pm };
} else {
return 'is not installed';
}
}
__END__
=head1 LICENSE
This program is Free software, made available under the same terms as Perl.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
=cut
# vim: ft=perl et sw=4 ts=4 :
--
Soren
More information about the Cygwin
mailing list