Imported Upstream version 3.3.2
[debian/amanda] / perl / Amanda / Interactivity / tty_email.pm
1 # Copyright (c) 2010-2012 Zmanda, Inc.  All Rights Reserved.
2 #
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License version 2 as published
5 # by the Free Software Foundation.
6 #
7 # This program is distributed in the hope that it will be useful, but
8 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
10 # for more details.
11 #
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 #
16 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
17 # Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
18
19 package Amanda::Interactivity::tty_email;
20
21 use strict;
22 use warnings;
23 use POSIX qw( :errno_h );
24 use vars qw( @ISA );
25 @ISA = qw( Amanda::Interactivity );
26
27 use Amanda::Paths;
28 use Amanda::Util;
29 use Amanda::Debug qw( debug );
30 use Amanda::Changer;
31 use Amanda::MainLoop qw( :GIOCondition );
32 use Amanda::Interactivity::tty;
33 use Amanda::Interactivity::email;
34
35 =head1 NAME
36
37 Amanda::Interactivity::tty_email -- Interactivity class to read user request from /dev/tty
38
39 =head1 SYNOPSIS
40
41 Amanda::Interactivity class combining tty (when it is available) and email (otherwise).
42
43 =cut
44
45 sub new {
46     my $class = shift;
47     my $property = shift;
48
49     my $input;
50
51     my $r = open($input, '>', "/dev/tty");
52     if ($r) {
53         close($input);
54         return Amanda::Interactivity::tty->new($property);
55     } else {
56         return Amanda::Interactivity::email->new($property);
57     }
58 }
59
60 1;