summaryrefslogtreecommitdiffstats
path: root/perl-install/common.pm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>1999-07-29 15:18:54 +0000
committerPascal Rigaux <pixel@mandriva.com>1999-07-29 15:18:54 +0000
commit88a07c82cece62903ae68e1e2c482d810bbf8560 (patch)
tree5eee08b842d20f111fc82bba2e42425e253e8a50 /perl-install/common.pm
parent5dc2835bfbf1f53ad51ba540f4423c22cc94b26c (diff)
downloaddrakx-88a07c82cece62903ae68e1e2c482d810bbf8560.tar
drakx-88a07c82cece62903ae68e1e2c482d810bbf8560.tar.gz
drakx-88a07c82cece62903ae68e1e2c482d810bbf8560.tar.bz2
drakx-88a07c82cece62903ae68e1e2c482d810bbf8560.tar.xz
drakx-88a07c82cece62903ae68e1e2c482d810bbf8560.zip
no_comment
Diffstat (limited to 'perl-install/common.pm')
-rw-r--r--perl-install/common.pm31
1 files changed, 26 insertions, 5 deletions
diff --git a/perl-install/common.pm b/perl-install/common.pm
index ce4d599e9..ec8f92366 100644
--- a/perl-install/common.pm
+++ b/perl-install/common.pm
@@ -6,8 +6,9 @@ use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK $printable_chars $sizeof_int $bitof_int
@ISA = qw(Exporter);
%EXPORT_TAGS = (
- common => [ qw(_ __ min max bool member divide is_empty_array_ref set_new set_add round_up round_down first second top uniq translate untranslate) ],
- file => [ qw(dirname basename all glob_ cat_ chop_ mode) ],
+ common => [ qw(_ __ min max sum bool member divide is_empty_array_ref add2hash set_new set_add round_up round_down first second top uniq translate untranslate) ],
+ functional => [ qw(fold_left) ],
+ file => [ qw(dirname basename touch all glob_ cat_ chop_ mode) ],
system => [ qw(sync makedev unmakedev psizeof strcpy gettimeofday syscall_ crypt_) ],
constant => [ qw($printable_chars $sizeof_int $bitof_int $SECTORSIZE) ],
);
@@ -22,12 +23,14 @@ $SECTORSIZE = 512;
sub _ { my $s = shift @_; sprintf translate($s), @_ }
sub __ { $_[0] }
-sub min { my $min = shift; grep { $_ < $min and $min = $_; } @_; $min }
-sub max { my $max = shift; grep { $_ > $max and $max = $_; } @_; $max }
+sub min { fold_left(sub { $a < $b ? $a : $b }, @_) }
+sub max { fold_left(sub { $a > $b ? $a : $b }, @_) }
+sub sum { fold_left(sub { $a + $b }, @_) }
sub first { $_[0] }
sub second { $_[1] }
sub top { $_[$#_] }
sub uniq { my %l; @l{@_} = (); keys %l }
+sub add2hash { my ($a, $b) = @_; while (my ($k, $v) = each %{$b || {}}) { $a->{$k} ||= $v } }
sub member { my $e = shift; foreach (@_) { $e eq $_ and return 1 } 0 }
sub dirname { @_ == 1 or die "usage: dirname <name>\n"; local $_ = shift; s|[^/]*/*\s*$||; s|(.)/*$|$1|; $_ || '.' }
sub basename { @_ == 1 or die "usage: basename <name>\n"; local $_ = shift; s|/*\s*$||; s|.*/||; $_ }
@@ -50,6 +53,24 @@ sub remove_spaces { local $_ = shift; s/^ +//; s/ +$//; $_ }
sub mode { my @l = stat $_[0] or die "unable to get mode of file $_[0]: $!\n"; $l[2] }
sub psizeof { length pack $_[0] }
+sub touch {
+ my $f = shift;
+ unless (-e $f) {
+ local *F;
+ open F, ">$f";
+ }
+ my $now = time;
+ utime $now, $now, $f;
+}
+
+sub fold_left(&$@) {
+ my $f = shift;
+ local $a = shift;
+ foreach $b (@_) { $a = &$f() }
+ $a
+}
+
+
sub all {
my $d = shift;
@@ -89,7 +110,7 @@ sub unmakedev { $_[0] >> 8, $_[0] & 0xff }
sub translate {
my ($s) = @_;
unless (defined %po::I18N::I18N) {
- if (my ($lang) = ($ENV{LC_ALL} || $ENV{LANGUAGE} || $ENV{LC_MESSAGES} || $ENV{LANG}) =~ /(..)/) {
+ if (my ($lang) = substr($ENV{LC_ALL} || $ENV{LANGUAGE} || $ENV{LC_MESSAGES} || $ENV{LANG} || '', 0, 2)) {
local $SIG{__DIE__} = 'none';
eval { require "po/$lang.pm" };
}