ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Runtime.pm
(Generate patch)

Comparing COMP/SCRAM/src/Runtime.pm (file contents):
Revision 1.2 by williamc, Mon Aug 28 08:35:12 2000 UTC vs.
Revision 1.3 by williamc, Wed Nov 15 10:35:06 2000 UTC

# Line 13 | Line 13
13   # file(file)    : Specify an environment description file
14   # doc(var)      : Print out any documentation for the runtime env
15   # list()        : return a list of all variables set
16 + # sethash(hashref) : Set the environment in the hash provided
17   # printenv(shell) : output environment to stdout in shell format
18   # getvalue(var) : return a string - modified by type for the var specified
19 + # addvar(name,value[,type]) : add a variable - if necessary specify a type
20 + # unshiftvar(name,value{,type]) : unshift a variable
21  
22   package Runtime;
23   require 5.004;
# Line 36 | Line 39 | sub file {
39          $self->_parsefile($filename);
40   }
41  
42 + sub sethash {
43 +        my $self=shift;
44 +        my $hashref=shift;
45 +
46 +        foreach $var ( @{$self->{'varlist'}} ) {
47 +          $$hashref{$var}=$self->_expandvar($self->getvalue($var));
48 +        }
49 + }
50 +
51   sub printenv {
52          my $self=shift;
53          my $shell=shift;
# Line 65 | Line 77 | sub getvalue {
77          my @vals=@{$self->{vars}{$name}};
78          
79          if ( defined $self->{'vartype'}{$name} ) { #any type proceesing
80 <           $string=&{"_".$self->{'vartype'}{$name}}(@vals);
80 >           $string=&{"_".$self->{'vartype'}{$name}}($self,@vals);
81          }
82          else {
83             $string=$vals[0];
# Line 73 | Line 85 | sub getvalue {
85          return $string;
86   }
87  
88 + sub addvar {
89 +        my $self=shift;
90 +        my $name=shift;
91 +        my $val=shift;
92 +
93 +        push @{$self->{'varlist'}}, $name;
94 +        push @{$self->{'vars'}{$name}}, $val;
95 +        if ( @_ ) {
96 +          $self->{'vartype'}{$name}=shift;;
97 +        }
98 +        else {
99 +          $self->{'vartype'}{$name}=undef;
100 +        }
101 + }
102 +
103 + sub unshiftvar {
104 +        my $self=shift;
105 +        my $name=shift;
106 +        my $val=shift;
107 +
108 +        if ( exists $self->{'vars'}{$name} ) {
109 +          unshift @{$self->{'vars'}{$name}}, $val;
110 +        }
111 +        else {
112 +          $self->addvar($name,$val,@_);
113 +        }
114 + }
115 +
116   # ---- Support Routines
117   sub _expandvar {
118          my $self=shift;
# Line 109 | Line 149 | sub _path {
149          return $string;
150   }
151  
152 + #
153 + # removes doubles and whitespace
154 + #
155 + sub _removedoubles {
156 +        my $self=shift;
157 +        my @red=();
158 +
159 +        foreach $elem ( @_ ) {
160 +          $elem=~s/^\s+//; # chop leading whitespace
161 +          if ( (! grep { $_ eq $elem } @red ) && ( $elem ne "")) {
162 +               push @red,$elem;
163 +          }
164 +        }
165 +        return @red;
166 + }
167 +
168   sub _parsefile {
169          my $self=shift;
170          my $filename=shift;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines