ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/UserInterface_basic.pm
Revision: 1.1
Committed: Tue Aug 31 15:43:52 1999 UTC (25 years, 8 months ago) by williamc
Content type: text/plain
Branch: MAIN
Log Message:
Tested Version

File Contents

# User Rev Content
1 williamc 1.1 #
2     # User Interface --- very basic command line input interface
3     #
4     # Interface
5     # ---------
6     # new() : a new interface object
7     # runquery(type, parameter,args) : Call the appropriate query handling
8     # routine for the given type
9     # startform() : Indicate a new form to start
10     # endform(parameterstore) : Close a form and transfer parameters
11     # (call setparam() on object)
12     #
13     # ------------------------------------------------------------
14     # ---- required processing routines ---
15     # freechoice( param , commentstring, optionref )
16     # : display and ask user for input
17     # strictchoice( param , commentstring, optionref )
18     # : display and ask user for input
19     # basic(param, commentstring) : Simply user input query
20    
21     package ActiveDoc::UserInterface_basic;
22     require 5.001;
23    
24     sub new {
25     my $class=shift;
26     $self={};
27     bless $self, $class;
28     $self->init(@_); # override if reqd
29     return $self;
30     }
31    
32     sub init {
33     my $self=shift;
34     @{$self->{allowed_commands}}=qw(freechoice basic strictchoice);
35     }
36    
37     sub runquery() {
38     my $self=shift;
39     my $type=shift;
40     my $param=shift;
41     my @args=@_;
42     my $found='false';
43    
44     my $rv;
45    
46     foreach $command ( @{$self->{allowed_commands}} ) {
47     if ( $command=~/^$type/ ) {
48     $rv=$self->$command( $param, @args ); $found='true';
49     last;
50     }
51     }
52     if ( ! ( $found=~/true/ ) ) {
53     # default to basic
54     $rv=$self->basic( $param, @args );
55     }
56     $self->{paramhash}{$param}=$rv;
57     }
58    
59    
60     # --------------- Request Implementations -----------------------------
61     #
62    
63     sub basic {
64     my $self=shift;
65     my $param=shift;
66     my $string=shift;
67     my @args=@_;
68    
69     $self->printout($string);
70     return $self->prompt();
71     }
72    
73     sub freechoice {
74     my $self=shift;
75     my $param=shift;
76     my $string=shift;
77     my $choiceref=shift;
78    
79     my $menuchoice;
80     my $rv;
81    
82     $self->printout($string);
83     my $num=1;
84     foreach $item ( @{$choiceref} ) {
85     $self->printout($num.". ".$item."\n");
86     $num++;
87     }
88     $self->printout($num.". Enter Alternative Value\n");
89     $self->printout("Please Enter a Number from the list above :");
90     # Error check
91     while ( (($menuchoice=$self->prompt()) > $num) || ( $menuchoice < 1) ) {
92     $self->printout("Please Select a number Between 1 and $num :");
93     }
94     # Deal with alternative value
95     if ( $menuchoice == $num ) {
96     $rv=$self->basic($param,"Please enter new value\n");
97     }
98     else {
99     $rv=$$choiceref[$menuchoice-1];
100     $self->printout( $rv." selected\n");
101     }
102     return $rv;
103     }
104    
105     sub strictchoice {
106     my $self=shift;
107     my $param=shift;
108     my $string=shift;
109     my $choiceref=shift;
110    
111     my $menuchoice;
112     my $rv;
113    
114     $self->printout($string);
115     my $num=0;
116     foreach $item ( @{$choiceref} ) {
117     $num++;
118     $self->printout($num.". ".$item."\n");
119     }
120     $self->printout("Please Enter a Number from the list above :");
121     # Error check
122     while ( (($menuchoice=$self->prompt()) > $num) || ( $menuchoice < 1) ) {
123     $self->printout("Please Select a number Between 1 and $num :");
124     }
125     $rv=$$choiceref[$menuchoice-1];
126     $self->printout( $rv." selected\n");
127     return $rv;
128     }
129     # ----------------- Support Routines ----------------------------------
130    
131     sub printout {
132     my $self=shift;
133     my $string=shift;
134    
135     print $string;
136     }
137    
138     sub prompt {
139     my $self=shift;
140    
141     my $input;
142    
143     $input = <STDIN>;
144     chomp $input;
145     return $input;
146     }
147    
148     sub startform {
149     my $self=shift;
150     undef %$self->{paramhash};
151     $self->printout("-----------------------------------------------------".
152     "---------------\n");
153     }
154    
155     sub endform {
156     my $self=shift;
157     my $parameterobject=shift;
158    
159     # copy the parameter hash across
160     foreach $key ( %$paramhash ) {
161     $parameterobject->setparam($key, $$self->{paramhash}{$key});
162     }
163     }