script/findeps

filter: Statementstmt 67.9% 53 / 78 Branchbran 23.0% 6 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 73.3% 11 / 15 Podpod n/a totaltotal 58.8% 70 / 119 CC 12 SCAR 28.7
CC
12
Cov
57%
makeCpanfile
56.0
make_line
12.0
scan
4.0
CRAP 17.6
« blib/lib/App/findeps.pm ↑ Summary
1 #!/usr/bin/env perl
2 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use feature qw(say);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 24 our $VERSION = "0.13";
7  
8 24 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 24 ▶use Directory::Iterator;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 24 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 24 ▶use Module::CoreList;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 24 ▶use version 0.77;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 24 my $pVer = version->parse($]); # parse version from running environment
15  
16 24 ▶use App::findeps;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 24 ▶use File::Basename qw(basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 24 my $scriptName = basename($0);
20 24 my $usage = <<"EOL";
21 Usage: $scriptName [ -u ] [ -L yourlib ] FILE | cpanm
22 -u | --upgradeAll : flag it if you want to upgrade all your dependencies
23 -L | --myLib [yourLib] : designate directory name of your library.
24 : then it will be excluding from detection.
25 : defaults to 'lib'
26  
27 EOL
28  
29 24 ▶GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("u|upgradeAll", \$App::findeps::Upgrade, "L|myLib=s", \$App::findeps::myLib, "m|makeCpanfile", \$App::findeps::toCpanfile) or die $usage 24 0 24
30 "u|upgradeAll" => \$App::findeps::Upgrade,
31 "L|myLib=s" => \$App::findeps::myLib,
32 "m|makeCpanfile" => \$App::findeps::toCpanfile,
33 ) or die $usage;
34  
35 24 ▶die $usage unless @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 24 24
36  
37 24 ▶makeCpanfile(@ARGV) if $App::findeps::toCpanfile;
Branch: 1 branch
BranchTrueFalseTotal
if $App::findeps::toCpanfile 0 24 24
38  
39 24 my @list = scan(@ARGV);
40  
41 24 ▶die "Ready to run @ARGV\n" unless @list;
Branch: 1 branch
BranchTrueFalseTotal
unless @list 0 24 24
42  
43 24 say $_ for @list;
44  
45 24 exit;
46  
47 24 ▶sub scan {
Subroutine scan: called CC=4 SCAR=13.9
48 24 my @files = @_;
49 24 ▶ @files = map { /::/ ? _getPath($_) : $_ } @files;
Branch: 1 branch
BranchTrueFalseTotal
/::/ ? : 0 24 24
50 24 my $map = App::findeps::scan( files => \@files );
51 24 my @list = ();
52 24 foreach my $key ( sort keys %$map ) {
53 27 my $version = $map->{$key};
54 27 my $name = App::findeps::_name($key);
55 27 my $dist = $name;
56 27 ▶ $dist .= "~$version" if defined $version;
Branch: 1 branch
BranchTrueFalseTotal
if defined $version 0 27 27
57 27 push @list, $dist;
58 }
59 24 return @list;
60 }
61  
62 0 ▶sub makeCpanfile {
Subroutine makeCpanfile: not called CC=7 SCAR=40.3
63 0 ▶ die 'Too many Arguments' if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 0 0
64 0 my $file = shift;
65 0 $App::findeps::Upgrade = 1;
66 0 my $name = App::findeps::_name($file);
67 0 ▶ $file = _getPath($name) if $file =~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /::/ 0 0 0
68 0 my @list = scan($file);
69 0 my ( @require, @test_require );
70 0 push @require, make_line($_) for @list;
71  
72 0 my $list = Directory::Iterator->new('t');
73 0 ▶ while ( $list->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list->next) 0 0 0
74 0 my $test = scan( $list->get );
75 0 ▶ push @test_require, make_line($test) unless first { $test =~ /^$_/ } @list, $name;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless &first(sub { $test =~ /^$_/; } , @list, $name) 0 0 0
76 }
77  
78 0 local $" = "\n";
79 0 print <<"EOL";
80 requires 'perl', '$pVer';
81  
82 @require
83 EOL
84 0 local $" = "\n ";
85 0 ▶ print <<"EOL" if @test_require;
Branch: 1 branch
BranchTrueFalseTotal
if @test_require 0 0 0
86 on 'test' => sub {
87 @test_require
88 };
89 EOL
90 0 exit;
91 }
92  
93 0 ▶sub make_line {
Subroutine make_line: not called CC=3 SCAR=24.8
94 0 my ( $name, $version ) = split '~', shift;
95 0 ▶ return if Module::CoreList->is_core( $name, $version, $pVer );
Branch: 1 branch
BranchTrueFalseTotal
if "Module::CoreList"->is_core($name, $version, $pVer) 0 0 0
96 0 ▶ $version = $version ? ", '$version'" : '';
Branch: 1 branch
BranchTrueFalseTotal
$version ? : 0 0 0
97 0 return "requires '$name'$version;";
98 }
99  
100 0 ▶sub _getPath {
Subroutine _getPath: not called CC=1 SCAR=6.9
101 0 local $_ = shift;
102 0 s!::!/!g;
103 0 "lib/$_.pm";
104 }
105  
106 __END__
« blib/lib/App/findeps.pm ↑ Summary