blib/script/cpandeps-diff

filter: Statementstmt 97.8% 93 / 95 Branchbran 74.0% 37 / 50 Conditioncond 66.6% 8 / 12 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 100% 16 / 16 Podpod n/a totaltotal 86.6% 156 / 180 CC 10 SCAR 8.3
CC
10
Cov
88%
_report
5.0
_add
3.0
_remove
2.0
CRAP 2.3
« blib/lib/CPAN/FindDependencies/MakeMaker.pm ↑ Summary blib/script/cpandeps »
1 #!/usr/local/bin/perl
2  
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 15 ▶use Capture::Tiny qw(capture);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use CPAN::FindDependencies;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use File::Find::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use Text::Diff;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # generate help before chdir()ing. can't assume `perldoc` is in the path. Yuck.
13 15 ▶(my $help, undef) = capture { system(
Subroutine __ANON__: called CC=1 SCAR=0.0
14 15 $Config{perlpath}, qw{-MPod::Perldoc -e Pod::Perldoc->run() -- -T}, $0
15 15 ) };
16  
17 15 my($command, @command_params, %finddeps_args);
18 15 ▶if(@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV) 15 0 15
19 15 ▶ while(my $arg = shift(@ARGV)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $arg = shift @ARGV) 40 14 54
20 40 my $this_command;
21 40 ▶ if($arg eq 'add') {
Branch: 7 branches
BranchTrueFalseTotal
if ($arg eq 'add') { } 5 35 40
elsif ($arg =~ /^(rm|remove|delete)$/) { } 1 34 35
elsif ($arg eq 'report') { } 2 32 34
elsif ($arg =~ /^(--)?mirror$/) { } 12 20 32
elsif ($arg =~ /^(--)?perl$/) { } 15 5 20
elsif ($arg eq 'list') { } 4 1 5
elsif ($arg =~ /^(-h|(--)?help)$/) { } 1 0 1
22 5 ▶ die("You must provide an argument to '$arg'.\n\n"._help())
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 1 4 5
23 unless(@ARGV);
24 4 ($this_command, @command_params) = (\&_add, shift(@ARGV));
25 } elsif($arg =~ /^(rm|remove|delete)$/) {
26 1 ▶ die("You must provide an argument to '$arg'.\n\n"._help())
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 1 1
27 unless(@ARGV);
28 1 ($this_command, @command_params) = (\&_remove, shift(@ARGV));
29 } elsif($arg eq 'report') {
30 2 ▶ die("You must provide an argument to '$arg'.\n\n"._help())
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 2 2
31 unless(@ARGV);
32 2 ($this_command, @command_params) = (\&_report, shift(@ARGV));
33 } elsif($arg =~ /^(--)?mirror$/) {
34 12 ▶ die("You must provide an argument to '$arg'.\n\n"._help())
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 12 12
35 unless(@ARGV);
36 12 ▶ $finddeps_args{mirrors} ||= [];
Condition100%2/2
$finddeps_args{"mirrors"} ||= []
l!l
39
MC/DC100%1/1
$finddeps_args{"mirrors"} ||= []
$finddeps_args{"mirrors"}
Truth table100%2/2
A
A= $finddeps_args{"mirrors"}
Aresult
11
00
37 12 push @{$finddeps_args{mirrors}}, shift(@ARGV);
38 } elsif($arg =~ /^(--)?perl$/) {
39 15 ▶ die("You must provide an argument to '$arg'.\n\n"._help())
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 15 15
40 unless(@ARGV);
41 die("You can't provide two or more versions of perl.\n\n"._help())
42 15 ▶ if(exists($finddeps_args{perl}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $finddeps_args{"perl"} 0 15 15
43 15 $finddeps_args{perl} = shift(@ARGV);
44 } elsif($arg eq 'list') {
45 4 ($this_command, @command_params) = (\&_print_list);
46 } elsif($arg =~ /^(-h|(--)?help)$/) {
47 1 ($this_command, @command_params) = (\&_print_help);
48 } else {
49 0 die("'$arg' isn't a valid argument.\n\n"._help());
50 }
51  
52 39 ▶ if($command && $this_command) {
Branch: 2 branches
BranchTrueFalseTotal
if ($command and $this_command) { } 0 39 39
elsif ($this_command) { } 12 27 39
Condition66%2/3
$command and $this_command
!ll&&!rl&&r
3810
MC/DC0%0/2
$command and $this_command
$command $this_command
Truth table66%2/3
A and B
A= $commandB= $this_command
ABresult
0X0
100
111
53 0 die("You can't provide two or more commands.\n\n"._help());
54 } elsif($this_command) {
55 12 $command = $this_command;
56 }
57 }
58 }
59 14 ▶$finddeps_args{mirrors} ||= ['DEFAULT'];
Condition100%2/2
$finddeps_args{"mirrors"} ||= ["DEFAULT"]
l!l
86
MC/DC100%1/1
$finddeps_args{"mirrors"} ||= ["DEFAULT"]
$finddeps_args{"mirrors"}
Truth table100%2/2
A
A= $finddeps_args{"mirrors"}
Aresult
11
00
60 14 ▶$finddeps_args{perl} ||= '5.005';
Condition50%1/2
$finddeps_args{"perl"} ||= "5.005"
l!l
140
MC/DC0%0/1
$finddeps_args{"perl"} ||= "5.005"
$finddeps_args{"perl"}
Truth table50%1/2
A
A= $finddeps_args{"perl"}
Aresult
11
00
61  
62 # create the cache if needed
63 14 ▶chdir($ENV{CPANDEPS_DIFF_DIR} || $ENV{HOME});
Condition33%1/3
$ENV{'CPANDEPS_DIFF_DIR'} || $ENV{'HOME'}
l!l&&r!l&&!r
1400
MC/DC0%0/2
$ENV{'CPANDEPS_DIFF_DIR'} || $ENV{'HOME'}
$ENV{'CPANDEPS_DIFF_DIR'} $ENV{'HOME'}
Truth table33%1/3
A || B
A= $ENV{'CPANDEPS_DIFF_DIR'}B= $ENV{'HOME'}
ABresult
1X1
011
000
64 14 mkdir('.cpandeps-diff');
65 14 mkdir(".cpandeps-diff/$finddeps_args{perl}");
66 14 mkdir(".cpandeps-diff/$finddeps_args{perl}/cache");
67 # clear out Ye Olde cache files. Max age is 23h so multiple runs within a
68 # day won't hammer servers, but a daily cron job will always be fresh
69 14 unlink(
70 File::Find::Rule->file()->mtime("<=".(time() - 23*60*60))
71 ->in(".cpandeps-diff/$finddeps_args{perl}/cache")
72 );
73  
74 14 ▶($command, @command_params) = (\&_report, _list())
Branch: 1 branch
BranchTrueFalseTotal
unless $command 2 12 14
75 unless($command);
76 14 $command->(@command_params);
77  
78 9 ▶sub _get_deps {
Subroutine _get_deps: called CC=1 SCAR=0.0
79 9 my $module = shift;
80 466 return join("\n", sort { $a cmp $b } map { $_->distribution() } grep { $module ne $_->name() } CPAN::FindDependencies::finddeps(
81 $module,
82 nowarnings => 1,
83 perl => $finddeps_args{perl},
84 cachedir => ".cpandeps-diff/$finddeps_args{perl}/cache",
85 9 map { (mirror => $_) } @{$finddeps_args{mirrors}}
86 ));
87 }
88  
89 11 ▶sub _list {
Subroutine _list: called CC=2 SCAR=7.0
90 11 ▶ opendir(my $dir_fh, ".cpandeps-diff/$finddeps_args{perl}") ||
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dir_fh, qq[.cpandeps-diff/$finddeps_args{"perl"}] or die qq[Couldn't read $ENV{"HOME"}/.cpandeps-diff/$finddeps_args{"perl"}: $!\n] 11 0 11
91 die("Couldn't read $ENV{HOME}/.cpandeps-diff/$finddeps_args{perl}: $!\n");
92 11 my @list = grep { -f ".cpandeps-diff/$finddeps_args{perl}/$_" } readdir($dir_fh);
93 11 closedir($dir_fh);
94 11 return sort { $a cmp $b } @list;
95 }
96  
97 4 ▶sub _report {
Subroutine _report: called CC=5 SCAR=16.2
98 4 foreach my $module (@_) {
99 6 my $current_deps = _get_deps($module);
100 6 my $previous_deps = do {
101 6 ▶ open(my $fh, '<', ".cpandeps-diff/$finddeps_args{perl}/$module") ||
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", qq[.cpandeps-diff/$finddeps_args{"perl"}/$module] or die qq[Couldn't read $ENV{"HOME"}/.cpandeps-diff/$finddeps_args{"perl"}/${module}: $!\n] 6 0 6
102 die("Couldn't read $ENV{HOME}/.cpandeps-diff/$finddeps_args{perl}/$module: $!\n");
103 6 my $prev = join('', <$fh>);
104 6 close($fh);
105 6 $prev;
106 };
107 6 ▶ if($current_deps ne $previous_deps) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_deps ne $previous_deps) 3 3 6
108 3 print "Differences found in dependencies for $module:\n";
109 3 print diff(\$previous_deps, \$current_deps, { STYLE => 'Table' });
110 3 ▶ open(my $fh, '>', ".cpandeps-diff/$finddeps_args{perl}/$module") ||
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", qq[.cpandeps-diff/$finddeps_args{"perl"}/$module] or die qq[Couldn't write $ENV{"HOME"}/.cpandeps-diff/$finddeps_args{"perl"}/${module}: $!\n] 3 0 3
111 die("Couldn't write $ENV{HOME}/.cpandeps-diff/$finddeps_args{perl}/$module: $!\n");
112 3 print $fh $current_deps;
113 3 close($fh);
114 }
115 }
116 }
117  
118 4 ▶sub _add {
Subroutine _add: called CC=3 SCAR=11.0
119 4 my $module = shift;
120 4 ▶ return if(grep { $_ eq $module } _list());
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $module;} _list() 1 3 4
121  
122 3 ▶ open(my $fh, '>', ".cpandeps-diff/$finddeps_args{perl}/$module") ||
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", qq[.cpandeps-diff/$finddeps_args{"perl"}/$module] or die qq[Couldn't write $ENV{"HOME"}/.cpandeps-diff/$finddeps_args{"perl"}/${module}: $!\n] 3 0 3
123 die("Couldn't write $ENV{HOME}/.cpandeps-diff/$finddeps_args{perl}/$module: $!\n");
124 3 print $fh _get_deps($module);
125 3 close($fh);
126 }
127  
128 1 ▶sub _remove {
Subroutine _remove: called CC=2 SCAR=7.0
129 1 my $module = shift;
130 1 ▶ die("'$module' isn't in the database.\n\n"._help()) unless(grep { $_ eq $module } _list());
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $module;} _list() 0 1 1
131  
132 1 unlink(".cpandeps-diff/$finddeps_args{perl}/$module");
133 }
134  
135 4 ▶sub _print_list { print "$_\n" foreach (_list()); }
Subroutine _print_list: called CC=2 SCAR=6.9
136 1 ▶sub _print_help { print _help(); }
Subroutine _print_help: called CC=1 SCAR=0.0
137 2 ▶sub _help { return $help; }
Subroutine _help: called CC=1 SCAR=0.0
138  
139 =head1 NAME
140  
141 cpandeps-diff - generate reports when modules' dependencies get new releases
142  
143 =head1 SYNOPSIS
144  
145 cpandeps-diff add Some::Module --perl 5.30.3 --mirror file:///home/me/cpanmirror
146  
147 cpandeps-diff list
148  
149 cpandeps-diff report Some::Module
150  
151 =head1 COMMANDS
152  
153 cpandeps-diff takes at most one of several different commands, some of which in
154 turn take more arguments:
155  
156 =head2 add $module [@args]
157  
158 Add the named module to the list of modules we care about
159  
160 =head2 remove $module [@args]
161  
162 Stop reporting on this module
163  
164 (aliases: delete; rm)
165  
166 =head2 list
167  
168 Show which modules we're going to report on
169  
170 =head2 report $module [@args]
171  
172 Generate a report for just this one module
173  
174 =head2 [@args]
175  
176 If you don't provide a command then it will generate a report about all known
177 modules.
178  
179 =head2 help
180  
181 Can you guess what this does?
182  
183 =head1 ARGUMENTS
184  
185 =head2 perl $version
186  
187 Use this version of perl for figuring out what's in core. Any dependencies
188 that are in core will not be reported on unless a newer version is required.
189  
190 If not specified it defaults to 5.005.
191  
192 Note that adding, removing and reporting on modules always depends on the
193 version of perl, so as well as being used to figure out what's in core
194 you can also have different lists of modules for different versions of perl.
195  
196 =head2 mirror $mirror
197  
198 Use this CPAN mirror to fetch dependency information from (see
199 L<CPAN::FindDependencies> documentation for details). You may provide this
200 argument as many times as you want.
201  
202 =head1 FILES
203  
204 Data is stored in a directory called .cpandeps-diff, which by default
205 is under your home directory. If you want to put it somewhere else
206 (you probably don't) then set CPANDEPS_DIFF_DIR in your environment. That
207 data includes a cache of data fetched from the CPAN which will be automatically
208 cleared out after 23 hours. This cache helps to generate reports for multiple
209 modules more quickly, and also to prevent you from being rate-limited or
210 even kicked off CPAN mirrors.
211  
212 =head1 WARNINGS, BUGS and FEEDBACK
213  
214 This script has not been thoroughly tested.
215  
216 I welcome feedback about my code, including constructive criticism.
217 Bug reports should be made on Github or by email.
218  
219 =head1 AUTHOR, LICENCE and COPYRIGHT
220  
221 Copyright 2007 - 2026 David Cantrell E<lt>F<david@cantrell.org.uk>E<gt>
222  
223 This software is free-as-in-speech software, and may be used,
224 distributed, and modified under the terms of either the GNU
225 General Public Licence version 2 or the Artistic Licence. It's
226 up to you which one you use. The full text of the licences can
227 be found in the files GPL2.txt and ARTISTIC.txt, respectively.
228  
229 =head1 CONSPIRACY
230  
231 This software is also free-as-in-mason.
232  
233 =cut
« blib/lib/CPAN/FindDependencies/MakeMaker.pm ↑ Summary blib/script/cpandeps »