lib/inc/Module/Install.pm

filter: Statementstmt 43.2% 32 / 74 Branchbran 16.6% 8 / 48 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 60.0% 6 / 10 Podpod n/a totaltotal 32.3% 46 / 142 CC 22 SCAR 39.4
CC
22
Cov
31%
_require_myconfig_or_config
110.0
_check_update_local
56.0
_home
12.4
CRAP 51.5
« lib/Module/Install/Admin/Manifest.pm ↑ Summary lib/Module/Install/Admin/Bundle.pm »
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
BranchTrueFalseTotal
if (-d './inc') { } 2 49 51
25 2 ▶ my $author = $^O eq 'VMS' ? './inc/_author' : './inc/.author';
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'VMS' ? : 0 2 2
26 5 ▶ if ( -d $author ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $author) 1 1 2
27 5 my $modified_at = (stat($author))[9];
28 5 ▶ if ((time - $modified_at) > 24 * 60 * 60) {
Branch: 1 branch
BranchTrueFalseTotal
if (time - $modified_at > 86400) 0 1 1
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
BranchTrueFalseTotal
unless $INC[0] eq "inc" 6 45 51
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
BranchTrueFalseTotal
$cpan_version = _check_update_local($modified_at) or return 0 0 0
72 }
73  
74 # XXX: should die instead of warn?
75 0 ▶ warn <<"WARN" if $cpan_version > $VERSION;
Branch: 1 branch
BranchTrueFalseTotal
if $cpan_version > $inc::Module::Install::VERSION 0 0 0
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
BranchTrueFalseTotal
unless eval "require Compress::Zlib; 1" 0 0 0
87 0 ▶ _require_myconfig_or_config() or return;
Branch: 1 branch
BranchTrueFalseTotal
_require_myconfig_or_config() or return 0 0 0
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
BranchTrueFalseTotal
unless -f $file 0 0 0
94 # return if (stat($file))[9] < $modified_at;
95  
96 0 ▶ my $gz = Compress::Zlib::gzopen($file, 'r') or return;
Branch: 1 branch
BranchTrueFalseTotal
my $gz = Compress::Zlib::gzopen($file, "r") or return 0 0 0
97 0 my $line;
98 0 ▶ while($gz->gzreadline($line)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gz->gzreadline($line)) 0 0 0
99 0 ▶ my ($cpan_version) = $line =~ /^Module::Install\s+(\S+)/ or next;
Branch: 1 branch
BranchTrueFalseTotal
my($cpan_version) = $line =~ /^Module::Install\s+(\S+)/ or next 0 0 0
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
BranchTrueFalseTotal
if $INC{"CPAN/MyConfig.pm"} 0 0 0
108 0 local @INC = @INC;
109 0 ▶ my $home = _home() or return;
Branch: 1 branch
BranchTrueFalseTotal
my $home = _home() or return 0 0 0
110 0 my $cpan_dir = File::Spec->catdir($home,'.cpan');
111 0 ▶ return unless -d $cpan_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $cpan_dir 0 0 0
112 0 unshift @INC, $cpan_dir;
113 0 eval { require CPAN::MyConfig };
114 0 ▶ if ($@ and $@ !~ m#locate CPAN/MyConfig\.pm#) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ and not $@ =~ m[locate CPAN/MyConfig\.pm]) 0 0 0
Condition0%0/3
$@ and not $@ =~ m[locate CPAN/MyConfig\.pm]
!ll&&!rl&&r
000
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]
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $INC{"CPAN/MyConfig.pm"} 0 0 0
119  
120 0 eval { require CPAN::Config; };
121 0 ▶ if ($@ and $@ !~ m#locate CPAN/Config\.pm#) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ and not $@ =~ m[locate CPAN/Config\.pm]) 0 0 0
Condition0%0/3
$@ and not $@ =~ m[locate CPAN/Config\.pm]
!ll&&!rl&&r
000
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]
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $INC{"CPAN/Config.pm"} 0 0 0
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
BranchTrueFalseTotal
if (eval { do { require File::HomeDir; 1 } }) 0 0 0
133 1 ▶ $home = File::HomeDir->can('my_dot_config')
Branch: 1 branch
BranchTrueFalseTotal
'File::HomeDir'->can('my_dot_config') ? : 0 0 0
134 ? File::HomeDir->my_dot_config
135 : File::HomeDir->my_data;
136 1 ▶ unless (defined $home) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $home) 0 0 0
137 1 $home = File::HomeDir->my_home
138 }
139 }
140 1 ▶ unless (defined $home) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $home) 0 0 0
141 0 $home = $ENV{HOME};
142 }
143 1 $home;
144 }
145  
146 46 1;
147  
148 __END__
« lib/Module/Install/Admin/Manifest.pm ↑ Summary lib/Module/Install/Admin/Bundle.pm »