X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2FUtils.pm;h=b9be1e45a510daaeb0955ddd7ff80a83102816ed;hb=338c4f27d2fd517aa63544459399aef9b28438be;hp=8aabcaabbad59f97e1bd3d6c3ac6aac48eccbe76;hpb=a70e80a6af6e31d56b120348bc8bc23cdd6543f5;p=clearscm.git diff --git a/lib/Utils.pm b/lib/Utils.pm index 8aabcaa..b9be1e4 100644 --- a/lib/Utils.pm +++ b/lib/Utils.pm @@ -79,6 +79,7 @@ our @EXPORT = qw ( PipeOutput PipeOutputArray ReadFile + RequiredFields RedirectOutput StartPipe Stats @@ -341,10 +342,9 @@ Returns: =cut - $prompt ||= 'Password'; - my $password; + my $password = ''; local $| = 1; @@ -365,9 +365,18 @@ Returns: last; } # if - print '*'; + # Handle backspaces + if ($key eq chr(127)) { + unless ($password eq '') { + chop $password; + + print "\b \b"; + } # unless + } else { + print '*'; - $password .= $key; + $password .= $key; + } # if } # while ReadMode 'restore'; # Reset tty mode before exiting. @@ -463,7 +472,7 @@ In a scalar context just the 1 minute load average. # TODO: Make it work on Windows... return if $^O =~ /win/i; - open my $loadAvg, '/proc/loadavg' + open my $loadAvg, '<', '/proc/loadavg' or croak "Unable to open /proc/loadavg\n"; my $load = <$loadAvg>; @@ -971,6 +980,67 @@ Returns: exit 1; } # Usage +sub RequiredFields($$) { + +=pod + +=head2 RequiredFields($total, $log) + +Check if a list of fields are contained in a hash + +Parameters: + +=for html
+ +=over + +=item $fields + +Array reference to a list of field names that are required + +=item $rec + +Hash reference whose key values we are checking + +=back + +=for html+ +Returns: + +=for html
+ +=over + +=item Message + +Returns either an empty string or a string naming the first missing required +field + +=back + +=for html+ +=cut + + my ($fields, $rec) = @_; + + for my $fieldname (@$fields) { + my $found = 0; + + for (keys %$rec) { + if ($fieldname eq $_) { + $found = 1; + last; + } # if + } # for + + return "$fieldname is required" unless $found; + } # for + + return; +} # RequiredFields + END { StopPipe; } # END