App-PMUtils
view release on metacpan or search on metacpan
lib/App/PMUtils.pm view on Meta::CPAN
summary => 'Absolutify each path',
schema => 'bool',
cmdline_aliases => {P=>{}},
},
prefix => {
schema => ['int*', min=>0],
default => 0,
},
dir => {
summary => 'Show directory instead of path',
description => <<'_',
Also, will return `.` if not found, so you can conveniently do this on a Unix
shell:
% cd `pmpath -Pd Moose`
and it won't change directory if the module doesn't exist.
_
schema => ['bool', is=>1],
cmdline_aliases => {d=>{}},
},
},
};
sub pmpath {
require Module::Path::More;
my %args = @_;
my $mods = $args{module};
my $res = [];
my $found;
for my $mod (@{$mods}) {
my $mpath = Module::Path::More::module_path(
module => $mod,
find_pm => $args{pm},
find_pmc => $args{pmc},
find_pod => $args{pod},
find_prefix => $args{prefix},
abs => $args{abs},
all => $args{all},
);
$found++ if $mpath;
for (ref($mpath) eq 'ARRAY' ? @$mpath : ($mpath)) {
if ($args{dir}) {
require File::Spec;
my ($vol, $dir, $file) = File::Spec->splitpath($_);
$_ = $dir;
}
push @$res, @$mods > 1 ? {module=>$mod, path=>$_} : $_;
}
}
if ($found) {
[200, "OK", $res];
} else {
if ($args{dir}) {
[200, "OK (not found)", "."];
} else {
[404, "No such module"];
}
}
}
$SPEC{pmdir} = do {
my $meta = { %{ $SPEC{pmpath} } }; # shallow copy
$meta->{summary} = "Get directory of locally installed Perl module/prefix";
$meta->{description} = <<'_';
This is basically a shortcut for:
% pmpath -Pd MODULE_OR_PREFIX_NAME
Sometimes I forgot that <prog:pmpath> has a `-d` option, and often intuitively
look for a <prog:pmdir> command.
_
$meta->{args} = { %{ $SPEC{pmpath}{args} } }; # shalow copy
delete $meta->{args}{all};
delete $meta->{args}{dir};
delete $meta->{args}{prefix};
$meta;
};
sub pmdir {
pmpath(@_, prefix=>1, dir=>1);
}
$SPEC{rel2mod} = {
v => 1.1,
summary => 'Convert release name (e.g. Foo-Bar-1.23.tar.gz) to '.
'module name (Foo::Bar)',
args => {
releases => {
#'x.name.is_plural' => 1,
schema => ['array*', of=>'str*'],
req => 1,
pos => 0,
greedy => 1,
cmdline_src => 'stdin_or_args',
},
},
result_naked => 1,
};
sub rel2mod {
my %args = @_;
#use DD; dd \%args;
my @res;
for (@{ $args{releases} }) {
s!.+/!!; # remove directory path
s/(.+)-v?\d.+/$1/;
s/-/::/g;
push @res, $_;
}
\@res;
}
$SPEC{pmunlink} = {
( run in 2.160 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )