Data::Sofu::List - A Sofu List
Provides a interface similar to the original SofuD (sofu.sf.net)
require Data::Sofu::List; my $list = Data::Sofu::List->new(); $list->appendElement(Data::Sofu::Value->new($_)) foreach (0 .. 10);;
This Module is pure OO, exports nothing
Also look at Data::Sofu::Object for methods, cause List inherits from it
Data::Sofu::Object
Data::Sofu::List
DATA has to be an Arrayhref
$inc = Data::Sofu::List->new(\@INC);
Sets the contents of this list (replaces the old contents).
$inc->set(\@INC);
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)
Data::Sofu::Map
Data::Sofu::Value
Perl only
Returns the list as a perl array.
Returns 1
Return the object at the position INDEX in the List.
Dies if the List is shorter than INDEX.
Deprecated!
Returns a true value if the List has an Element with the number 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.
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.
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.
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()
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()
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("."));
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)
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)
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.
Appends one (or multiple (Perl only)) ELEMENT to the end of this List.
$inc->appendElement(Data::Sofu::Value->new("lib/"));
Removes and returns the first Element of this List
Removes and returns the last Element of this List
Appends one (or multiple (Perl only)) ELEMENT to the front of this List.
$inc->insertElement(Data::Sofu::Value->new("lib/"));
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);
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);
Returns the index of the first Element that machtes VALUE
Empties this list
Returns the length of this List.
Note: The index of the last element is length-1!
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.
Perl only.
Takes a Subroutine and iterates with it over this List. Values can be modified.
$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.
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.
Some Methods here are not included in Sofud, but they should be so their name might change (Old ones will be preserved)
Data::Sofu, Data::Sofu::Binary, Data::Sofu::Object, Data::Sofu::Map, Data::Sofu::Value, Data::Sofu::Undefined, http://sofu.sf.net
To install Data::Sofu, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Sofu
CPAN shell
perl -MCPAN -e shell install Data::Sofu
For more information on module installation, please visit the detailed CPAN module installation guide.