Acme-TLDR

 view release on metacpan or  search on metacpan

lib/Acme/TLDR.pm  view on Meta::CPAN

package Acme::TLDR;
# ABSTRACT: Abbreviate Perl namespaces for the Extreme Perl Golf


use strict;
use utf8;
use warnings qw(all);

use Digest::MD5 qw(md5_hex);
use ExtUtils::Installed;
use File::HomeDir;
use File::Spec::Functions;
use Filter::Simple;
use List::MoreUtils qw(uniq);
use Module::CoreList;
use Storable;

our $VERSION = '0.004'; # VERSION


# hack; only absolute paths
BEGIN { @main::INC = grep { substr($_, 0, 1) eq substr($^X, 0, 1) } @INC }

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};



( run in 3.855 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )