1 |
################################# |
2 |
# |
3 |
# $Id: libsetup.pm,v 1.2 2002/10/25 11:38:50 joko Exp $ |
4 |
# |
5 |
# $Log: libsetup.pm,v $ |
6 |
# Revision 1.2 2002/10/25 11:38:50 joko |
7 |
# + sub checkCommonDeps |
8 |
# + sub checkDeps_orig |
9 |
# + refactored sub checkDeps |
10 |
# |
11 |
# Revision 1.1 2002/07/27 00:28:36 cvsjoko |
12 |
# + new |
13 |
# |
14 |
# |
15 |
# |
16 |
################################# |
17 |
|
18 |
package libsetup; |
19 |
|
20 |
require Exporter; |
21 |
@ISA = qw( Exporter ); |
22 |
@EXPORT = qw( |
23 |
Dumper |
24 |
md5 md5_hex md5_base64 |
25 |
ParseDate UnixDate |
26 |
strftime |
27 |
stripHtml stripSpaces stripNewLines toReal trim |
28 |
croak |
29 |
array_getDifference |
30 |
); |
31 |
|
32 |
use strict; |
33 |
use warnings; |
34 |
|
35 |
|
36 |
my @modules = qw( |
37 |
Data::Dumper Digest::MD5 POSIX Carp |
38 |
LWP::UserAgent HTML::PullParser |
39 |
Date::Manip |
40 |
DBI DBD::mysql |
41 |
Set::Object Tangram Class::Tangram |
42 |
WDDX |
43 |
); |
44 |
|
45 |
|
46 |
sub setupCpanModule { |
47 |
my $module = shift; |
48 |
use CPAN; |
49 |
print "try to setup module \"$module\"? (remember to be root) (y|n) "; |
50 |
my $result = <STDIN>; |
51 |
print "\n"; |
52 |
chomp($result); |
53 |
if (lc($result) eq 'y') { |
54 |
print "installing \"$module from CPAN\" ..."; |
55 |
if (CPAN::install($module)) { |
56 |
print "ok"; |
57 |
return 1; |
58 |
} else { |
59 |
print "failed"; |
60 |
exit; |
61 |
} |
62 |
print "\n"; |
63 |
|
64 |
#my $obj = CPAN::Shell->expand('Module',$module); |
65 |
#$obj->install; |
66 |
} |
67 |
} |
68 |
|
69 |
|
70 |
sub checkCommonDeps { |
71 |
checkDeps_orig(\@modules); |
72 |
} |
73 |
|
74 |
sub checkDeps_orig { |
75 |
my $modules = shift; |
76 |
my @modules = @{$modules}; |
77 |
map { |
78 |
#print $_, "\n"; |
79 |
print "testing for \"$_\" ..."; |
80 |
my $evalcmd = "use $_;"; |
81 |
eval($evalcmd); |
82 |
if ($@) { |
83 |
print "failed"; print "\n"; |
84 |
#print $@, "\n"; |
85 |
#print "could not load \"$_\", maybe this module is not installed", "\n"; |
86 |
if (!setupCpanModule($_)) { |
87 |
print "setup of \"$_\" failed, exit.", "\n"; |
88 |
exit; |
89 |
} |
90 |
} else { |
91 |
print "ok"; |
92 |
} |
93 |
print "\n"; |
94 |
} @modules; |
95 |
} |
96 |
|
97 |
sub checkDeps { |
98 |
my $modules = shift; |
99 |
my @modules = @{$modules}; |
100 |
my $result; |
101 |
map { |
102 |
my $evalcmd = "use $_;"; |
103 |
eval($evalcmd); |
104 |
if ($@) { |
105 |
$result->{$_} = 'notok'; |
106 |
} else { |
107 |
$result->{$_} = 'ok'; |
108 |
} |
109 |
} @modules; |
110 |
return $result; |
111 |
} |
112 |
|
113 |
1; |