The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Data::Sofu::Object - Sofud compatibility layer.

DESCRIPTION

Provides a interface similar to the original SofuD (sofu.sf.net)

Synopsis

        require Data::Sofu::Object;
        my $map = Data::Sofu::Object->new({Text=>"Hello World"});
        print ref $map; # Data::Sofu::Map;
        $map->write(\*STDOUT); # Text = "Hello World"
        $map->write("file.sofu"); # Text = "Hello World"
        #You don't need Data::Sofu::Object:
        use Data::Sofu;
        $map = loadSofu("file.sofu");
        $map->write(\*STDOUT);

SYNTAX

This Module is pure OO, exports nothing

METHODS

Data::Sofu::Object is the base class for Map, Value, List, Reference and Undefined.

All Methods in here might be overwritten, but work the same way

new(DATA) Creates a new Data::Sofu::Object and returns it

Converts DATA to appropriate Objects

Note

There is no need to call Data::Sofu::Object without DATA.

indent (LEVEL)

Internal Function to create indentation during write()

LEVEL is the amount of indentation requested

Returns Indentation x LEVEL as a string

setIndent([NewIndent])

Allows different indentations to be used (default is "\t")

Returns the current indentation

clear()

Clears the Buffer of seen Objects only used during the old Data::Sofu::from() and Data::Sofu::toObjects()

asValue()

Returns the Object as a C>Data::Sofu::Value> or throws an error if it can't be converted

asList()

Returns the Object as a Data::Sofu::List or throws an error if it can't be converted

asMap()

Returns the Object as a Data::Sofu::Map or throws an error if it can't be converted

asReference()

Returns the Object as a Data::Sofu::Reference or throws an error if it can't be converted

stringify(LEVEL, TREE)

Returns a string representation of the Object, used during write(), should not be called alone

LEVEL is the current indentation level.

TREE is the current position in the TREE (used for Reference building)

binarify(TREE, BINARY DRIVER)

Returns a binary representation of the Object, used during writeBinary(), should never be called alone.

TREE is the current position in the TREE (used for Reference building)

BINARY DRIVER is a Data::Sofu::Binary instance which is initialized with a Encoding, ByteOrder and Sofumark properties.

storeComment(TREE, COMMENT)

Recursivly stores a comment identified by TREE, is used to store a single comment of the hash returned by Data::Sofu::getSofucomments();

importComments(COMMENTS)

Takes a Hashref (as returned by Data::Sofu::getSofucomments()) and gives every Object its fitting Comment

COMMENTS is a reference to a Hash

Normally Data::Sofu->new->toObjects($data,$comments) should have done this.

isValue()

Return 1 if this Object is a Data::Sofu::Value instance, 0 otherwise.

isList()

Return 1 if this Object is a Data::Sofu::List instance, 0 otherwise.

isMap()

Return 1 if this Object is a Data::Sofu::Map instance, 0 otherwise.

stringComment()

Returns the current Objects comment as a string (inculding the # sign)

getComment()

Returns the current comment as an arrayref (One string for each line)

hasComment()

Returns the amount of comment lines.

setComment(COMMENT)

Sets the comments for this Object.

COMMENT should be a reference to an Array

appendComment(COMMENT)

Appends to the comments for this Object.

COMMENT should be a reference to an Array

isDefined()

Returns 1 if the Object is not an instance of Data::Sofu::Undefined

isReference()

Returns 0 if the Object is not an instance of Data::Sofu::Reference

pack()

Returns a string representation of the current Object and all Objects it might include

binaryPack()

Returns a string of that represents the current Object according the the Binary Sofu specification.

Only works on Data::Sofu::Map's other Objects are getting boxed in a Map

string(LEVEL,TREE)

A helper function to detect multiple references and convert them to Sofu References, calls stringify with its arguments

        $o->string(-1,"") === $o->pack();
        print $map->string(0,"") === $o->write(\*STDOUT);

packComment(BINARY DRIVER)

Returns the Objects Comments packed by a BINARY DRIVER, used by binaryPack() and writeBinary()

Never call this one alone.

binary(TREE, BINARY DRIVER)

A helper function to detect multiple references and convert them to Sofu References, calls stringify with its arguments. Should never be called alone, because the result will miss its header.

write(FILE)

Writes the string representation of this Object to a file

File can be:

A filename,

a filehandle or

a reference to a scalar.

writeBinary (FILE,ENCODING,BYTEORDER,SOFUMARK)

Writes the binary representation of this Object to a file

File can be:

A filename,

a filehandle or

a reference to a scalar.

Note: the filehandle will be set to binmode

Uses Data::Sofu::Binary::Bin0200 as driver.

BUGS

Comment and Binary Modes are not really sofud complient, might change in the future

SEE ALSO

Data::Sofu, Data::Sofu::Binary, Data::Sofu::Map, Data::Sofu::List, Data::Sofu::Value, Data::Sofu::Undefined, http://sofu.sf.net