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