File Coverage

blib/lib/Module/CPANTS/Kwalitee/BrokenInstaller.pm
Criterion Covered Total %
statement 20 49 40.8
branch 3 30 10.0
condition 0 3 0.0
subroutine 8 10 80.0
pod 3 3 100.0
total 34 95 35.7


line stmt bran cond sub pod time code
1             package Module::CPANTS::Kwalitee::BrokenInstaller;
2 7     7   3269 use warnings;
  7         27  
  7         205  
3 7     7   35 use strict;
  7         12  
  7         450  
4 7     7   37 use File::Spec::Functions qw(catfile);
  7         11  
  7         4271  
5              
6             our $VERSION = '1.01';
7             $VERSION =~ s/_//; ## no critic
8              
9 42     42 1 95 sub order { 100 }
10              
11             sub analyse {
12 11     11 1 38 my $class = shift;
13 11         27 my $me = shift;
14 11         207 my $distdir = $me->distdir;
15              
16             # inc/Module/Install.pm file
17 11         109 my $mi = catfile($distdir, 'inc', 'Module', 'Install.pm');
18              
19             # Must be okay if not using Module::Install
20 11 50       301 return if not -f $mi;
21              
22 0 0       0 open my $ih, '<', $mi
23             or die "Could not open file '$mi' for checking the bad_installer metric: $!";
24 0         0 my $buf;
25 0 0       0 read $ih, $buf, 100000 or die $!;
26 0         0 close $ih;
27 0 0       0 if ($buf =~ /VERSION\s*=\s*("|'|)(\d+|\d*\.\d+(?:_\d+)?)\1/m) {
28 0         0 $me->d->{module_install}{version} = my $version = $2;
29 0         0 my $non_devel = $version;
30 0         0 $non_devel =~ s/_\d+$//;
31 0 0 0     0 if ($non_devel < 0.61 or $non_devel == 1.04) {
32 0         0 $me->d->{module_install}{broken} = 1;
33             }
34 0 0       0 if ($non_devel < 0.89) {
35 0         0 my $makefilepl = catfile($distdir, 'Makefile.PL');
36 0 0       0 return if not -f $makefilepl;
37              
38 0 0       0 open my $ih, '<', $makefilepl
39             or die "Could not open file '$makefilepl' for checking the bad_installer metric: $!";
40 0         0 local $/ = undef;
41 0         0 my $mftext = <$ih>;
42 0         0 close $ih;
43              
44 0 0       0 return if not defined $mftext;
45              
46 0 0       0 if ($mftext =~ /auto_install/) {
47 0         0 $me->d->{module_install}{broken_auto_install} = 1;
48             } else {
49 0         0 return;
50             }
51              
52 0 0       0 if ($non_devel < 0.64) {
53 0         0 $me->d->{module_install}{broken} = 1;
54             }
55             }
56             }
57             else {
58             # Unknown version (parsing $VERSION failed)
59 0         0 $me->d->{module_install}{broken} = 1;
60             }
61              
62 0         0 return;
63             }
64              
65             sub kwalitee_indicators {
66             return [
67             {
68             name => 'no_broken_module_install',
69             error => q{This distribution uses an obsolete version of Module::Install. Versions of Module::Install prior to 0.61 might not work on some systems at all. Additionally if your Makefile.PL uses the 'auto_install()' feature, you need at least version 0.64. Also, 1.04 is known to be broken.},
70             remedy => q{Upgrade the bundled version of Module::Install to the most current release. Alternatively, you can switch to another build system / installer that does not suffer from this problem. (ExtUtils::MakeMaker, Module::Build both of which have their own set of problems.)},
71             code => sub {
72 11     11   77 my $d = shift;
73 11 50       42 return 1 unless exists $d->{module_install};
74 0 0       0 $d->{module_install}{broken} ? 0 : 1;
75             },
76             details => sub {
77 0     0   0 q{This distribution uses obsolete Module::Install version }.(shift->{module_install}{version});
78             },
79             },
80             {
81             name => 'no_broken_auto_install',
82             error => q{This distribution uses an old version of Module::Install. Versions of Module::Install prior to 0.89 do not detect correctly that CPAN/CPANPLUS shell is used.},
83             remedy => q{Upgrade the bundled version of Module::Install to at least 0.89, but preferably to the most current release. Alternatively, you can switch to another build system / installer that does not suffer from this problem. (ExtUtils::MakeMaker, Module::Build both of which have their own set of problems.)},
84             code => sub {
85 11     11   66 my $d = shift;
86 11 50       45 return 1 unless exists $d->{module_install};
87 0 0       0 $d->{module_install}{broken_auto_install} ? 0 : 1;
88             },
89             details => sub {
90 0     0   0 q{This distribution uses obsolete Module::Install version }.(shift->{module_install}{version});
91             },
92             },
93 8     8 1 170 ];
94             }
95              
96             1
97              
98             __END__