diff options
| author | fukachan <fukachan> | 2004-07-27 15:47:39 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2004-07-27 15:47:39 +0000 |
| commit | 6e1143ec5cfd9c2d9c4d6bb6f41c3b668ecc0b6c (patch) | |
| tree | b21ec876a49eb7b0844891f3ca22716ffeafdd91 | |
| parent | 01c6e574d8c161e76740e5c9c45412c9aa0deec9 (diff) | |
| download | fml8-6e1143ec5cfd9c2d9c4d6bb6f41c3b668ecc0b6c.tar.gz fml8-6e1143ec5cfd9c2d9c4d6bb6f41c3b668ecc0b6c.tar.bz2 fml8-6e1143ec5cfd9c2d9c4d6bb6f41c3b668ecc0b6c.zip | |
implement message_nl() and modified to use it.
| -rw-r--r-- | fml/lib/FML/Install.pm | 70 |
1 files changed, 66 insertions, 4 deletions
diff --git a/fml/lib/FML/Install.pm b/fml/lib/FML/Install.pm index 82127161..9f3c8227 100644 --- a/fml/lib/FML/Install.pm +++ b/fml/lib/FML/Install.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Install.pm,v 1.14 2004/07/23 04:09:44 fukachan Exp $ +# $FML: Install.pm,v 1.15 2004/07/23 15:59:00 fukachan Exp $ # package FML::Install; @@ -751,9 +751,15 @@ sub is_valid_owner my ($self, $user) = @_; use User::pwent; - my $pw = getpwnam($user) || croak("no such user: $user"); + my $pw = getpwnam($user) || do { + my $r = "no such user: $user"; + my $s = $self->message_nl("installer.no_such_user", $r); + croak($r); + }; if ($pw->uid == 0) { - croak("user should be not ROOT!"); + my $r = "user should be not ROOT!"; + my $s = $self->message_nl("installer.no_root_user", $r); + croak($r); } return 1; @@ -769,7 +775,11 @@ sub is_valid_group my ($self, $group) = @_; use User::grent; - my $gr = getgrnam($group) || croak("no such group: $group"); + my $gr = getgrnam($group) || do { + my $r = "no such group: $group"; + my $s = $self->message_nl("installer.no_such_group", $r); + croak($r); + }; return 1; } @@ -993,6 +1003,58 @@ sub md5 =head1 MESSAGE MANIPULATION +=head2 message_nl($clss, $default_msg) + +return message by natural language. + +=cut + + +# Descriptions: return message by natural language. +# Arguments: OBJ($self) STR($class) STR($default_msg) +# Side Effects: none +# Return Value: STR +sub message_nl +{ + my ($self, $class, $default_msg) = @_; + my $charset ||= 'us-ascii'; + + use File::Spec; + $class =~ s@\.@/@g; # XXX . -> / + + my $msg_dir = File::Spec->catfile("fml", "share", "message"); + my $msg_file = File::Spec->catfile($msg_dir, $charset, $class); + + if (-f $msg_file) { + return $self->_import_message_from_file($msg_file); + } + else { + return $default_msg; + } +} + + +# Descriptions: get message from file. +# Arguments: OBJ($self) STR($file) +# Side Effects: none +# Return Value: STR +sub _import_message_from_file +{ + my ($self, $file) = @_; + my $buf = ''; + + use FileHandle; + my $fh = new FileHandle $file; + if (defined $fh) { + my $xbuf; + while ($xbuf = <$fh>) { $buf .= $xbuf;} + $fh->close(); + } + + return $buf; +} + + =head2 enable_message() enable verbose message output. |
