| 1 | package inc::Module::Install; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # This module ONLY loads if the user has manually installed their own | ||||||||||||||||||||||||||||
| 4 | # installation of Module::Install, and are some form of MI author. | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # It runs from the installed location, and is never bundled | ||||||||||||||||||||||||||||
| 7 | # along with the other bundled modules. | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | # So because the version of this differs from the version that will | ||||||||||||||||||||||||||||
| 10 | # be bundled almost every time, it doesn't have it's own version and | ||||||||||||||||||||||||||||
| 11 | # isn't part of the synchronisation-checking. | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 51 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 51 | ▶ | use vars qw{$VERSION}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 51 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | # While this version will be overwritten when Module::Install | ||||||||||||||||||||||||||||
| 17 | # loads, it remains so Module::Install itself can detect which | ||||||||||||||||||||||||||||
| 18 | # version an author currently has installed. | ||||||||||||||||||||||||||||
| 19 | # This allows it to implement any back-compatibility features | ||||||||||||||||||||||||||||
| 20 | # it may want or need to. | ||||||||||||||||||||||||||||
| 21 | 51 | $VERSION = '1.21'; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 47 | ▶ | if ( -d './inc' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | my $author = $^O eq 'VMS' ? './inc/_author' : './inc/.author'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 5 | ▶ | if ( -d $author ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 5 | my $modified_at = (stat($author))[9]; | |||||||||||||||||||||||||||
| 28 | 5 | ▶ | if ((time - $modified_at) > 24 * 60 * 60) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | # inc is a bit stale; there may be a newer Module::Install | ||||||||||||||||||||||||||||
| 30 | 5 | _check_update($modified_at); | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | 5 | $Module::Install::AUTHOR = 1; | |||||||||||||||||||||||||||
| 33 | 0 | require File::Path; | |||||||||||||||||||||||||||
| 34 | 0 | File::Path::rmtree('inc'); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | } else { | ||||||||||||||||||||||||||||
| 37 | 45 | $Module::Install::AUTHOR = 1; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 46 | ▶ | unshift @INC, 'inc' unless $INC[0] eq 'inc'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 46 | local $^W; | |||||||||||||||||||||||||||
| 42 | 46 | require Module::Install; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub _check_update { | ||||||||||||||||||||||||||
|
Subroutine
_check_update: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 45 | 0 | my $modified_at = shift; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # XXX: We have several online services to get update information | ||||||||||||||||||||||||||||
| 48 | # including search.cpan.org. They are more reliable than the | ||||||||||||||||||||||||||||
| 49 | # 02packages.details.txt.gz on the local machine. We might be | ||||||||||||||||||||||||||||
| 50 | # better to depend on those services... but on which? | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | my $cpan_version = 0; | |||||||||||||||||||||||||||
| 53 | 0 | if (0) { # XXX: should be configurable? | |||||||||||||||||||||||||||
| 54 | my $url = "http://search.cpan.org/dist/Module-Install/META.yml"; | ||||||||||||||||||||||||||||
| 55 | eval "require YAML::Tiny; 1" or return; | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | if (eval "require LWP::UserAgent; 1") { | ||||||||||||||||||||||||||||
| 58 | my $ua = LWP::UserAgent->new( | ||||||||||||||||||||||||||||
| 59 | timeout => 10, | ||||||||||||||||||||||||||||
| 60 | env_proxy => 1, | ||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||
| 62 | my $res = $ua->get($url); | ||||||||||||||||||||||||||||
| 63 | return unless $res->is_success; | ||||||||||||||||||||||||||||
| 64 | my $yaml = eval { YAML::Tiny::Load($res->content) } or return; | ||||||||||||||||||||||||||||
| 65 | $cpan_version = $yaml->{version}; | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | else { | ||||||||||||||||||||||||||||
| 69 | # If you don't want to rely on the net... | ||||||||||||||||||||||||||||
| 70 | 0 | require File::Spec; | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | $cpan_version = _check_update_local($modified_at) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # XXX: should die instead of warn? | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | warn <<"WARN" if $cpan_version > $VERSION; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | Newer version of Module::Install is available on CPAN. | ||||||||||||||||||||||||||||
| 77 | CPAN: $cpan_version | ||||||||||||||||||||||||||||
| 78 | LOCAL: $VERSION | ||||||||||||||||||||||||||||
| 79 | Please upgrade. | ||||||||||||||||||||||||||||
| 80 | WARN | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub _check_update_local { | ||||||||||||||||||||||||||
|
Subroutine
_check_update_local: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 84 | 0 | my $modified_at = shift; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | return unless eval "require Compress::Zlib; 1"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | _require_myconfig_or_config() or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | my $file = File::Spec->catfile( | ||||||||||||||||||||||||||||
| 89 | $CPAN::Config->{keep_source_where}, | ||||||||||||||||||||||||||||
| 90 | 0 | 'modules', | |||||||||||||||||||||||||||
| 91 | '02packages.details.txt.gz' | ||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | return unless -f $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | # return if (stat($file))[9] < $modified_at; | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | my $gz = Compress::Zlib::gzopen($file, 'r') or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | my $line; | |||||||||||||||||||||||||||
| 98 | 0 | ▶ | while($gz->gzreadline($line)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my ($cpan_version) = $line =~ /^Module::Install\s+(\S+)/ or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | return $cpan_version; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 0 | return; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # adapted from CPAN::HandleConfig | ||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub _require_myconfig_or_config { | ||||||||||||||||||||||||||
|
Subroutine
_require_myconfig_or_config: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | return 1 if $INC{"CPAN/MyConfig.pm"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | local @INC = @INC; | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | my $home = _home() or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | my $cpan_dir = File::Spec->catdir($home,'.cpan'); | |||||||||||||||||||||||||||
| 111 | 0 | ▶ | return unless -d $cpan_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | unshift @INC, $cpan_dir; | |||||||||||||||||||||||||||
| 113 | 0 | eval { require CPAN::MyConfig }; | |||||||||||||||||||||||||||
| 114 | 0 | ▶ | if ($@ and $@ !~ m#locate CPAN/MyConfig\.pm#) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ and not $@ =~ m[locate CPAN/MyConfig\.pm]
MC/DC0%0/2
$@ and not $@ =~ m[locate CPAN/MyConfig\.pm]
$@
not $@ =~ m[locate CPAN/MyConfig\.pm]
Truth table0%0/3
A and not(B)
A= $@B= not $@ =~ m[locate CPAN/MyConfig\.pm]
| |||||||||||||||||||||||||||||
| 115 | 0 | warn "Error while requiring CPAN::MyConfig:\n$@\n"; | |||||||||||||||||||||||||||
| 116 | 0 | return; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | return 1 if $INC{"CPAN/MyConfig.pm"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | eval { require CPAN::Config; }; | |||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ($@ and $@ !~ m#locate CPAN/Config\.pm#) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ and not $@ =~ m[locate CPAN/Config\.pm]
MC/DC0%0/2
$@ and not $@ =~ m[locate CPAN/Config\.pm]
$@
not $@ =~ m[locate CPAN/Config\.pm]
Truth table0%0/3
A and not(B)
A= $@B= not $@ =~ m[locate CPAN/Config\.pm]
| |||||||||||||||||||||||||||||
| 122 | 0 | warn "Error while requiring CPAN::Config:\n$@\n"; | |||||||||||||||||||||||||||
| 123 | 0 | return; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | 0 | ▶ | return 1 if $INC{"CPAN/Config.pm"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | return; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | # adapted from CPAN::HandleConfig | ||||||||||||||||||||||||||||
| 130 | 0 | ▶ | sub _home { | ||||||||||||||||||||||||||
|
Subroutine
_home: not called CC=5 SCAR=25.2
| |||||||||||||||||||||||||||||
| 131 | 0 | my $home; | |||||||||||||||||||||||||||
| 132 | 0 | ▶ | if (eval {require File::HomeDir; 1}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 1 | ▶ | $home = File::HomeDir->can('my_dot_config') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | ? File::HomeDir->my_dot_config | ||||||||||||||||||||||||||||
| 135 | : File::HomeDir->my_data; | ||||||||||||||||||||||||||||
| 136 | 1 | ▶ | unless (defined $home) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 1 | $home = File::HomeDir->my_home | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | 1 | ▶ | unless (defined $home) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | $home = $ENV{HOME}; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | 1 | $home; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 46 | 1; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | __END__ | ||||||||||||||||||||||||||||