Marc - Sebastian Lucksch > Sofu-0.3 > Data::Sofu::List

Download:
sofu/Sofu-0.3.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.3   Source  

NAME ^

Data::Sofu::List - A Sofu List

DESCRIPTION ^

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

Synopsis ^

        require Data::Sofu::List;
        my $list = Data::Sofu::List->new();
        $list->appendElement(Data::Sofu::Value->new($_)) foreach (0 .. 10);;

SYNTAX ^

This Module is pure OO, exports nothing

METHODS ^

Also look at Data::Sofu::Object for methods, cause List inherits from it

new([DATA]) Creates a new Data::Sofu::List and returns it

DATA has to be an Arrayhref

        $inc = Data::Sofu::List->new(\@INC);

set(DATA)

Sets the contents of this list (replaces the old contents).

DATA has to be an Arrayhref

        $inc->set(\@INC);

asList()

Returns itself, used to make sure this List is really a List (Data::Sofu::Map and Data::Sofu::Value will die if called with this method)

asArray()

Perl only

Returns the list as a perl array.

isList()

Returns 1

object(INDEX)

Return the object at the position INDEX in the List.

Dies if the List is shorter than INDEX.

hasElement(INDEX)

Deprecated!

Returns a true value if the List has an Element with the number INDEX

hasObject(INDEX)

Returns a true value if the List has an Element with the number INDEX

hasValue(INDEX)

Returns 1 if this List has an Element at INDEX and this Element is a Data::Sofu::Value.

        $inc->hasValue(2) === $inc->hasElement(2) and $inc->object(2)->isValue();

Note: Return 0 if the Object is not a Value and under if the Element doesn't exist at all.

hasMap(INDEX)

Returns 1 if this List has an Element at INDEX and this Element is a Data::Sofu::Map.

        $inc->hasMap(2) === $inc->hasElement(2) and $inc->object(2)->isMap();

Note: Return 0 if the Object is not a Map and under if the Element doesn't exist at all.

hasList(INDEX)

Returns 1 if this List has an Element at INDEX and this Element is a Data::Sofu::List.

        $inc->hasMap(2) === $inc->hasElement(2) and $inc->object(2)->isList();

Note: Return 0 if the Object is not a List and under if the Element doesn't exist at all.

list(INDEX)

Returns the Object at the postition "INDEX" as a Data::Sofu::List.

Dies if the Object is not a Data::Sofu::List.

        $inc->list(2) === $inc->object(2)->asList()

map(INDEX)

Returns the Object at the postition "INDEX" as a Data::Sofu::Map.

Dies if the Object is not a Data::Sofu::Map.

        $inc->map(2) === $inc->object(2)->asMap()

value(INDEX)

Returns the Object at the postition "INDEX" as a Data::Sofu::Value.

Dies if the Object is not a Data::Sofu::Value.

        $inc->value(2) === $inc->object(2)->asValue()

setElement(INDEX, VALUE)

Perl only (for now)

Sets the Element at INDEX to VALUE

        $inc->setElement(0,Data::Sofu::Value->new("."));

next()

Iterartes over the List, return the next Element on every call and undef at the end of the List.

When called in void context it just resets the iterator.

splice(OFFSET, LENGTH, REPLACEMENT)

Perl only (for now)

Like Perl splice, replaces LENGTH Elements from OFFSET with REPLACEMENT, returns the replaced Elements.

        my $lib = new Data::Sofu::List();
        $inc->splice(2,0,Data::Sofu::Value->new("."),Data::Sofu::Value->new(".."),Data::Sofu::Value->new("../lib"));
                # Inserts 3 new Elements after the second Element

spliceList(OFFSET, LENGTH, REPLACEMENT)

Perl only (for now)

Like splice, replaces LENGTH Elements from OFFSET with REPLACEMENT, returns the replaced Elements.

REPLACEMENT is another Data::Sofu::List

        my $lib = new Data::Sofu::List(Data::Sofu::Value->new("."),Data::Sofu::Value->new(".."),Data::Sofu::Value->new("../lib"));
        $inc->spliceList(2,0,$lib);
                # Inserts the list $lib after the second Element.

appendElement(ELEMENT)

Appends one (or multiple (Perl only)) ELEMENT to the end of this List.

        $inc->appendElement(Data::Sofu::Value->new("lib/"));

firstElement()

Perl only (for now)

Removes and returns the first Element of this List

lastElement()

Perl only (for now)

Removes and returns the last Element of this List

insertElement(ELEMENT)

Perl only (for now)

Appends one (or multiple (Perl only)) ELEMENT to the front of this List.

        $inc->insertElement(Data::Sofu::Value->new("lib/"));

appendList(LIST)

Perl only (for now)

Appends another LIST to the end of this List.

        my $lib = new Data::Sofu::List(Data::Sofu::Value->new("."),Data::Sofu::Value->new(".."),Data::Sofu::Value->new("../lib"));
        $inc->appendList($lib);

insertList(LIST)

Perl only (for now)

Appends another LIST to the front of this List.

        my $lib = new Data::Sofu::List(Data::Sofu::Value->new("."),Data::Sofu::Value->new(".."),Data::Sofu::Value->new("../lib"));
        $inc->insertList($lib);

elementIndex(VALUE)

Returns the index of the first Element that machtes VALUE

clear(VALUE)

Perl only (for now)

Empties this list

length

Perl only (for now)

Returns the length of this List.

Note: The index of the last element is length-1!

opApply()

Takes a Subroutine and iterates with it over this List. Values can't be modified.

The Subroutine takes one Argument: The Value.

        $inc->opApply(sub {
                print "Element = $_[0]->asValue->toString(),"\n";
        });

Note: The Values are Objects, so they still can be changed, but not replaced.

opApplyDeluxe()

Perl only.

Takes a Subroutine and iterates with it over this List. Values can be modified.

The Subroutine takes one Argument: The Value.

        $inc->opApplyDeluxe(sub {
                $_[0]=Data::Sofu::List(split /\//,$_[0]->asValue()->toString());
        });

Note: Please make sure every replaced Value is a Data::Sofu::Object or inherits from it.

storeComment(TREE,COMMENT)

Stores a comment in the Object if TREE is empty, otherwise it propagades the Comment to all its Elements

Should not be called directly, use importComments() instead.

stringify(LEVEL, TREE)

Returns a string representing this List and all its elements.

Runs string(LEVEL+1,TREE+index) on all its elements.

binarify(TREE,BINARY DRIVER)

Returns the binary version of this List and all its elements using the BINARY DRIVER. Don't call this one, use binaryPack instead.

BUGS ^

Some Methods here are not included in Sofud, but they should be so their name might change (Old ones will be preserved)

SEE ALSO ^

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

syntax highlighting: