-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall_cpan_dependencies.pl
73 lines (61 loc) · 1.81 KB
/
install_cpan_dependencies.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env perl
# This script is intended to install all the cpan module dependendency automatically (windows and Linux).
# If you want to add/delete any new/old modules, add/delete that to '__DATA__' section.
# Run this only once when setting the environment for first time.
# Run this script as administrator/root or with elevated user rights.
use strict;
use warnings;
use CPAN;
sub configure_cpan {
my $c = "CPAN::HandleConfig";
$c->load(doit => 1, autoconfig => 1);
$c->edit(prerequisites_policy => "follow");
$c->edit(build_requires_install_policy => "yes");
$c->commit;
return 1;
}
sub check_pre_req_package {
my $package = shift;
print "\n---> Checking module - $package";
eval { require $package; };
if ($@) {
print "\n---> Error loading module: $@";
}
else {
print "\n---> Package $package is already installed\n";
return 1;
}
my $exit_code;
print "\n---> Installing $package...";
eval { $exit_code = system("cpan $package > cpan_installation.log"); };
if ($@ or $exit_code != 0) {
print
"\n---> [ERROR] CPAN installation for $package failed with an exit code of $exit_code. $@";
print "\n Please try to install $package manually if needed\n";
return 0;
}
else {
print "\n---> CPAN installation for $package is successfull!\n";
return 1;
}
}
sub main {
my $os_name = $^O;
print "\nRunning on operating System : " . $os_name . "\n";
configure_cpan;
while (my $pre_req_packages = <DATA>) {
chomp $pre_req_packages;
next if $pre_req_packages =~ /^\s*$/;
check_pre_req_package($pre_req_packages);
}
return 1;
}
main;
__DATA__
File::Find::Rule
Mojo::UserAgent
Email::Sender
Email::MIME
Log::Log4perl
DateTime
Excel::Writer::XLSX