import Devel-Size 0.53 from CPAN
[p5sagit/Devel-Size.git] / Size.pm
1 package Devel::Size;
2
3 use strict;
4 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD %EXPORT_TAGS);
5
6 require Exporter;
7 require DynaLoader;
8
9 @ISA = qw(Exporter DynaLoader);
10
11 # Items to export into callers namespace by default. Note: do not export
12 # names by default without a very good reason. Use EXPORT_OK instead.
13 # Do not simply export all your public functions/methods/constants.
14
15 # This allows declaration       use Devel::Size ':all';
16 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
17 # will save memory.
18 %EXPORT_TAGS = ( 'all' => [ qw(
19         size total_size
20 ) ] );
21
22 @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
23
24 @EXPORT = qw(
25         
26 );
27 $VERSION = '0.53';
28
29 bootstrap Devel::Size $VERSION;
30
31 # Preloaded methods go here.
32
33 1;
34 __END__
35
36 =head1 NAME
37
38 Devel::Size - Perl extension for finding the memory usage of Perl variables
39
40 =head1 SYNOPSIS
41
42   use Devel::Size qw(size total_size);
43
44   my $size = size("A string");
45
46   my @foo = (1, 2, 3, 4, 5);
47   my $other_size = size(\@foo);
48
49   my $foo = {a => [1, 2, 3],
50           b => {a => [1, 3, 4]}
51          };
52   my  $total_size = total_size($foo);
53
54 =head1 DESCRIPTION
55
56 This module figures out the real sizes of Perl variables in bytes.  
57 Call functions with a reference to the variable you want the size
58 of.  If the variable is a plain scalar it returns the size of
59 the scalar.  If the variable is a hash or an array, use a reference
60 when calling.
61
62 =head1 FUNCTIONS
63
64 =head2 size($ref)
65
66 The C<size> function returns the amount of memory the variable
67 returns.  If the variable is a hash or an array, it only reports
68 the amount used by the structure, I<not> the contents.
69
70 =head2 total_size($ref)
71
72 The C<total_size> function will traverse the variable and look
73 at the sizes of contents.  Any references contained in the variable
74 will also be followed, so this function can be used to get the
75 total size of a multidimensional data structure.  At the moment
76 there is no way to get the size of an array or a hash and its
77 elements without using this function.
78
79 =head2 EXPORT
80
81 None but default, but optionally C<size> and C<total_size>.
82
83 =head1 BUGS
84
85 Doesn't currently walk all the bits for code refs, globs, formats, and
86 IO. Those throw a warning, but a minimum size for them is returned.
87
88 =head1 AUTHOR
89
90 Dan Sugalski dan@sidhe.org
91
92 =head1 SEE ALSO
93
94 perl(1).
95
96 =cut