NAME
Data::Sofu - Perl extension for Sofu data
SYNOPSIS
require Data::Sofu;
my $sofu=new Sofu;
%hash=$sofu->read("file.sofu");
$comments=$sofu->comments;
$sofu->write("file.sofu",$hashref);
open FH,">file.sofu";
$sofu->write(\*FH,$hashref,$comments);
close FH;
$texta=$sofu->pack($arrayref);
$texth=$sofu->pack($hashref);
$arrayref=$sofu->unpack($texta);
$arrayhash=$sofu->unpack($texth);
DESCRIPTION
This Module provides the ability to read and write sofu files of the versions 0.1 and 0.2. Visit http://sofu.sf.net for a description about sofu.
It can also read not-so-wellformed sofu files and correct their errors.
Additionally it provides the ability to pack HASHes and ARRAYs to sofu strings and unpack those.
The comments in a sofu file can be preserved if
SYNTAX
This class does not export any functions, so you need to call them using object notation.
FUNCTIONS AND METHODS
new
Creates a new Data::Sofu object.
setIndent(INDENT)
Sets the indent to INDENT. Default indent is "\t".
setWarnings( 1/0 )
Enables/Disables sofu syntax warnings.
comments
Gets/sets the comments of the last file read
write(FILE,DATA,[COMMENTS])
Writes a sofu file with the name FILE. FILE can be: A reference to a filehandle or a filename
An existing file of this name will be overwritten.
DATA can be a scalar, a hashref or an arrayref.
The top element of sofu files must be a hash, so any other datatype is converted to {Value=>DATA}.
@a=(1,2,3);
$sofu->write("Test.sofu",\@a);
%data=$sofu->read("Test.sofu");
@a=@{$data->{Value}}; # (1,2,3)
COMMENTS is s reference to hash with comments like the one retuned by comments()
read(FILE)
Reads the sofu file FILE and returns a hash with the data. FILE can be: A reference to a filehandle or a filename
pack(DATA)
Packs DATA to a sofu string. DATA can be a scalar, a hashref or an arrayref.
unpack(SOFU STRING)
This function unpacks SOFU STRING and returns a scalar, which can be either a string or a reference to a hash or a reference to an array.
BUGS
Hashes with keys other than strings without whitespaces are not supported due to the restrictions of the sofu file format.
Crossreference will trigger a warning.
Comments written after an object will be rewritten at the top of an object:
foo = { # Comment1
Bar = "Baz"
} # Comment2
will get to:
foo = { # Comment1
# Comment 2
Bar = "Baz"
}
SEE ALSO
perl(1),http://sofu.sf.net