script/cpan-outdated

filter: Statementstmt 45.7% 64 / 140 Branchbran 14.5% 9 / 62 Conditioncond 16.6% 4 / 24 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 54.1% 13 / 24 Podpod n/a totaltotal 34.2% 90 / 263 CC 34 SCAR 50.3
CC
34
Cov
34%
main
420.0
get_index
30.0
modules_to_check
20.0
CRAP 153.1
↑ Summary blib/lib/App/cpanoutdated.pm »
1 #!/usr/bin/perl
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use ExtUtils::Installed;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use IO::Zlib;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use CPAN::DistnameInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Module::Metadata;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 our $VERSION = "0.32";
14  
15 2 my $mirror = 'http://www.cpan.org/';
16 2 my $local_lib;
17 2 my $self_contained = 0;
18 2 my $index_file;
19 my $help;
20 2 Getopt::Long::Configure("bundling");
21 Getopt::Long::GetOptions(
22 'h|help' => \$help,
23 'verbose' => \my $verbose,
24 'm|mirror=s' => \$mirror,
25 'index=s' => \$index_file,
26 'p|print-package' => \my $print_package,
27 0 ▶ 'I=s' => sub { die "this option was deprecated" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 'l|local-lib=s' => \$local_lib,
29 'L|local-lib-contained=s' =>
30 0 ▶ sub { $local_lib = $_[1]; $self_contained = 1; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 0 ▶ 'compare-changes' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 0 die "--compare-changes option was deprecated.\n"
33 . "You can use 'cpan-listchanges `cpan-outdated -p`' instead.\n"
34 . "cpanm cpan-listchanges # install from CPAN\n"
35 },
36 2 ▶ 'exclude-core' => \my $exclude_core,
Branch: 1 branch
BranchTrueFalseTotal
&Getopt::Long::GetOptions("h|help", \$help, "verbose", \my $verbose, "m|mirror=s", \$mirror, "index=s", \$index_file, "p|print-package", \my $print_package, "I=s", sub { die "this option was deprecated"; } , "l|local-lib=s", \$local_lib, "L|local-lib-contained=s", sub { $local_lib = $_[1]; $self_contained = 1; } , "compare-changes", sub { die "--compare-changes option was deprecated.\nYou can use 'cpan-listchanges `cpan-outdated -p`' instead.\ncpanm cpan-listchanges # install from CPAN\n"; } , "exclude-core", \my $exclude_core) or ++$help 2 0 2
37 ) or $help++;
38 2 ▶if ($help) {
Branch: 1 branch
BranchTrueFalseTotal
if ($help) 0 2 2
39 0 require Pod::Usage;
40 0 Pod::Usage::pod2usage();
41 }
42  
43 2 $mirror =~ s:/$::;
44 2 my $index_url = "${mirror}/modules/02packages.details.txt.gz";
45 2 $index_url = URI->new($index_url);
46 2 ▶if ($index_url->isa('URI::file')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index_url->isa("URI::file")) 0 2 2
47 0 ▶ die '--index is incompatible with a file:// mirror' if defined $index_file;
Branch: 1 branch
BranchTrueFalseTotal
if defined $index_file 0 0 0
48 0 $index_file = $index_url->file
49 }
50  
51 2 my $core_modules;
52 2 ▶if ($exclude_core) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exclude_core) 0 2 2
53 0 require Module::CoreList;
54 2 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
55 0 $core_modules = $Module::CoreList::version{$]};
56 }
57  
58 2 ▶unless ($ENV{HARNESS_ACTIVE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"HARNESS_ACTIVE"}) 0 2 2
59 0 &main;
60 0 exit;
61 }
62  
63 0 ▶sub modules_to_check {
Subroutine modules_to_check: not called CC=4 SCAR=30.0
64 0 my @inc = @_;
65 0 my @modules =
66 ExtUtils::Installed->new(skip_cwd => 1, inc_override => \@inc)->modules;
67 # As core modules may not have been listed by EUI because they lack
68 # .packlist, we add them from Module::CoreList
69 0 ▶ if (!$exclude_core || ($local_lib && !$self_contained)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $exclude_core or $local_lib and not $self_contained) 0 0 0
Condition0%0/6
not $exclude_core or $local_lib and not $self_contained
l!l&&r!l&&!r
000
$local_lib and not $self_contained
!ll&&!rl&&r
000
MC/DC0%0/3
not $exclude_core or $local_lib and not $self_contained
not $exclude_core $local_lib not $self_contained
Truth table0%0/4
not(A) or B and not(C)
A= not $exclude_coreB= $local_libC= not $self_contained
ABCresult
1XX1
0111
00X0
0100
70 0 require Module::CoreList;
71 # This adds duplicates, but they are removed by the caller
72 0 push @modules, keys %{ $Module::CoreList::version{$]} };
73 }
74 0 (@modules)
75 }
76  
77 0 ▶sub installed_version_for {
Subroutine installed_version_for: not called CC=2 SCAR=17.9
78 0 my($pkg, $inc) = @_;
79  
80 0 ▶ local $SIG{__WARN__} = sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 0 my $meta = Module::Metadata->new_from_module($pkg, inc => $inc);
82 0 ▶ $meta ? $meta->version($pkg) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$meta ? : 0 0 0
83 }
84  
85 0 ▶sub main {
Subroutine main: not called CC=20 SCAR=60.4
86 0 my @inc = make_inc($local_lib, $self_contained);
87  
88 0 ▶ if ( !defined($index_file)
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $index_file && -e $index_file or -z $index_file or not $index_url->isa("URI::file")) 0 0 0
Condition0%0/9
not defined $index_file && -e $index_file or -z $index_file or not $index_url->isa("URI::file")
l!l&&r!l&&!r
000
not defined $index_file && -e $index_file or -z $index_file
l!l&&r!l&&!r
000
defined $index_file && -e $index_file
!ll&&!rl&&r
000
MC/DC0%0/4
not defined $index_file && -e $index_file or -z $index_file or not $index_url->isa("URI::file")
defined $index_file -e $index_file -z $index_file not $index_url->isa("URI::file")
Truth table0%0/5
not(A && B) or C or not(D)
A= defined $index_fileB= -e $index_fileC= -z $index_fileD= not $index_url->isa("URI::file")
ABCDresult
0XXX1
10XX1
111X1
11011
11000
89 || ! -e $index_file || -z $index_file
90 || !$index_url->isa('URI::file')) {
91  
92 0 $index_file = get_index($index_url, $index_file)
93 }
94  
95 0 my %installed = map { $_ => 1 } modules_to_check(@inc);
96  
97 0 ▶ my $fh = zopen($index_file) or die "cannot open $index_file";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = zopen($index_file) or die "cannot open $index_file" 0 0 0
98 # skip header part
99 0 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
100 0 ▶ last if $line eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "\n" 0 0 0
101 }
102 # body part
103 0 my %seen;
104 my %dist_latest_version;
105 0 ▶ LINES: while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
106 0 my ($pkg, $version, $dist) = split /\s+/, $line;
107 0 ▶ next unless $installed{$pkg};
Branch: 1 branch
BranchTrueFalseTotal
unless $installed{$pkg} 0 0 0
108 0 ▶ next if $version eq 'undef';
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "undef" 0 0 0
109  
110 # The note below about the latest version heuristics applies here too
111 0 ▶ next if $seen{$dist};
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$dist} 0 0 0
112  
113 # $Mail::SpamAssassin::Conf::VERSION is 'bogus'
114 # https://rt.cpan.org/Public/Bug/Display.html?id=73465
115 0 ▶ next unless $version =~ /[0-9]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $version =~ /[0-9]/ 0 0 0
116  
117 # if excluding core modules
118 0 ▶ next if $exclude_core && exists $core_modules->{$pkg};
Branch: 1 branch
BranchTrueFalseTotal
if $exclude_core and exists $core_modules->{$pkg} 0 0 0
Condition0%0/3
$exclude_core and exists $core_modules->{$pkg}
!ll&&!rl&&r
000
MC/DC0%0/2
$exclude_core and exists $core_modules->{$pkg}
$exclude_core exists $core_modules->{$pkg}
Truth table0%0/3
A and B
A= $exclude_coreB= exists $core_modules->{$pkg}
ABresult
0X0
100
111
119  
120 0 ▶ next if $dist =~ m{/perl-[0-9._]+\.tar\.(gz|bz2)$};
Branch: 1 branch
BranchTrueFalseTotal
if $dist =~ m[/perl-[0-9._]+\.tar\.(gz|bz2)$] 0 0 0
121  
122 0 ▶ my $inst_version = installed_version_for($pkg, \@inc)
Branch: 1 branch
BranchTrueFalseTotal
my $inst_version = installed_version_for($pkg, \@inc) or next 0 0 0
123 or next;
124  
125 0 ▶ if (compare_version($inst_version, $version)) {
Branch: 1 branch
BranchTrueFalseTotal
if (compare_version($inst_version, $version)) 0 0 0
126 0 $seen{$dist}++;
127 0 ▶ if ($verbose) {
Branch: 2 branches
BranchTrueFalseTotal
if ($verbose) { } 0 0 0
elsif ($print_package) { } 0 0 0
128 0 printf "%-30s %-7s %-7s %s\n", $pkg, $inst_version, $version, $dist;
129 } elsif ($print_package) {
130 0 print "$pkg\n";
131 } else {
132 0 print "$dist\n";
133 }
134 }
135 }
136 }
137  
138  
139 # return true if $inst_version is less than $version
140 7 ▶sub compare_version {
Subroutine compare_version: called CC=5 SCAR=16.2
141 7 my ($inst_version, $version) = @_;
142 7 ▶ return 0 if $inst_version eq $version;
Branch: 1 branch
BranchTrueFalseTotal
if $inst_version eq $version 2 5 7
143  
144 5 ▶ my $inst_version_obj = eval { version->new($inst_version) } || version->new(permissive_filter($inst_version));
Condition66%2/3
eval { do { 'version'->new($inst_version) } } || 'version'->new(permissive_filter($inst_version))
l!l&&r!l&&!r
230
MC/DC0%0/2
eval { do { 'version'->new($inst_version) } } || 'version'->new(permissive_filter($inst_version))
eval { do { 'version'->new($inst_version) } } 'version'->new(permissive_filter($inst_version))
Truth table66%2/3
A || B
A= eval { do { 'version'->new($inst_version) } }B= 'version'->new(permissive_filter($inst_version))
ABresult
1X1
011
000
145 5 ▶ my $version_obj = eval { version->new($version) } || version->new(permissive_filter($version));
Condition66%2/3
eval { do { 'version'->new($version) } } || 'version'->new(permissive_filter($version))
l!l&&r!l&&!r
230
MC/DC0%0/2
eval { do { 'version'->new($version) } } || 'version'->new(permissive_filter($version))
eval { do { 'version'->new($version) } } 'version'->new(permissive_filter($version))
Truth table66%2/3
A || B
A= eval { do { 'version'->new($version) } }B= 'version'->new(permissive_filter($version))
ABresult
1X1
011
000
146  
147 5 ▶ return $inst_version_obj < $version_obj ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$inst_version_obj < $version_obj ? : 3 2 5
148 }
149  
150 # for broken packages.
151 12 ▶sub permissive_filter {
Subroutine permissive_filter: called CC=1 SCAR=0.0
152 12 local $_ = $_[0];
153 12 s/^[Vv](\d)/$1/; # Bioinf V2.0
154 12 s/^(\d+)_(\d+)$/$1.$2/; # VMS-IndexedFile 0_02
155 12 s/-[a-zA-Z]+$//; # Math-Polygon-Tree 0.035-withoutworldwriteables
156 12 s/([a-j])/ord($1)-ord('a')/gie; # DBD-Solid 0.20a
157 12 s/[_h-z-]/./gi; # makepp 1.50.2vs.070506
158 12 s/\.{2,}/./g;
159 12 $_;
160 }
161  
162  
163 # Return the $fname (a generated File::Temp object if not provided)
164 0 ▶sub get_index {
Subroutine get_index: not called CC=5 SCAR=34.0
165 0 my ($url, $fname) = @_;
166 0 require HTTP::Tiny;
167 0 my $ua = HTTP::Tiny->new;
168 0 my $response;
169 0 ▶ if (defined $fname) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fname) { } 0 0 0
170 # If the file is not empty, use it as a local cached copy
171 0 ▶ if (-s $fname) {
Branch: 1 branch
BranchTrueFalseTotal
if (-s $fname) { } 0 0 0
172 0 $response = $ua->mirror($url, $fname);
173 } else {
174 # If the file is empty we do not trust its timestamp
175 # so set a custom If-Modified-Since (Perl 5.0 release)
176 0 $response = $ua->mirror($url, $fname,
177 {
178 headers => {
179 'if-modified-since' => 'Wed, 19 Oct 1994 17:18:57 GMT',
180 },
181 });
182 }
183 } else {
184 0 require File::Temp;
185 0 $fname = File::Temp->new(UNLINK => 1, SUFFIX => '.gz');
186 0 binmode $fname;
187 $response = $ua->request(
188 'GET' => $url,
189 {
190 0 ▶ data_callback => sub { print {$fname} $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
191 }
192 0 );
193 0 close $fname;
194 }
195 0 ▶ if ($response->{status} == 599) {
Branch: 2 branches
BranchTrueFalseTotal
if ($response->{'status'} == 599) { } 0 0 0
elsif (not $response->{'success'}) { } 0 0 0
196 0 die "Cannot get_index $url to $fname: $response->{content}";
197 # 304 = "Not Modified" is still a success since we are mirroring
198 } elsif (! $response->{success}) {
199 0 die "Cannot get_index $url to $fname: $response->{status} $response->{reason}";
200 }
201 #print "$fname $response->{status} $response->{reason}\n";
202 # Return the filename (which might be a File::Temp object)
203 $fname
204 0 }
205  
206 0 ▶sub zopen {
Subroutine zopen: not called CC=1 SCAR=6.9
207 # Explicitely stringify the filename as it may be a File::Temp object
208 0 IO::Zlib->new("$_[0]", "rb");
209 }
210  
211 0 ▶sub make_inc {
Subroutine make_inc: not called CC=3 SCAR=24.8
212 0 my ($base, $self_contained) = @_;
213  
214 0 ▶ if ($base) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base) { } 0 0 0
215 0 require local::lib;
216 0 my @modified_inc = (
217 local::lib->install_base_perl_path($base),
218 local::lib->install_base_arch_path($base),
219 );
220 0 ▶ if ($self_contained) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self_contained) { } 0 0 0
221 0 push @modified_inc, @Config{qw(privlibexp archlibexp)};
222 } else {
223 0 push @modified_inc, @INC;
224 }
225 0 return @modified_inc;
226 } else {
227 0 return @INC;
228 }
229 }
230  
231 __END__
↑ Summary blib/lib/App/cpanoutdated.pm »