ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/Query.pm
Revision: 1.3
Committed: Fri Dec 17 15:20:43 1999 UTC (25 years, 4 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.2: +9 -0 lines
Log Message:
Added new querycheck method - no functionality yet though

File Contents

# Content
1 #
2 # Query.pm
3 #
4 # Originally Written by Christopher Williams
5 #
6 # Description
7 # -----------
8 # Hold information request data
9 #
10 # Interface
11 # ---------
12 # new() : A new Query object
13 # querylist() : return ordered list of query names
14 # title() : return/set the title text
15 # intro() : return/set the intro text
16 # querytype(name) : return/set the input type of the named query
17 # querymessage(name) : return/set the message text associated with the named
18 # query
19 # queryprompt(name) : return/set the prompt string for the query
20 # queryoptions(name) : return/set the query option list for the named query
21 # querycheck(name) : return/set the query checker object
22 # currentvalue(name) : return the current value of the query list exapnded
23 # in the context of the other query values - affected
24 # by lodgevalue.
25 # getparam(name) : return the absolute value of the param (non expanded) - not
26 # affected by lodgevalue until OK called.
27 # setparam(name,value) : set the value of a given query to list
28 # setifundef(name,value) : set the value of a given query to list
29 # expand(@string) : expand given strings
30 # lodgevalue(name,val) : set a value of a given query variable to the list
31 # current value will be expanded in terms of these
32 # OK() : set all query values to the values of the lodged
33 # variables
34 # cancel() : clear the values of any lodged variables
35 # setparam(name,value) : hard set
36 # params : return list of all parameters
37
38 package ActiveDoc::Query;
39 require 5.004;
40
41 sub new {
42 my $class=shift;
43 $self={};
44 bless $self, $class;
45 return $self;
46 }
47
48 sub title {
49 my $self=shift;
50 @_?$self->{title}=shift
51 :((defined $self->{title})?$self->{title}:"");
52 }
53
54 sub intro {
55 my $self=shift;
56 @_?$self->{intro}=shift
57 :((defined $self->{intro})?$self->{intro}:"");
58 }
59
60 sub querytype {
61 my $self=shift;
62 my $name=shift;
63
64 @_?$self->{querytype}{$name}=shift
65 :$self->{querytype}{$name};
66 }
67
68 sub querycheck {
69 my $self=shift;
70 my $name=shift;
71
72 @_?$self->{querycheck}{$name}=shift
73 :$self->{querycheck}{$name};
74 }
75
76 sub querymessage {
77 my $self=shift;
78 my $name=shift;
79
80 @_?($self->{querymessage}{$name}=shift)
81 :($self->expand($self->{querymessage}{$name}));
82 }
83
84 sub queryprompt {
85 my $self=shift;
86 my $name=shift;
87
88 my $rv=undef;
89 if ( @_ ) {
90 $self->{queryprompt}{$name}=shift;
91 $rv=$self->{queryprompt}{$name};
92 } elsif ( defined $self->{queryprompt}{$name} ) {
93 $rv=$self->expand($self->{queryprompt}{$name});
94 }
95 return $rv;
96 }
97
98 sub queryoptions {
99 my $self=shift;
100 my $name=shift;
101 my @out=();
102
103 if ( @_ ) {
104 push @{$self->{queryoptions}{$name}},@_;
105 }
106 foreach $option ( @{$self->{queryoptions}{$name}} ) {
107 push @out, $self->expand($option);
108 }
109
110 return @out;
111 }
112
113 sub expand {
114 my $self=shift;
115 my $string=shift;
116
117 $string=~s{
118 \$\((\w+)\)
119 }{
120 if (defined $self->{lodgehash}{$1}) {
121 $self->expand($self->{lodgehash}{$1});
122 } else {
123 "\$$1";
124 }
125 }egx;
126 $string=~s{
127 \$(\w+)
128 }{
129 if (defined $self->{lodgehash}{$1}) {
130 $self->expand($self->{lodgehash}{$1});
131 } else {
132 "\$$1";
133 }
134 }egx;
135 return $string;
136 }
137
138 sub currentvalue {
139 my $self=shift;
140 my $name=shift;
141
142 $self->expand(
143 ((defined $self->{lodgehash}{$name})?$self->{lodgehash}{$name}:""));
144 }
145
146 sub getparam {
147 my $self=shift;
148 my $name=shift;
149 return $self->{params}{$name};
150 }
151
152 sub lodgevalue {
153 my $self=shift;
154 my $name=shift;
155
156 $self->{lodgehash}{$name}=shift;
157 }
158
159 sub OK {
160 my $self=shift;
161
162 foreach $name ( $self->querylist() ) {
163 $self->setparam($name, $self->{lodgehash}{$name});
164 }
165 }
166
167 sub querylist {
168 my $self=shift;
169 return ( keys %{$self->{querytype}});
170 }
171
172 sub cancel {
173 my $self=shift;
174
175 foreach $name ( keys %{$self->{lodgehash}} ) {
176 $self->{lodgehash}{$name}=$self->{params}{$name};
177 }
178 }
179
180 sub setifundef {
181 my $self=shift;
182 my $name=shift;
183 my $value=shift;
184
185 if ( ! defined $self->{params}{$name} ) {
186 $self->setparam($name,$value);
187 }
188 }
189
190 sub setparam {
191 my $self=shift;
192 my $name=shift;
193 my $value=shift;
194
195 print "Setting $name = $value\n";
196 $self->{params}{$name}=$value;
197 $self->lodgevalue($name,$value);
198 }
199
200 sub params {
201 my $self=shift;
202
203 return ( keys %{$self->{params}} );
204 }