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   426 use strict;
  1         2  
  1         34  
4 1     1   5 use warnings;
  1         1  
  1         108  
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.99;
24             bootstrap Sys::MemInfo $VERSION;
25              
26             sub get {
27 4     4 1 1200 my $field = shift;
28 1     1   11 no strict;
  1         1  
  1         46  
29 4         4 return &{$field};
  4         1036  
30             }
31              
32             =head1 NAME
33              
34             Sys::MemInfo - query the total free and used physical memory
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 3.13.0, 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 same terms as Perl itself.
103              
104             =head1 COPYRIGHT
105              
106             Copyright (C) 2005, 2006, 2014, 2016 - Sylvain Cresto
107              
108             =cut
109              
110             1;