| 1 | package lazy; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use 5.024; # App::cpm and its toolchain family require Perl 5.24+ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use feature qw( state ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | our $VERSION = '1.000003'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use App::cpm 1 (); # CLI has no $VERSION; v0.998xxx range is broken (GH#38) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use App::cpm::CLI (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use Carp qw( longmess ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Sub::Name qw( subname ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use Sub::Identify qw( sub_name ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use Try::Tiny qw( catch try ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | # Cargo-culted from App::cpm::CLI | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # Adding pass_through so that we don't have to keep up with all possible options | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use Getopt::Long qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | :config | ||||||||||||||||||||||||||||||||||||||||||
| 21 | no_auto_abbrev | ||||||||||||||||||||||||||||||||||||||||||
| 22 | no_ignore_case | ||||||||||||||||||||||||||||||||||||||||||
| 23 | bundling | ||||||||||||||||||||||||||||||||||||||||||
| 24 | pass_through | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=8 SCAR=21.2
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | shift; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | my $local_lib; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | # Don't add this to @INC twice | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | for my $i (@INC) { | |||||||||||||||||||||||||||||||||||||||||
| 35 | 36 | ▶ | next unless ref $i && ref $i eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $i and ref $i eq "CODE"
MC/DC0%0/2
ref $i and ref $i eq "CODE"
ref $i
ref $i eq "CODE"
Truth table33%1/3
A and B
A= ref $iB= ref $i eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | return if sub_name($i) eq '_lazy_worker'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 4 | local @ARGV = @args; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # Stolen from App::cpm::CLI::parse_options() | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # We only need to peek at -L here; everything else (including -g) is | ||||||||||||||||||||||||||||||||||||||||||
| 44 | # forwarded to App::cpm via pass_through. | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | GetOptions( | |||||||||||||||||||||||||||||||||||||||||
| 46 | 'L|local-lib-contained=s' => \$local_lib, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | # Generally assume a global install, which makes the invocation as | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # simple as: | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | # perl -Mlazy foo.pl | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # | ||||||||||||||||||||||||||||||||||||||||||
| 55 | # To install into ./local: | ||||||||||||||||||||||||||||||||||||||||||
| 56 | # perl -Mlazy='-Llocal' | ||||||||||||||||||||||||||||||||||||||||||
| 57 | # | ||||||||||||||||||||||||||||||||||||||||||
| 58 | # To install into ./some-other-dir: | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # perl -Mlazy='-Lsome-other-dir' | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | # Ensure global install by default | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | ▶ | if ( !$local_lib ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 3 | ▶ | print "🌍 global install if required\n" unless $ENV{HARNESS_ACTIVE}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 3 | push @args, ('-g'); | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | print "🔨 Installing into $local_lib if required\n" | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | unless $ENV{HARNESS_ACTIVE}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | require local::lib; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | local::lib->import($local_lib); | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 4 | my $cpm = App::cpm::CLI->new; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | # Push the hook onto @INC and then re-add all of @INC again. This way, if | ||||||||||||||||||||||||||||||||||||||||||
| 76 | # we got to the hook and tried to install, we can re-try @INC to see if the | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # module can now be used. | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 16 | ▶ | my $_lazy = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 16 | shift; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 16 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 16 | state %seen; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 16 | $seen{$name}++; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 16 | ▶ | return if $seen{$name} > 1; # Limit recursion to a single attempt | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 15 | $name =~ s{/}{::}g; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 15 | $name =~ s{\.pm\z}{}; | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | # Silently skip probes we never want to install: autoloader split | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # files, Net::DNS::Resolver's per-OS subclasses, and | ||||||||||||||||||||||||||||||||||||||||||
| 91 | # Encode::ConfigLocal. These fire constantly during normal @INC | ||||||||||||||||||||||||||||||||||||||||||
| 92 | # searching, so warning about them is pure noise. | ||||||||||||||||||||||||||||||||||||||||||
| 93 | return | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 15 | ▶ | if $name =~ qr{\Aauto::.*\.al\z} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$name =~ qr/\Aauto::.*\.al\z/u or $name =~ qr/\ANet::DNS::Resolver::/u or $name eq "Encode::ConfigLocal"
$name =~ qr/\Aauto::.*\.al\z/u or $name =~ qr/\ANet::DNS::Resolver::/u
MC/DC100%3/3
$name =~ qr/\Aauto::.*\.al\z/u or $name =~ qr/\ANet::DNS::Resolver::/u or $name eq "Encode::ConfigLocal"
$name =~ qr/\Aauto::.*\.al\z/u
$name =~ qr/\ANet::DNS::Resolver::/u
$name eq "Encode::ConfigLocal"
Truth table100%4/4
A or B or C
A= $name =~ qr/\Aauto::.*\.al\z/uB= $name =~ qr/\ANet::DNS::Resolver::/uC= $name eq "Encode::ConfigLocal"
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | || $name =~ qr{\ANet::DNS::Resolver::} | ||||||||||||||||||||||||||||||||||||||||||
| 96 | || $name eq 'Encode::ConfigLocal'; | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 3 | warn "lazy: installing $name ...\n"; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 3 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | $cpm->run( 'install', @args, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | warn "Failed to install $name: " . longmess(); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | warn $_; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 4 | subname '_lazy_worker', $_lazy; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 4 | push @INC, $_lazy, @INC; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | # ABSTRACT: Lazily install missing Perl modules | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | __END__ | ||||||||||||||||||||||||||||||||||||||||||