File Coverage

blib/lib/Sys/MemInfo.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 17 17 100.0


line stmt bran cond sub pod time code
1             package Sys::MemInfo;
2              
3 1     1   1026 use strict;
  1         2  
  1         51  
4 1     1   7 use warnings;
  1         1  
  1         180  
5              
6             require Exporter;
7             require DynaLoader;
8              
9             our @ISA = qw(Exporter DynaLoader);
10             # Items to export into callers namespace by default. Note: do not export
11             # names by default without a very good reason. Use EXPORT_OK instead.
12             # Do not simply export all your public functions/methods/constants.
13             our @EXPORT = qw(
14             );
15             our @EXPORT_OK = qw(
16             totalmem
17             freemem
18             totalswap
19             freeswap
20             availkeys
21             get
22             );
23             our $VERSION = 0.91;
24             bootstrap Sys::MemInfo $VERSION;
25              
26             sub get {
27 4     4 1 1065 my $field = shift;
28 1     1   16 no strict;
  1         3  
  1         90  
29 4         5 return &{$field};
  4         1184  
30             }
31              
32             =pod
33              
34             Sys::MemInfo - Memory informations
35              
36             =head1 SYNOPSIS
37              
38             use Sys::MemInfo qw(totalmem freemem totalswap);
39              
40             print "total memory: ".(&totalmem / 1024)."\n";
41             print "free memory: ".(&freemem / 1024)."\n";
42              
43             print "total swap: ".(&totalswap / 1024)."\n";
44             print "free swap: ".(Sys::MemInfo::get("freeswap") / 1024)."\n";
45              
46             =head1 DESCRIPTION
47              
48             Sys::MemInfo return the total amount of free and used physical memory in bytes in totalmem and freemem variables.
49              
50             Total amount of free and user swap memory are alse returned in totalswap and freeswap variables.
51              
52             This module has been tested on Linux 2.6.10, UnixWare 7.1.2, AIX5, OpenBSD 3.8,
53             NetBSD 2.0.2, FreBSD 5.4, HPUX11, Solaris 9, Tru64 5.1, Irix 6.5, Mac OS X 10.2 darwin and Windows XP.
54              
55             It should work on FreeBSD 4 and Windows 9X/ME/NT/200X/Vista.
56              
57             =head1 METHODS
58              
59             =over 4
60              
61             =item availkeys
62              
63             Return list of all accessor keys (freemem, totalmem, etc.) This is useful
64             for dumping out all known information from the object by calling get() on
65             all of the returned keys.
66              
67             =item freemem
68              
69             Returns free physical memory in bytes.
70              
71             =item freeswap
72              
73             Returns free swap space in bytes.
74              
75             =item get
76              
77             Returns the value of the passed key.
78              
79             =item totalmem
80              
81             Returns total physical memory size in bytes.
82              
83             =item totalswap
84              
85             Returns total swap space in bytes.
86              
87             =back
88              
89             =head1 AUTHOR
90              
91             Sylvain Cresto Escresto@gmail.comE
92              
93             Thanks to Laurent Dufour and Wilson Snyder.
94              
95             =head1 BUGS
96              
97             Please send bug-reports to scresto@gmail.com
98              
99             =head1 LICENCE
100              
101             This library is free software; you can redistribute it and/or modify
102             it under the terms of the GNU Lesser General Public License as
103             published by the Free Software Foundation; either version 2.1 of the
104             License, or (at your option) any later version.
105              
106             This library is distributed in the hope that it will be useful, but
107             WITHOUT ANY WARRANTY; without even the implied warranty of
108             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
109             Lesser General Public License for more details.
110              
111             You should have received a copy of the GNU Lesser General Public
112             License along with this library; if not, write to the Free Software
113             Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
114             USA
115              
116             =head1 COPYRIGHT
117              
118             Copyright (C) 2005, 2006 - Sylvain Cresto
119              
120             =cut
121              
122             1;