# Copyright (c) 2000 bivio Software, Inc. All rights reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: TTY.pm,v 2.1 2006/10/16 21:08:04 moeller Exp $ package Bivio::IO::TTY; use strict; $Bivio::IO::TTY::VERSION = sprintf('%d.%02d', q$Revision: 2.1 $ =~ /\d+/g); $_ = $Bivio::IO::TTY::VERSION; =head1 NAME Bivio::IO::TTY - perform actions on a tty =head1 RELEASE SCOPE bOP =head1 SYNOPSIS use Bivio::IO::TTY; =cut use Bivio::UNIVERSAL; @Bivio::IO::TTY::ISA = ('Bivio::UNIVERSAL'); =head1 DESCRIPTION C performs operations on a TTY. =cut #=IMPORTS use Term::ReadKey (); #=VARIABLES =head1 METHODS =cut =for html =head2 static read_password() : string =head2 static read_password(string prompt) : string Reads a password with I from /dev/tty. If it cannot open /dev/tty, returns undef. =cut sub read_password { my($proto, $prompt) = @_; $prompt = 'Enter password: ' unless defined($prompt); return undef unless _open(); print TTY $prompt; Term::ReadKey::ReadMode('noecho', \*TTY); my $password = ; Term::ReadKey::ReadMode(0, \*TTY); print TTY "\n"; close(TTY); chomp($password); return $password; } #=PRIVATE METHODS # _open() : boolean # # Returns true if it can open /dev/tty. # sub _open { return open(TTY, '+