File: Helper.pm

package info (click to toggle)
nagios-plugins 1.4-6sarge2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,892 kB
  • ctags: 3,369
  • sloc: ansic: 29,379; perl: 12,117; sh: 5,836; makefile: 540; python: 444; yacc: 316; awk: 46; sed: 16
file content (44 lines) | stat: -rw-r--r-- 944 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package Helper;
use strict;

use Exporter();
use vars qw($VERSION @ISA @EXPORT);
$VERSION = 0.01;
@ISA=qw(Exporter);
@EXPORT=qw(&get_option);

sub get_option ($$) {
    my $file = 'Cache';
    my $response;
    my $var = shift;

    require "$file.pm";
    if(defined($Cache::{$var})){
			$response=$Cache::{$var};
			return $$response;
		}

		my $request = shift;
		my $filename;
		my $path;
		foreach $path (@INC) {
			$filename="$path/$file.pm";
			last if (-e $filename);
		}
		print STDERR "Enter $request\n";
		$response=<STDIN>;
		chop($response);
		open(CACHE,"<$filename") or die "Cannot open cache for reading";
		undef $/;
		my $cache = <CACHE>;
		$/="\n";
		close CACHE;
		$cache =~ s/^(\@EXPORT\s*=\s*qw\(\s*[^\)]*)\)\s*;/$1 $var\)\;/msg;
		$cache =~ s/^1;[\n\s]*\Z/\$$var=\"$response\"\;\n1\;\n/msg;
		open(CACHE,">$filename") or die "Cannot open cache for writing";
		print CACHE $cache;
		close CACHE;
		return $response;
}

1;