Commit | Line | Data |
4536f655 |
1 | # File: Stem/Vars.pm |
2 | |
3 | # This file is part of Stem. |
4 | # Copyright (C) 1999, 2000, 2001 Stem Systems, Inc. |
5 | |
6 | # Stem is free software; you can redistribute it and/or modify |
7 | # it under the terms of the GNU General Public License as published by |
8 | # the Free Software Foundation; either version 2 of the License, or |
9 | # (at your option) any later version. |
10 | |
11 | # Stem is distributed in the hope that it will be useful, |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | # GNU General Public License for more details. |
15 | |
16 | # You should have received a copy of the GNU General Public License |
17 | # along with Stem; if not, write to the Free Software |
18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | |
20 | # For a license to use the Stem under conditions other than those |
21 | # described here, to purchase support for this software, or to purchase a |
22 | # commercial warranty contract, please contact Stem Systems at: |
23 | |
24 | # Stem Systems, Inc. 781-643-7504 |
25 | # 79 Everett St. info@stemsystems.com |
26 | # Arlington, MA 02474 |
27 | # USA |
28 | |
29 | package Stem::Vars ; |
30 | |
31 | use strict ; |
32 | use Stem::Route ; |
33 | use base 'Exporter' ; |
34 | use vars qw( %Env @EXPORT ) ; |
35 | |
36 | @EXPORT = qw( %Env ) ; |
37 | |
38 | |
39 | |
40 | Stem::Route::register_class( __PACKAGE__, 'var', 'env' ) ; |
41 | |
42 | sub new { |
43 | |
44 | my( $class, %env ) = @_ ; |
45 | |
46 | delete $env{ 'reg_name' } ; |
47 | |
48 | @Env{ keys %env } = values %env ; |
49 | |
50 | return ; |
51 | } |
52 | |
53 | sub set_env_cmd { |
54 | |
55 | my( $self, $msg ) = @_ ; |
56 | |
57 | my( $data ) = $msg->data() ; |
58 | |
59 | $data = ${$data} if ref $data ; |
60 | |
61 | if ( my( $key, $val ) = $data =~ /^\s*(\w+)\s*=\s*(.+)$/ ) { |
62 | |
63 | $val =~ s/\s+$// ; |
64 | $Env{ $key } = $val ; |
65 | } |
66 | |
67 | return ; |
68 | } |
69 | |
70 | sub get_env_cmd { |
71 | |
72 | my( $self, $msg ) = @_ ; |
73 | |
74 | my( $data ) = $msg->data() ; |
75 | |
76 | $data = ${$data} if ref $data ; |
77 | |
78 | return $Env{$data} ; |
79 | } |
80 | |
81 | sub status_cmd { |
82 | |
83 | my $text ; |
84 | |
85 | $text = <<TEXT ; |
86 | |
87 | Status of Stem Environment |
88 | |
89 | TEXT |
90 | |
91 | foreach my $key ( sort keys %Env ) { |
92 | |
93 | my $val = $Env{$key} ; |
94 | |
95 | $text .= sprintf( "\t%-24s = '$val'\n", $key ) ; |
96 | } |
97 | |
98 | $text .= "\n\n" ; |
99 | |
100 | return $text ; |
101 | } |
102 | |
103 | 1 ; |