App-PMUtils
view release on metacpan or search on metacpan
script/pmversion view on Meta::CPAN
$SPEC{pmversion} = {
v => 1.1,
summary => 'Get Perl module version',
description => <<'_',
_
args => {
module => $App::PMUtils::arg_module_multiple,
method => {
schema => ['str*', in=>[qw/load mm/]],
default => 'mm',
description => <<'_',
`load` means to load the module and read the package variable `$VERSION`. This
means you have to actually execute the module's source code.
`mm` means using <pm:ExtUtils::MakeMaker>'s `MM->parse_version`. This uses
simple regex over the module's source code and does not require you to actually
execute the source code.
_
},
},
};
sub pmversion {
require Module::Path::More;
my %args = @_;
my $mods = $args{module};
my $meth = $args{method} // 'mm';
my $found;
my $res = [];
for my $mod (@$mods) {
$mod =~ s!/!::!g;
my $mpath = Module::Path::More::module_path(module=>$mod);
unless ($mpath) {
push @$res, "Module $mod is not installed";
next;
}
$found++;
my $v;
if ($meth eq 'load') {
require Module::Load;
no strict 'refs'; ## no critic: TestingAndDebugging::RequireUseStrict
Module::Load::load($mod);
$v = ${"$mod\::VERSION"};
} else {
$v = MM->parse_version($mpath);
$v = undef if defined($v) && $v eq 'undef';
}
if (defined $v) {
push @$res, (@$mods > 1 ? "$mod $v" : $v);
} else {
push @$res, "Module $mod does not define \$VERSION";
}
}
if (!$found) {
[404, "No such module(s): " . join(", ", @$mods)];
} else {
[200, "OK", $res];
}
}
Perinci::CmdLine::Any->new(
url => '/main/pmversion',
read_config => 0,
read_env => 0,
)->run;
# ABSTRACT: Get Perl module version
# PODNAME: pmversion
__END__
=pod
=encoding UTF-8
=head1 NAME
pmversion - Get Perl module version
=head1 VERSION
This document describes version 0.745 of pmversion (from Perl distribution App-PMUtils), released on 2024-08-30.
=head1 SYNOPSIS
% pmversion Some::Module Another::Module
=head1 OPTIONS
C<*> marks required options.
=head2 Main options
=over
=item B<--method>=I<s>
Default value:
"mm"
Valid values:
["load","mm"]
C<load> means to load the module and read the package variable C<$VERSION>. This
means you have to actually execute the module's source code.
C<mm> means using L<ExtUtils::MakeMaker>'s C<< MM-E<gt>parse_version >>. This uses
simple regex over the module's source code and does not require you to actually
execute the source code.
=item B<--module-json>=I<s>
( run in 0.804 second using v1.01-cache-2.11-cpan-39bf76dae61 )