| 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
| |||||||||||
| 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
| |||||||||||
| 36 | |||||||||||
| 37 | 24 | ▶ | makeCpanfile(@ARGV) if $App::findeps::toCpanfile; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | |||||||||||
| 39 | 24 | my @list = scan(@ARGV); | |||||||||
| 40 | |||||||||||
| 41 | 24 | ▶ | die "Ready to run @ARGV\n" unless @list; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 96 | 0 | ▶ | $version = $version ? ", '$version'" : ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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__ | ||||||||||