This commit was manufactured by cvs2svn to create branch 'avendor'.
[monitoring-plugins.git] / Helper.pm
blob198a6480ef98e93e0dc01c558064ad499978801d
1 package Helper;
2 use strict;
4 use Exporter();
5 use vars qw($VERSION @ISA @EXPORT);
6 $VERSION = 0.01;
7 @ISA=qw(Exporter);
8 @EXPORT=qw(&get_option);
10 sub get_option ($$) {
11 my $file = 'Cache';
12 my $response;
13 my $var = shift;
15 require "$file.pm";
16 if(defined($Cache::{$var})){
17 $response=$Cache::{$var};
18 return $$response;
21 my $request = shift;
22 my $filename;
23 my $path;
24 foreach $path (@INC) {
25 $filename="$path/$file.pm";
26 last if (-e $filename);
28 print STDERR "Enter $request\n";
29 $response=<STDIN>;
30 chop($response);
31 open(CACHE,"<$filename") or die "Cannot open cache for reading";
32 undef $/;
33 my $cache = <CACHE>;
34 $/="\n";
35 close CACHE;
36 $cache =~ s/^(\@EXPORT\s*=\s*qw\(\s*[^\)]*)\)\s*;/$1 $var\)\;/msg;
37 $cache =~ s/^1;[\n\s]*\Z/\$$var=\"$response\"\;\n1\;\n/msg;
38 open(CACHE,">$filename") or die "Cannot open cache for writing";
39 print CACHE $cache;
40 close CACHE;
41 return $response;