466 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			466 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 | 
						|
<html xmlns="http://www.w3.org/1999/xhtml">
 | 
						|
<head>
 | 
						|
<title>GT::Dumper - Convert Perl data structures into a string.</title>
 | 
						|
<link rev="made" href="mailto:root@penguin.office.gossamer-threads.com" />
 | 
						|
 | 
						|
<style type="text/css">
 | 
						|
/* $MVD$:fontset("Untitled Font Set 1","ARIEL","HELVETICA","HELV","SANSERIF") */
 | 
						|
/* $MVD$:fontset("Arial","Arial") */
 | 
						|
/* $MVD$:fontset("Arial Black","Arial Black") */
 | 
						|
/* $MVD$:fontset("Algerian","Algerian") */
 | 
						|
 | 
						|
 | 
						|
body {
 | 
						|
    background-color: white;
 | 
						|
    font-family: Verdana, Arial, sans-serif;
 | 
						|
    font-size: small;
 | 
						|
    color: black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
p {
 | 
						|
    background-color : white;
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h1 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : medium;
 | 
						|
    background-color : white;
 | 
						|
    color : maroon;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h2 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : medium;
 | 
						|
    font-weight : bold;
 | 
						|
    color : blue;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h3 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : medium;
 | 
						|
    color : black;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h4 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : small;
 | 
						|
    color : maroon;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h5 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : small;
 | 
						|
    color : blue;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h6 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
ul {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
ol {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
dl {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
li {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
th {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
td {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
dl {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
dd {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
dt {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
code {
 | 
						|
    font-family : Courier;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
pre {
 | 
						|
    font-family : Courier;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
.mvd-H1 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : 14.0pt;
 | 
						|
    background-color : transparent;
 | 
						|
    background-image : none;
 | 
						|
    color : maroon;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-H2 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : 12.0pt;
 | 
						|
    color : blue;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
p.indent {
 | 
						|
    font-family : "Verdana, Arial, sans-serif";
 | 
						|
    list-style-type : circle;
 | 
						|
    list-style-position : inside;
 | 
						|
    color : black;
 | 
						|
    margin-left : 16.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-P-indent {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    list-style-type : circle;
 | 
						|
    list-style-position : inside;
 | 
						|
    color : black;
 | 
						|
    margin-left : 16.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
pre.programlisting {
 | 
						|
    font-size : 9.0pt;
 | 
						|
    list-style-type : disc;
 | 
						|
    margin-left : 16.0pt;
 | 
						|
    margin-top : -14.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-PRE-programlisting {
 | 
						|
    font-size : 9.0pt;
 | 
						|
    list-style-type : disc;
 | 
						|
    margin-left : 16.0pt;
 | 
						|
    margin-top : -14.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-PRE {
 | 
						|
    font-size : 9.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
p.note {
 | 
						|
    margin-left : 28.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-P-note {
 | 
						|
    margin-left : 28.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-H4 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : normal;
 | 
						|
    font-size : 9.0pt;
 | 
						|
    color : black;
 | 
						|
    margin-left : 6.0pt;
 | 
						|
    margin-top : -14.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-P {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : 10.0pt;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
.mvd-BODY {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
p.indentnobullet {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    list-style-type : none;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-P-indentnobullet {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    list-style-type : none;
 | 
						|
}
 | 
						|
</style>
 | 
						|
 | 
						|
 | 
						|
</head>
 | 
						|
 | 
						|
<body style="background-color: white">
 | 
						|
 | 
						|
<p><a name="__index__"></a></p>
 | 
						|
<!-- INDEX BEGIN -->
 | 
						|
 | 
						|
<ul>
 | 
						|
 | 
						|
	<li><a href="#name">NAME</a></li>
 | 
						|
	<li><a href="#synopsis">SYNOPSIS</a></li>
 | 
						|
	<li><a href="#description">DESCRIPTION</a></li>
 | 
						|
	<li><a href="#example">EXAMPLE</a></li>
 | 
						|
	<li><a href="#methods_functions">METHODS/FUNCTIONS</a></li>
 | 
						|
	<ul>
 | 
						|
 | 
						|
		<li><a href="#dumper">Dumper</a></li>
 | 
						|
		<li><a href="#dump">dump</a></li>
 | 
						|
		<li><a href="#dump_structure">dump_structure</a></li>
 | 
						|
	</ul>
 | 
						|
 | 
						|
	<li><a href="#see_also">SEE ALSO</a></li>
 | 
						|
	<li><a href="#maintainer">MAINTAINER</a></li>
 | 
						|
	<li><a href="#copyright">COPYRIGHT</a></li>
 | 
						|
	<li><a href="#version">VERSION</a></li>
 | 
						|
</ul>
 | 
						|
<!-- INDEX END -->
 | 
						|
 | 
						|
<hr />
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<h1><a name="name">NAME</a></h1>
 | 
						|
<p>GT::Dumper - Convert Perl data structures into a string.</p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<hr />
 | 
						|
<h1><a name="synopsis">SYNOPSIS</a></h1>
 | 
						|
<pre>
 | 
						|
    use GT::Dumper;
 | 
						|
    print Dumper($complex_var);
 | 
						|
    print GT::Dumper->dump ( var => '$MYVAR', data => $complex_var);</pre>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<hr />
 | 
						|
<h1><a name="description">DESCRIPTION</a></h1>
 | 
						|
<p>GT::Dumper by default exports a method <code>Dumper()</code> which will
 | 
						|
behave similar to Data::Dumper's Dumper(). It differs in that
 | 
						|
it will only take a single argument, and the variable dumped
 | 
						|
will be $VAR instead of $VAR1. Also, to provide easier control
 | 
						|
to change the variable name that gets dumped, you can use:</p>
 | 
						|
<pre>
 | 
						|
    GT::Dumper->dump ( var => string, data => yourdata );</pre>
 | 
						|
<p>and the dump will start with string = instead of $VAR = .</p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<hr />
 | 
						|
<h1><a name="example">EXAMPLE</a></h1>
 | 
						|
<pre>
 | 
						|
    use GT::Dumper;
 | 
						|
    my %foo;
 | 
						|
    my @bar = (1, 2, 3);
 | 
						|
    $foo{alpha} = \@bar;
 | 
						|
    $foo{beta} = 'a string';
 | 
						|
    print Dumper(\%foo);</pre>
 | 
						|
<p>This will print:</p>
 | 
						|
<pre>
 | 
						|
    $VAR = {
 | 
						|
        'beta' => 'a string',
 | 
						|
        'alpha' => [
 | 
						|
            '1',
 | 
						|
            '2',
 | 
						|
            '3',
 | 
						|
        ],
 | 
						|
    };</pre>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<hr />
 | 
						|
<h1><a name="methods_functions">METHODS/FUNCTIONS</a></h1>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<h2><a name="dumper">Dumper</a></h2>
 | 
						|
<p><code>Dumper()</code> is exported by default when using GT::Dumper. It takes a single
 | 
						|
variable and returns a string representation of the variable. The string can
 | 
						|
then be eval()'ed back into the same data structure.</p>
 | 
						|
<p>It takes only one argument - the variable to dump. The return is a string of
 | 
						|
the form:</p>
 | 
						|
<p>$VAR = DATA</p>
 | 
						|
<p>where 'DATA' is the actual data structure of the variable. A more powerful and
 | 
						|
customizable dumping method is the <a href="#dump">dump</a> method.</p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<h2><a name="dump">dump</a></h2>
 | 
						|
<p><code>dump()</code> provides a more customizable method to dumping a data structure. Through
 | 
						|
the various options available, listed below, the output of a data structure
 | 
						|
dump can be formatted in several different ways.</p>
 | 
						|
<p>The options are as follows. Only the <a href="#data">data</a> option is required.</p>
 | 
						|
<ul>
 | 
						|
<li><strong><a name="item_data">data</a></strong><br />
 | 
						|
</li>
 | 
						|
The data option takes a data structure to dump. It is required.
 | 
						|
<p></p>
 | 
						|
<li><strong><a name="item_var">var</a></strong><br />
 | 
						|
</li>
 | 
						|
By default, a dump is output as an assignment to <code>$VAR</code>. For example, dumping
 | 
						|
the string <code>foo</code> would return: <code>$VAR = 'foo'</code>. You can change and even omit
 | 
						|
the assignment using the <a href="#item_var"><code>var</code></a> option. To specify a different variable, you
 | 
						|
simply specify it as the value here. To have 'foo' dump as just <code>'foo'</code>
 | 
						|
instead of <code>$VAR = 'foo'</code>, specify var as an empty string, or undef.
 | 
						|
<p></p>
 | 
						|
<li><strong><a name="item_tab">tab</a></strong><br />
 | 
						|
</li>
 | 
						|
When indenting for complex data structures (array refs, hash refs, etc.) an
 | 
						|
indent is used. By default, the indent is 4 spaces, however you can change this
 | 
						|
by using the <a href="#item_tab"><code>tab</code></a> option.
 | 
						|
<p></p>
 | 
						|
<li><strong><a name="item_sort">sort</a></strong><br />
 | 
						|
</li>
 | 
						|
The <a href="#item_sort"><code>sort</code></a> option enables hash key sorting. It is not on by default - to
 | 
						|
enable, simply specify the sort option with 1 as the value. The default sort
 | 
						|
method is case-sensitive alphabetical. See the <a href="#order">order</a> option for
 | 
						|
specifying your own sort order.
 | 
						|
<p></p>
 | 
						|
<li><strong><a name="item_order">order</a></strong><br />
 | 
						|
</li>
 | 
						|
When sorting, it is sometimes desirable to use a custom sort order rather than
 | 
						|
the default case-sensitive alphabetical sort. The <a href="#item_order"><code>order</code></a> option takes a code
 | 
						|
reference and enables custom sort ordering. The code reference will be passed 4
 | 
						|
variables. The first and second are the two items being compared - $a and $b in
 | 
						|
Perl's sort mechanism. The third and fourth are the values in the hash being
 | 
						|
sorted. The code reference, like a Perl sort routine, should return -1 if $a
 | 
						|
should come before $b, 0 if $a and $b are equivelant in your sort order, and 1
 | 
						|
if $b should come before $a. Because of scoping and package issues in Perl, it
 | 
						|
is not possible to directly use $a and $b.
 | 
						|
<p></p>
 | 
						|
<li><strong><a name="item_compress">compress</a></strong><br />
 | 
						|
</li>
 | 
						|
The default dump method is to use ' => ' between hash key and value, to use
 | 
						|
indenting, and to add a line break after each dumped element. You can turn all
 | 
						|
of these off by using the compress option.
 | 
						|
<p>Compression removes all non-essential characters from the output, thus reducing
 | 
						|
data size, however also generally making the dump very difficult to read. If
 | 
						|
enabled, the dumping behaviour is changed as follows:</p>
 | 
						|
<ul>
 | 
						|
<li><strong><a name="item_assignment">assignment</a></strong><br />
 | 
						|
</li>
 | 
						|
If using a var (ie. <code>$VAR = DATA</code>), the spaces around the = will be stripped.
 | 
						|
The output will look like: <code>$VAR=DATA</code>
 | 
						|
<p></p>
 | 
						|
<li><strong><a name="item_hash_keys">hash keys</a></strong><br />
 | 
						|
</li>
 | 
						|
Instead of placing the 4 characters ' => ' between hash keys and values, a
 | 
						|
single ',' will be used.
 | 
						|
<p></p>
 | 
						|
<li><strong><a name="item_tabs">tabs</a></strong><br />
 | 
						|
</li>
 | 
						|
Tabs will not be used.
 | 
						|
<p></p>
 | 
						|
<li><strong><a name="item_newlines">newlines</a></strong><br />
 | 
						|
</li>
 | 
						|
Normally, a newline character is added after each dumped element. Compress
 | 
						|
turns this off.
 | 
						|
<p></p></ul>
 | 
						|
<li><strong><a name="item_structure">structure</a></strong><br />
 | 
						|
</li>
 | 
						|
The structure option causes the dump to be a valid perl structure rather than a
 | 
						|
valid perl statement. This differs in two ways - for one, the <a href="#item_var"><code>var</code></a> option is
 | 
						|
ignored - it is treated as if a blank <a href="#item_var"><code>var</code></a> was entered, thereby not returning
 | 
						|
an assignment. The other difference is that an an ordinary dump adds a
 | 
						|
semicolon and newline at the end of the dump, but these are not added when the
 | 
						|
structure option is enabled.
 | 
						|
<p></p></ul>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<h2><a name="dump_structure">dump_structure</a></h2>
 | 
						|
<p>This is a quick method to do a structure dump. It takes one argument - the data
 | 
						|
to dump. Calling:
 | 
						|
    $class->dump_structure($DATA);
 | 
						|
is identical to calling:
 | 
						|
    $class->dump(data => $DATA, structure => 1);
 | 
						|
See the <a href="#structure">structure</a> option.</p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<hr />
 | 
						|
<h1><a name="see_also">SEE ALSO</a></h1>
 | 
						|
<p><a href="glist.cgi?do=admin_gtdoc&topic=/Data/Dumper.html">the Data::Dumper manpage</a></p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<hr />
 | 
						|
<h1><a name="maintainer">MAINTAINER</a></h1>
 | 
						|
<p>Jason Rhinelander</p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<hr />
 | 
						|
<h1><a name="copyright">COPYRIGHT</a></h1>
 | 
						|
<p>Copyright (c) 2004 Gossamer Threads Inc.  All Rights Reserved.
 | 
						|
<a href="http://www.gossamer-threads.com/">http://www.gossamer-threads.com/</a></p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<hr />
 | 
						|
<h1><a name="version">VERSION</a></h1>
 | 
						|
<p>Revision: $Id: Dumper.pm,v 1.38 2005/02/18 04:44:33 jagerman Exp $</p>
 | 
						|
 | 
						|
</body>
 | 
						|
 | 
						|
</html>
 |