root/lib/Resmon/ExtComm.pm

Revision b3c640775d36906eb2e9f8a2b1cbf1bbb0ba8fd4, 478 bytes (checked in by Theo Schlossnagle <jesus@omniti.com>, 7 years ago)

make this stuff object oriented.. but Resmon::Modules should really by Resmon::Module

git-svn-id: https://labs.omniti.com/resmon/trunk@20 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

  • Property mode set to 100755
Line 
1 package Resmon::ExtComm;
2
3 use strict;
4 require Exporter;
5 use vars qw/@ISA @EXPORT/;
6
7 @ISA = qw/Exporter/;
8 @EXPORT = qw/cache_command/;
9
10 my %commhist;
11 my %commcache;
12
13 sub cache_command($$;$) {
14   my ($command, $expiry, $timeout) = @_;
15   $timeout ||= $expiry;
16
17   my $now = time;
18   if($commhist{$command}>$now) {
19     return $commcache{$command};
20   }
21   # TODO: timeouts
22   $commcache{$command} = `$command`;
23   $commhist{$command} = $now + $expiry;
24   return $commcache{$command};
25 }
26
27 1;
Note: See TracBrowser for help on using the browser.