ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/Query.pm
Revision: 1.2
Committed: Fri Dec 17 08:36:23 1999 UTC (25 years, 4 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.1: +11 -0 lines
Log Message:
*** empty log message ***

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 # currentvalue(name) : return the current value of the query list exapnded
22 # in the context of the other query values - affected
23 # by lodgevalue.
24 # getparam(name) : return the absolute value of the param (non expanded) - not
25 # affected by lodgevalue until OK called.
26 # setparam(name,value) : set the value of a given query to list
27 # setifundef(name,value) : set the value of a given query to list
28 # expand(@string) : expand given strings
29 # lodgevalue(name,val) : set a value of a given query variable to the list
30 # current value will be expanded in terms of these
31 # OK() : set all query values to the values of the lodged
32 # variables
33 # cancel() : clear the values of any lodged variables
34 # setparam(name,value) : hard set
35 # params : return list of all parameters
36
37 package ActiveDoc::Query;
38 require 5.004;
39
40 sub new {
41 my $class=shift;
42 $self={};
43 bless $self, $class;
44 return $self;
45 }
46
47 sub title {
48 my $self=shift;
49 @_?$self->{title}=shift
50 :((defined $self->{title})?$self->{title}:"");
51 }
52
53 sub intro {
54 my $self=shift;
55 @_?$self->{intro}=shift
56 :((defined $self->{intro})?$self->{intro}:"");
57 }
58
59 sub querytype {
60 my $self=shift;
61 my $name=shift;
62
63 @_?$self->{querytype}{$name}=shift
64 :$self->{querytype}{$name};
65 }
66
67 sub querymessage {
68 my $self=shift;
69 my $name=shift;
70
71 @_?($self->{querymessage}{$name}=shift)
72 :($self->expand($self->{querymessage}{$name}));
73 }
74
75 sub queryprompt {
76 my $self=shift;
77 my $name=shift;
78
79 my $rv=undef;
80 if ( @_ ) {
81 $self->{queryprompt}{$name}=shift;
82 $rv=$self->{queryprompt}{$name};
83 } elsif ( defined $self->{queryprompt}{$name} ) {
84 $rv=$self->expand($self->{queryprompt}{$name});
85 }
86 return $rv;
87 }
88
89 sub queryoptions {
90 my $self=shift;
91 my $name=shift;
92 my @out=();
93
94 if ( @_ ) {
95 push @{$self->{queryoptions}{$name}},@_;
96 }
97 foreach $option ( @{$self->{queryoptions}{$name}} ) {
98 push @out, $self->expand($option);
99 }
100
101 return @out;
102 }
103
104 sub expand {
105 my $self=shift;
106 my $string=shift;
107
108 $string=~s{
109 \$\((\w+)\)
110 }{
111 if (defined $self->{lodgehash}{$1}) {
112 $self->expand($self->{lodgehash}{$1});
113 } else {
114 "\$$1";
115 }
116 }egx;
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 return $string;
127 }
128
129 sub currentvalue {
130 my $self=shift;
131 my $name=shift;
132
133 $self->expand(
134 ((defined $self->{lodgehash}{$name})?$self->{lodgehash}{$name}:""));
135 }
136
137 sub getparam {
138 my $self=shift;
139 my $name=shift;
140 return $self->{params}{$name};
141 }
142
143 sub lodgevalue {
144 my $self=shift;
145 my $name=shift;
146
147 $self->{lodgehash}{$name}=shift;
148 }
149
150 sub OK {
151 my $self=shift;
152
153 foreach $name ( $self->querylist() ) {
154 $self->setparam($name, $self->{lodgehash}{$name});
155 }
156 }
157
158 sub querylist {
159 my $self=shift;
160 return ( keys %{$self->{querytype}});
161 }
162
163 sub cancel {
164 my $self=shift;
165
166 foreach $name ( keys %{$self->{lodgehash}} ) {
167 $self->{lodgehash}{$name}=$self->{params}{$name};
168 }
169 }
170
171 sub setifundef {
172 my $self=shift;
173 my $name=shift;
174 my $value=shift;
175
176 if ( ! defined $self->{params}{$name} ) {
177 $self->setparam($name,$value);
178 }
179 }
180
181 sub setparam {
182 my $self=shift;
183 my $name=shift;
184 my $value=shift;
185
186 print "Setting $name = $value\n";
187 $self->{params}{$name}=$value;
188 $self->lodgevalue($name,$value);
189 }
190
191 sub params {
192 my $self=shift;
193
194 return ( keys %{$self->{params}} );
195 }