Acme-TLDR
view release on metacpan or search on metacpan
lib/Acme/TLDR.pm view on Meta::CPAN
FILTER_ONLY
code => sub {
my $installed = _installed();
my $shortened = _shorten($installed);
while (my ($long, $short) = each %{$shortened}) {
s{\b\Q$short\E\b}{$long}gsx;
}
};
sub _debug {
my ($fmt, @args) = @_;
printf STDERR qq($fmt\n) => @args
if exists $ENV{DEBUG};
return;
}
sub _installed {
my $cache = catfile(
File::HomeDir->my_data,
q(.Acme-TLDR-) . md5_hex(join ':' => sort @INC) . q(.cache)
);
_debug(q(ExtUtils::Installed cache: %s), $cache);
my $updated = -M $cache;
my $modules;
if (
not defined $updated
or
grep { -e and -M _ < $updated }
map { catfile($_, q(perllocal.pod)) }
@INC
) {
## no critic (ProhibitPackageVars)
_debug(q(no cache found; generating));
$modules = [
uniq
keys %{$Module::CoreList::version{$]}},
ExtUtils::Installed->new->modules,
];
store $modules => $cache
unless exists $ENV{NOCACHE};
} else {
_debug(q(reading from cache));
$modules = retrieve $cache;
}
return $modules;
}
sub _shorten {
my ($modules) = @_;
my %collisions = map { $_ => 1 } @{$modules};
my %modules;
lib/Acme/TLDR.pm view on Meta::CPAN
for my $long (sort @{$modules}) {
my @parts = split /\b|(?=[A-Z0-9])/x, $long;
next unless $#parts;
my $short = join q() => map { /^(\w)\w{3,}$/x ? $1 : $_ } @parts;
next if $short eq $long;
unless (exists $collisions{$short}) {
++$collisions{$short};
$modules{$long} = $short;
_debug(q(%-64s => %s), $long, $short);
} else {
_debug(q(%-64s => *undef*), $long);
}
}
return \%modules;
}
1;
__END__
( run in 0.330 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )