XAS::Lib::Iterator - A class for the XAS environment
use XAS::Lib::Iterator; my @data = ['test1', 'test2', 'test3', 'test4']; my $iterator = XAS::Lib::Iterator->new(@data); while (my $item = $iterator->next) { printf("item: %s\n", $item); }
This is a general purpose iterator for an array of items. Once the items are composed, you can then transverse over them and return items.
Initialize the object and process the supplied items.
If the item is a blessed object with a as_list() method, then what is returned from that call is used.
If the item is a hash, it will be decomposed into an array of hashes with the fields "key" and "value". Where "key" is the orignal key and "value" is the original value. The items will be sorted by the key.
And lastly, you can use a delimited string. The delimiter can be white space or commas. This will be split into an array of sorted items.
Sorting is done by Perls builtin sort function.
Return the number of items.
Set the index to the first item.
Set the index to the last item.
Return or set the current position of the index.
The optional position within the index. This is ones based.
This method will find an item within the items. It will return the position in the index or -1.
The comparison routine. It is passed an item for comparision. The routine should return the following:
1 if the item is greater then what is wanted.
-1 if the item is lesser then what is wanted.
0 if they match.
Return the next item and increment the index.
Return the previous item and decrements the index.
Return the item at the current index position.
Return a slice of the items from the current index position to the end.
Kevin L. Esteb, <kevin@kesteb.us>
Copyright (c) 2015 Kevin L. Esteb
This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. For details, see the full text of the license at http://www.perlfoundation.org/artistic_license_2_0.
To install XAS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XAS
CPAN shell
perl -MCPAN -e shell install XAS
For more information on module installation, please visit the detailed CPAN module installation guide.