3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.12 2002/12/22 14:15:02 joko |
7 |
|
# + sub mkObject |
8 |
|
# |
9 |
|
# Revision 1.11 2002/12/19 16:27:17 joko |
10 |
|
# +- renamed 'cmd' to 'run_cmd' |
11 |
|
# |
12 |
|
# Revision 1.10 2002/12/19 01:05:35 joko |
13 |
|
# + sub today |
14 |
|
# |
15 |
|
# Revision 1.9 2002/12/05 13:54:00 joko |
16 |
|
# + fix: let 'deep_copy' print its message out (instead of die) |
17 |
|
# |
18 |
|
# Revision 1.8 2002/12/01 22:11:35 joko |
19 |
|
# + sub cmd |
20 |
|
# + sub run_cmds |
21 |
|
# |
22 |
|
# Revision 1.7 2002/11/29 04:44:53 joko |
23 |
|
# - sub array_getRelations |
24 |
|
# + sub getNewPerlObjectByPkgName |
25 |
|
# |
26 |
|
# Revision 1.6 2002/11/17 07:18:59 joko |
27 |
|
# + sub deep_copy |
28 |
|
# |
29 |
|
# Revision 1.5 2002/10/27 18:34:28 joko |
30 |
|
# + sub now |
31 |
|
# |
32 |
# Revision 1.4 2002/08/16 19:06:39 cvsjoko |
# Revision 1.4 2002/08/16 19:06:39 cvsjoko |
33 |
# + sub getDirList |
# + sub getDirList |
34 |
# |
# |
46 |
|
|
47 |
package libp; |
package libp; |
48 |
|
|
49 |
|
use strict; |
50 |
|
use warnings; |
51 |
|
|
52 |
require Exporter; |
require Exporter; |
53 |
@ISA = qw( Exporter ); |
our @ISA = qw( Exporter ); |
54 |
@EXPORT = qw( |
our @EXPORT_OK = qw( |
55 |
Dumper |
Dumper |
56 |
md5 md5_hex md5_base64 |
md5 md5_hex md5_base64 |
57 |
ParseDate UnixDate |
ParseDate UnixDate |
58 |
strftime |
strftime |
|
stripHtml stripSpaces stripNewLines toReal trim |
|
59 |
croak |
croak |
60 |
|
|
61 |
|
stripHtml stripSpaces stripNewLines toReal trim |
62 |
array_getDifference |
array_getDifference |
63 |
getDirList |
getDirList |
64 |
|
now today |
65 |
|
deep_copy |
66 |
|
getNewPerlObjectByPkgName |
67 |
|
run_cmd run_cmds |
68 |
|
mkObject |
69 |
); |
); |
70 |
|
|
|
use strict; |
|
|
use warnings; |
|
|
|
|
71 |
use Data::Dumper; |
use Data::Dumper; |
72 |
use Digest::MD5 qw(md5 md5_hex md5_base64); |
use Digest::MD5 qw(md5 md5_hex md5_base64); |
73 |
|
|
135 |
return $result; |
return $result; |
136 |
} |
} |
137 |
|
|
|
sub array_getRelations { |
|
|
my $a_ref = shift; |
|
|
my $b_ref = shift; |
|
|
my @a = @{$a_ref}; |
|
|
my @b = @{$b_ref}; |
|
|
|
|
|
my @isect = my @diff = my @union = (); |
|
|
my $e; |
|
|
my %count; |
|
|
|
|
|
foreach $e (@a, @b) { $count{$e}++ } |
|
|
|
|
|
foreach $e (keys %count) { |
|
|
push(@union, $e); |
|
|
push @{ $count{$e} == 2 ? \@isect : \@diff }, $e; |
|
|
} |
|
|
|
|
|
my $result = { |
|
|
union => \@union, |
|
|
isect => \@isect, |
|
|
diff => \@diff, |
|
|
}; |
|
|
|
|
|
} |
|
138 |
|
|
|
sub array_getDifference { |
|
|
my $res = array_getRelations(shift, shift); |
|
|
return $res->{diff}; |
|
|
} |
|
139 |
|
|
140 |
|
|
141 |
# ============================================= |
# ============================================= |
208 |
# ============================================= |
# ============================================= |
209 |
|
|
210 |
|
|
211 |
|
sub now { |
212 |
|
return strftime("%Y-%m-%d %H:%M:%S", localtime); |
213 |
|
} |
214 |
|
|
215 |
|
sub today { |
216 |
|
return strftime("%Y-%m-%d", localtime); |
217 |
|
} |
218 |
|
|
219 |
|
# ACK's go to ... |
220 |
|
sub deep_copy { |
221 |
|
my $this = shift; |
222 |
|
if (not ref $this) { |
223 |
|
$this; |
224 |
|
} elsif (ref $this eq "ARRAY") { |
225 |
|
[map deep_copy($_), @$this]; |
226 |
|
} elsif (ref $this eq "HASH") { |
227 |
|
+{map { $_ => deep_copy($this->{$_}) } keys %$this}; |
228 |
|
} elsif (ref $this eq "CODE") { |
229 |
|
$this; |
230 |
|
#} else { die "deep_copy asks: what type is $this?" } |
231 |
|
} else { print "deep_copy asks: what type is $this?", "\n"; } |
232 |
|
} |
233 |
|
|
234 |
|
sub getNewPerlObjectByPkgName { |
235 |
|
my $pkgname = shift; |
236 |
|
my $args = shift; |
237 |
|
#$logger->debug( __PACKAGE__ . "->getNewPerlObjectByPkgName( pkgname $pkgname args $args )" ); |
238 |
|
my $evstring = "use $pkgname;"; |
239 |
|
eval($evstring); |
240 |
|
#$@ && $logger->error( __PACKAGE__ . ':' . __LINE__ . " Error in eval $evstring: " . $@ ); |
241 |
|
$@ && print( __PACKAGE__ . ':' . __LINE__ . " Error in eval \"$evstring\": " . $@ ); |
242 |
|
return $pkgname->new($args); |
243 |
|
} |
244 |
|
|
245 |
|
sub mkObject { |
246 |
|
my $pkgname = shift; |
247 |
|
#my $args = shift; |
248 |
|
#$logger->debug( __PACKAGE__ . "->getNewPerlObjectByPkgName( pkgname $pkgname args $args )" ); |
249 |
|
my $evstring = "use $pkgname;"; |
250 |
|
eval($evstring); |
251 |
|
#$@ && $logger->error( __PACKAGE__ . ':' . __LINE__ . " Error in eval $evstring: " . $@ ); |
252 |
|
$@ && print( __PACKAGE__ . ':' . __LINE__ . " Error in eval \"$evstring\": " . $@ ); |
253 |
|
return $pkgname->new(@_); |
254 |
|
} |
255 |
|
|
256 |
|
sub run_cmd { |
257 |
|
my $cmd = shift; |
258 |
|
$cmd = 'perl ' . $cmd; |
259 |
|
my $sep = "-" x 90; |
260 |
|
print $sep, "\n"; |
261 |
|
print " ", $cmd, "\n"; |
262 |
|
print $sep, "\n"; |
263 |
|
system($cmd); |
264 |
|
print "\n"; |
265 |
|
} |
266 |
|
|
267 |
|
sub run_cmds { |
268 |
|
foreach (@_) { |
269 |
|
run_cmd($_); |
270 |
|
} |
271 |
|
} |
272 |
|
|
273 |
1; |
1; |