Array-Iterator-0.12/0000755000175000017500000000000013126720761011742 5ustar u1u1Array-Iterator-0.12/README0000644000175000017500000002425513126720761012632 0ustar u1u1SYNOPSIS use Array::Iterator; # create an iterator with an array my $i = Array::Iterator->new(1 .. 100); # create an iterator with an array reference my $i = Array::Iterator->new(\@array); # create an iterator with a hash reference my $i = Array::Iterator->new({ __array__ => \@array }); # a base iterator example while ($i->has_next()) { if ($i->peek() < 50) { # ... do something because # the next element is over 50 } my $current = $i->next(); # ... do something with current } # shortcut style my @accumulation; push @accumulation => { item => $iterator->next() } while $iterator->has_next(); # C++ ish style iterator for (my $i = Array::Iterator->new(@array); $i->has_next(); $i->next()) { my $current = $i->current(); # .. do something with current } # common perl iterator idiom my $current; while ($current = $i->get_next()) { # ... do something with $current } DESCRIPTION This class provides a very simple iterator interface. It is is uni-directional and can only be used once. It provides no means of reverseing or reseting the iterator. It is not recommended to alter the array during iteration, however no attempt is made to enforce this (although I will if I can find an efficient means of doing so). This class only intends to provide a clear and simple means of generic iteration, nothing more (yet). METHODS Public Methods new (@array | $array_ref | $hash_ref) The constructor can be passed either a plain perl array, an array reference, or a hash reference (with the array specified as a single key off the hash, __array__). Single element arrays are not supported by either of the first two calling conventions, since it is not possible to distinguish between an array of a single element which happens to be an array reference, and an array reference of a single element, thus previous versions of the constructor would raise an exception. If you expect to pass arrays to the constructor which may have only a single element, then the array can be passed as the element of a HASH reference, with the key, __array__: my $i = Array::Iterator->new({ __array__ => \@array }); has_next([$n]) This methods returns a boolean. True (1) if there are still more elements in the iterator, false (0) if there are not. Takes an optional positive integer (> 0) that specifies the position you want to check. This allows you to check if there an element at arbitrary position. Think of it as an ordinal number you want to check: $i->has_next(2); # 2nd next element $i->has_next(10); # 10th next element Note that has_next(1) is the same as has_next(). Throws an exception if $n <= 0. next This method returns the next item in the iterator, be sure to only call this once per iteration as it will advance the index pointer to the next item. If this method is called after all elements have been exhausted, an exception will be thrown. get_next This method returns the next item in the iterator, be sure to only call this once per iteration as it will advance the index pointer to the next item. If this method is called after all elements have been exhausted, it will return undef. This method was added to allow for a faily common perl iterator idiom of: my $current; while ($current = $i->get_next()) { ... } In this the loop terminates once $current is assigned to a false value. The only problem with this idiom for me is that it does not allow for undefined or false values in the iterator. Of course, if this fits your data, then there is no problem. Otherwise I would recommend the has_next/next idiom instead. peek([$n]) This method can be used to peek ahead at the next item in the iterator. It is non-destructuve, meaning it does not advance the internal pointer. If this method is called and attempts to reach beyond the bounds of the iterator, it will return undef. Takes an optional positive integer (> 0) that specifies how far ahead you want to peek: $i->peek(2); # gives you 2nd next element $i->peek(10); # gives you 10th next element Note that peek(1) is the same as peek(). Throws an exception if $n <= 0. NOTE: Prior to version 0.03 this method would throw an exception if called out of bounds. I decided this was not a good practice, as it made it difficult to be able to peek ahead effectively. This not the case when calling with an argument that is <= 0 though, as it's clearly a sign of incorrect usage. current This method can be used to get the current item in the iterator. It is non-destructive, meaning that it does not advance the internal pointer. This value will match the last value dispensed by next or get_next. current_index This method can be used to get the current index in the iterator. It is non-destructive, meaning that it does not advance the internal pointer. This value will match the index of the last value dispensed by next or get_next. get_length This is a basic accessor for getting the length of the array being iterated over. Protected Methods These methods are protected, in the Java/C++ sense of the word. They can only be called internally by subclasses of Array::Iterator, an exception is thrown if that condition is violated. They are documented here only for people interested in subclassing Array::Iterator. _current_index An lvalue-ed subroutine which allows access to the iterator's internal pointer. _iteratee This returns the item being iteratated over, in our case an array. _get_item ($iteratee, $index) This method is used by all other routines to access items with. Given the iteratee and an index, it will return the item being stored in the $iteratee at the index of $index. TO DO Improve BiDirectional Test suite I want to test the back and forth a little more, make sure they work well with one another. Other Iterators Array::Iterator::BiDirectional::Circular, Array::Iterator::Skipable and Array::Iterator::BiDirectional::Skipable are just a few ideas I have had. I am going to hold off for now until I am sure they are actually useful. SEE ALSO This module now includes several subclasses of Array::Iterator which add certain behaviors to Array::Iterator, they are: Array::Iterator::BiDirectional Adds the ability to move backwards and forwards through the array. Array::Iterator::Circular When this iterator reaches the end of its list, it will loop back to the start again. Array::Iterator::Reusable This iterator can be reset to its beginning and used again. The Design Patterns book by the Gang of Four, specifically the Iterator pattern. Some of the interface for this class is based upon the Java Iterator interface. OTHER ITERATOR MODULES There are a number of modules on CPAN with the word Iterator in them. Most of them are actually iterators included inside other modules, and only really useful within that parent modules context. There are however some other modules out there that are just for pure iteration. I have provided a list below of the ones I have found, if perhaps you don't happen to like the way I do it. Tie::Array::Iterable This module ties the array, something we do not do. But it also makes an attempt to account for, and allow the array to be changed during iteration. It accomplishes this control because the underlying array is tied. As we all know, tie-ing things can be a performance issue, but if you need what this module provides, then it will likely be an acceptable compromise. Array::Iterator makes no attempt to deal with this mid-iteration manipulation problem. In fact it is recommened to not alter your array with Array::Iterator, and if possible we will enforce this in later versions. Data::Iter This module allows for simple iteratation over both hashes and arrays. It does it by importing several functions which can be used to loop over either type (hash or array) in the same way. It is an interesting module, it differs from Array::Iterator in paradigm (Array::Iterator is more OO) as well as in intent. Class::Iterator This is essentially a wrapper around a closure based iterator. This method can be very flexible, but at times is difficult to manage due to the inherent complextity of using closures. I actually was a closure-as-iterator fan for a while, but eventually moved away from it in favor of the more plain vanilla means of iteration, like that found Array::Iterator. Class::Iter This is part of the Class::Visitor module, and is a Visitor and Iterator extensions to Class::Template. Array::Iterator is a standalone module not associated with others. Data::Iterator::EasyObj Data::Iterator::EasyObj makes your array of arrays into iterator objects. It also has the ability to further nest additional data structures including Data::Iterator::EasyObj objects. Array::Iterator is one dimensional only, and does not attempt to do many of the more advanced features of this module. ACKNOWLEDGEMENTS Thanks to Hugo Cornelis for pointing out a bug in peek() Thanks to Phillip Moore for providing the patch to allow single element iteration through the hash-ref constructor parameter. ORIGINAL AUTHOR stevan little, ORIGINAL COPYRIGHT AND LICENSE Copyright 2004, 2005 by Infinity Interactive, Inc. http://www.iinteractive.com This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Array-Iterator-0.12/dist.ini0000644000175000017500000000025013126720761013403 0ustar u1u1version = 0.12 name = Array-Iterator [@Author::PERLANCAR] :version=0.55 [Prereqs / TestRequires] Test::Exception=0 Test::More=0.98 [Prereqs] strict=0 warnings=0 Array-Iterator-0.12/Makefile.PL0000644000175000017500000000232113126720761013712 0ustar u1u1# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.008. use strict; use warnings; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "A simple class for iterating over Perl arrays", "AUTHOR" => "perlancar ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Array-Iterator", "LICENSE" => "perl", "NAME" => "Array::Iterator", "PREREQ_PM" => { "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "Test::Exception" => 0, "Test::More" => "0.98" }, "VERSION" => "0.12", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "Test::Exception" => 0, "Test::More" => "0.98", "strict" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Array-Iterator-0.12/META.yml0000644000175000017500000003063613126720761013223 0ustar u1u1--- abstract: 'A simple class for iterating over Perl arrays' author: - 'perlancar ' build_requires: File::Spec: '0' IO::Handle: '0' IPC::Open3: '0' Test::Exception: '0' Test::More: '0.98' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.008, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Array-Iterator requires: strict: '0' warnings: '0' resources: bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=Array-Iterator homepage: https://metacpan.org/release/Array-Iterator repository: git://github.com/sharyanto/perl-Array-Iterator.git version: '0.12' x_Dist_Zilla: perl: version: '5.024000' plugins: - class: Dist::Zilla::Plugin::GatherDir config: Dist::Zilla::Plugin::GatherDir: exclude_filename: [] exclude_match: [] follow_symlinks: 0 include_dotfiles: 0 prefix: '' prune_directory: [] root: . name: '@Author::PERLANCAR/@Filter/GatherDir' version: '6.008' - class: Dist::Zilla::Plugin::PruneCruft name: '@Author::PERLANCAR/@Filter/PruneCruft' version: '6.008' - class: Dist::Zilla::Plugin::ManifestSkip name: '@Author::PERLANCAR/@Filter/ManifestSkip' version: '6.008' - class: Dist::Zilla::Plugin::MetaYAML name: '@Author::PERLANCAR/@Filter/MetaYAML' version: '6.008' - class: Dist::Zilla::Plugin::License name: '@Author::PERLANCAR/@Filter/License' version: '6.008' - class: Dist::Zilla::Plugin::PodCoverageTests name: '@Author::PERLANCAR/@Filter/PodCoverageTests' version: '6.008' - class: Dist::Zilla::Plugin::PodSyntaxTests name: '@Author::PERLANCAR/@Filter/PodSyntaxTests' version: '6.008' - class: Dist::Zilla::Plugin::ExtraTests name: '@Author::PERLANCAR/@Filter/ExtraTests' version: '6.008' - class: Dist::Zilla::Plugin::ExecDir name: '@Author::PERLANCAR/@Filter/ExecDir' version: '6.008' - class: Dist::Zilla::Plugin::ShareDir name: '@Author::PERLANCAR/@Filter/ShareDir' version: '6.008' - class: Dist::Zilla::Plugin::MakeMaker config: Dist::Zilla::Role::TestRunner: default_jobs: 1 name: '@Author::PERLANCAR/@Filter/MakeMaker' version: '6.008' - class: Dist::Zilla::Plugin::Manifest name: '@Author::PERLANCAR/@Filter/Manifest' version: '6.008' - class: Dist::Zilla::Plugin::ConfirmRelease name: '@Author::PERLANCAR/@Filter/ConfirmRelease' version: '6.008' - class: Dist::Zilla::Plugin::PERLANCAR::BeforeBuild name: '@Author::PERLANCAR/PERLANCAR::BeforeBuild' version: '0.55' - class: Dist::Zilla::Plugin::Rinci::AbstractFromMeta name: '@Author::PERLANCAR/Rinci::AbstractFromMeta' version: '0.09' - class: Dist::Zilla::Plugin::PodnameFromFilename name: '@Author::PERLANCAR/PodnameFromFilename' version: '0.02' - class: Dist::Zilla::Plugin::PERLANCAR::EnsurePrereqToSpec name: '@Author::PERLANCAR/PERLANCAR::EnsurePrereqToSpec' version: '0.04' - class: Dist::Zilla::Plugin::PERLANCAR::MetaResources name: '@Author::PERLANCAR/PERLANCAR::MetaResources' version: '0.03' - class: Dist::Zilla::Plugin::CheckChangeLog name: '@Author::PERLANCAR/CheckChangeLog' version: '0.02' - class: Dist::Zilla::Plugin::CheckMetaResources name: '@Author::PERLANCAR/CheckMetaResources' version: '0.001' - class: Dist::Zilla::Plugin::CopyrightYearFromGit name: '@Author::PERLANCAR/CopyrightYearFromGit' version: '0.003' - class: Dist::Zilla::Plugin::IfBuilt name: '@Author::PERLANCAR/IfBuilt' version: '0.03' - class: Dist::Zilla::Plugin::MetaJSON name: '@Author::PERLANCAR/MetaJSON' version: '6.008' - class: Dist::Zilla::Plugin::MetaConfig name: '@Author::PERLANCAR/MetaConfig' version: '6.008' - class: Dist::Zilla::Plugin::GenShellCompletion name: '@Author::PERLANCAR/GenShellCompletion' version: '0.11' - class: Dist::Zilla::Plugin::Authority name: '@Author::PERLANCAR/Authority' version: '1.009' - class: Dist::Zilla::Plugin::OurDate name: '@Author::PERLANCAR/OurDate' version: '0.03' - class: Dist::Zilla::Plugin::OurDist name: '@Author::PERLANCAR/OurDist' version: '0.02' - class: Dist::Zilla::Plugin::PERLANCAR::OurPkgVersion name: '@Author::PERLANCAR/PERLANCAR::OurPkgVersion' version: '0.04' - class: Dist::Zilla::Plugin::PodWeaver config: Dist::Zilla::Plugin::PodWeaver: finder: - ':InstallModules' - ':ExecFiles' plugins: - class: Pod::Weaver::Plugin::EnsurePod5 name: '@CorePrep/EnsurePod5' version: '4.013' - class: Pod::Weaver::Plugin::H1Nester name: '@CorePrep/H1Nester' version: '4.013' - class: Pod::Weaver::Section::Name name: '@Author::PERLANCAR/Name' version: '4.013' - class: Pod::Weaver::Section::Version name: '@Author::PERLANCAR/Version' version: '4.013' - class: Pod::Weaver::Section::Region name: '@Author::PERLANCAR/prelude' version: '4.013' - class: Pod::Weaver::Section::Generic name: SYNOPSIS version: '4.013' - class: Pod::Weaver::Section::Generic name: DESCRIPTION version: '4.013' - class: Pod::Weaver::Section::Generic name: OVERVIEW version: '4.013' - class: Pod::Weaver::Section::Collect name: ATTRIBUTES version: '4.013' - class: Pod::Weaver::Section::Collect name: METHODS version: '4.013' - class: Pod::Weaver::Section::Collect name: FUNCTIONS version: '4.013' - class: Pod::Weaver::Section::Leftovers name: '@Author::PERLANCAR/Leftovers' version: '4.013' - class: Pod::Weaver::Section::Region name: '@Author::PERLANCAR/postlude' version: '4.013' - class: Pod::Weaver::Section::Completion::GetoptLongComplete name: '@Author::PERLANCAR/Completion::GetoptLongComplete' version: '0.08' - class: Pod::Weaver::Section::Completion::GetoptLongSubcommand name: '@Author::PERLANCAR/Completion::GetoptLongSubcommand' version: '0.04' - class: Pod::Weaver::Section::Completion::GetoptLongMore name: '@Author::PERLANCAR/Completion::GetoptLongMore' version: '0.001' - class: Pod::Weaver::Section::Homepage::DefaultCPAN name: '@Author::PERLANCAR/Homepage::DefaultCPAN' version: '0.05' - class: Pod::Weaver::Section::Source::DefaultGitHub name: '@Author::PERLANCAR/Source::DefaultGitHub' version: '0.07' - class: Pod::Weaver::Section::Bugs::DefaultRT name: '@Author::PERLANCAR/Bugs::DefaultRT' version: '0.06' - class: Pod::Weaver::Section::Authors name: '@Author::PERLANCAR/Authors' version: '4.013' - class: Pod::Weaver::Section::Legal name: '@Author::PERLANCAR/Legal' version: '4.013' - class: Pod::Weaver::Plugin::Rinci name: '@Author::PERLANCAR/Rinci' version: '0.76' - class: Pod::Weaver::Plugin::AppendPrepend name: '@Author::PERLANCAR/AppendPrepend' version: '0.01' - class: Pod::Weaver::Plugin::EnsureUniqueSections name: '@Author::PERLANCAR/EnsureUniqueSections' version: '0.121550' - class: Pod::Weaver::Plugin::SingleEncoding name: '@Author::PERLANCAR/SingleEncoding' version: '4.013' - class: Pod::Weaver::Plugin::PERLANCAR::SortSections name: '@Author::PERLANCAR/PERLANCAR::SortSections' version: '0.06' name: '@Author::PERLANCAR/PodWeaver' version: '4.008' - class: Dist::Zilla::Plugin::PruneFiles name: '@Author::PERLANCAR/PruneFiles' version: '6.008' - class: Dist::Zilla::Plugin::ReadmeFromPod name: '@Author::PERLANCAR/ReadmeFromPod' version: '0.35' - class: Dist::Zilla::Plugin::Rinci::AddPrereqs name: '@Author::PERLANCAR/Rinci::AddPrereqs' version: '0.13' - class: Dist::Zilla::Plugin::Rinci::AddToDb name: '@Author::PERLANCAR/Rinci::AddToDb' version: '0.01' - class: Dist::Zilla::Plugin::Rinci::Validate name: '@Author::PERLANCAR/Rinci::Validate' version: '0.24' - class: Dist::Zilla::Plugin::SetScriptShebang name: '@Author::PERLANCAR/SetScriptShebang' version: '0.01' - class: Dist::Zilla::Plugin::Test::Compile config: Dist::Zilla::Plugin::Test::Compile: bail_out_on_fail: '0' fail_on_warning: author fake_home: 0 filename: t/00-compile.t module_finder: - ':InstallModules' needs_display: 0 phase: test script_finder: - ':PerlExecFiles' skips: [] name: '@Author::PERLANCAR/Test::Compile' version: '2.054' - class: Dist::Zilla::Plugin::Test::Rinci name: '@Author::PERLANCAR/Test::Rinci' version: '0.03' - class: Dist::Zilla::Plugin::UploadToCPAN::WWWPAUSESimple name: '@Author::PERLANCAR/UploadToCPAN::WWWPAUSESimple' version: '0.04' - class: Dist::Zilla::Plugin::EnsureSQLSchemaVersionedTest name: '@Author::PERLANCAR/EnsureSQLSchemaVersionedTest' version: '0.02' - class: Dist::Zilla::Plugin::Acme::CPANLists::Blacklist name: '@Author::PERLANCAR/Acme::CPANLists::Blacklist' version: '0.02' - class: Dist::Zilla::Plugin::Prereqs::EnsureVersion name: '@Author::PERLANCAR/Prereqs::EnsureVersion' version: '0.02' - class: Dist::Zilla::Plugin::Prereqs::CheckCircular name: '@Author::PERLANCAR/Prereqs::CheckCircular' version: '0.004' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: test type: requires name: TestRequires version: '6.008' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: runtime type: requires name: Prereqs version: '6.008' - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: '6.008' - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: '6.008' - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: '6.008' - class: Dist::Zilla::Plugin::FinderCode name: ':ExtraTestFiles' version: '6.008' - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: '6.008' - class: Dist::Zilla::Plugin::FinderCode name: ':PerlExecFiles' version: '6.008' - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: '6.008' - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: '6.008' - class: Dist::Zilla::Plugin::FinderCode name: ':AllFiles' version: '6.008' - class: Dist::Zilla::Plugin::FinderCode name: ':NoFiles' version: '6.008' zilla: class: Dist::Zilla::Dist::Builder config: is_trial: '0' version: '6.008' x_authority: cpan:PERLANCAR x_serialization_backend: 'YAML::Tiny version 1.69' Array-Iterator-0.12/t/0000755000175000017500000000000013126720761012205 5ustar u1u1Array-Iterator-0.12/t/50_Array_Iterator_Reusable_test.t0000644000175000017500000000121013126720761020500 0ustar u1u1#!/usr/bin/perl use strict; use warnings; use Test::More tests => 12; BEGIN { use_ok('Array::Iterator::Reusable') }; can_ok("Array::Iterator::Reusable", 'new'); my $i = Array::Iterator::Reusable->new(1 .. 5); isa_ok($i, 'Array::Iterator::Reusable'); isa_ok($i, 'Array::Iterator'); can_ok($i, 'getNext'); can_ok($i, 'get_next'); # exhaust our iterator 1 while $i->getNext(); can_ok($i, 'hasNext'); can_ok($i, 'has_next'); ok(!$i->hasNext(), '... our iterator is exhausted'); can_ok($i, 'reset'); $i->reset(); ok($i->hasNext(), '... our iterator has been reset'); cmp_ok($i->currentIndex(), '==', 0, '... we are back to the begining'); Array-Iterator-0.12/t/40_Array_Iterator_Circular_test.t0000644000175000017500000000212313126720761020505 0ustar u1u1#!/usr/bin/perl use strict; use warnings; use Test::More tests => 25; BEGIN { use_ok('Array::Iterator::Circular') }; can_ok("Array::Iterator::Circular", 'new'); my $i = Array::Iterator::Circular->new(1 .. 5); isa_ok($i, 'Array::Iterator::Circular'); isa_ok($i, 'Array::Iterator'); can_ok($i, 'getLoopCount'); can_ok($i, 'get_loop_count'); can_ok($i, 'isStart'); can_ok($i, 'is_start'); can_ok($i, 'isEnd'); can_ok($i, 'is_end'); can_ok($i, 'getNext'); can_ok($i, 'get_next'); ok($i->isStart(), '... we are at the start of the array'); my $total_count = 0; while ($i->getLoopCount() < 5) { if ($total_count && (($total_count % 5) == 0)) { ok($i->isEnd(), '... we are at the end of the array'); ok($i->hasNext(), '... we should still get true from hasNext'); } defined($i->getNext()) || fail('... this should never return undef'); $total_count++; } cmp_ok($i->getLoopCount(), '==', 5, '... we have looped 5 times'); # this should be 1 past because of how the loop # above it structured, it is correct. cmp_ok($total_count, '==', 26, '... we have looped 5 times'); Array-Iterator-0.12/t/20_Array_Iterator_exceptions.t0000644000175000017500000000705313126720761020070 0ustar u1u1#!/usr/bin/perl use strict; use warnings; use Test::More tests => 19; use Test::Exception; BEGIN { use_ok('Array::Iterator') }; # test the exceptions # test that the constructor cannot be empty throws_ok { my $i = Array::Iterator->new(); } qr/^Insufficient Arguments \: you must provide something to iterate over/, '... we got the error we expected'; # check that it does not allow non-array ref paramaters throws_ok { my $i = Array::Iterator->new({}); } qr/^Incorrect type \: HASH reference must contain the key __array__/, '... we got the error we expected'; # or single element arrays (cause they make no sense) throws_ok { my $i = Array::Iterator->new(1); } qr/^Incorrect Type \: the argument must be an array or hash reference/, '... we got the error we expected'; # verify the HASH ref sanity checks throws_ok { my $i = Array::Iterator->new({ no_array_key => [] }); } qr/^Incorrect type \: HASH reference must contain the key __array__/, '... we got the error we expected'; throws_ok { my $i = Array::Iterator->new({ __array__ => "not an array ref" }); } qr/^Incorrect type \: __array__ value must be an ARRAY reference/, '... we got the error we expected'; throws_ok { Array::Iterator->_init(undef, 1); } qr/^Insufficient Arguments \: you must provide an length and an iteratee/, '... we got the error we expected'; throws_ok { Array::Iterator->_init(1); } qr/^Insufficient Arguments \: you must provide an length and an iteratee/, '... we got the error we expected'; # now test the next & peek exceptions my @control = (1 .. 5); my $iterator = Array::Iterator->new(@control); isa_ok($iterator, 'Array::Iterator'); my @_control; push @_control => $iterator->next() while $iterator->hasNext(); ok(!$iterator->hasNext(), '... we are out of elements'); ok(eq_array(\@control, \@_control), '.. make sure all are exhausted'); # test that next will croak if it is called passed the end throws_ok { $iterator->next(); } qr/^Out Of Bounds \: no more elements/, '... we got the error we expected'; # test arbitrary lookups edge cases { my $iterator2 = Array::Iterator->new(@control); throws_ok { $iterator2->has_next(0) } qr/\Qhas_next(0) doesn't make sense/, '... should not be able to call has_next() with zero argument'; throws_ok { $iterator2->has_next(-1) } qr/\Qhas_next() with negative argument doesn't make sense/, '... should not be able to call has_next() with negative argument'; throws_ok { $iterator2->peek(0) } qr/\Qpeek(0) doesn't make sense/, '... should not be able to call peek() with zero argument'; throws_ok { $iterator2->peek(-1) } qr/\Qpeek() with negative argument doesn't make sense/, '... should not be able to call peek() with negative argument'; } # check our protected methods throws_ok { $iterator->_current_index(); } qr/Illegal Operation/, '... got the error we expected'; throws_ok { $iterator->_iteratee(); } qr/Illegal Operation/, '... got the error we expected'; throws_ok { $iterator->_getItem(); } qr/Illegal Operation/, '... got the error we expected'; # ----------------------------------------------- # NOTE: # Test removed, peek no longer dies when it reaches # beyond the iterators bounds, it returns undef instead # ----------------------------------------------- # test that peek will croak if it is called passed the end # throws_ok { # $iterator->peek(); # } qr/^Out Of Bounds \: cannot peek past the end of the array/, # '... we got the error we expected'; # ----------------------------------------------- Array-Iterator-0.12/t/10_Array_Iterator_test.t0000644000175000017500000001354713126720761016672 0ustar u1u1#!/usr/bin/perl use strict; use warnings; use Test::More tests => 99; BEGIN { use_ok('Array::Iterator') }; my @control = (1 .. 5); can_ok("Array::Iterator", 'new'); my $iterator = Array::Iterator->new(@control); isa_ok($iterator, 'Array::Iterator'); # check my private methods can_ok($iterator, '_init'); # check my protected methods can_ok($iterator, '_getItem'); can_ok($iterator, '_current_index'); can_ok($iterator, '_iteratee'); # check out public methods can_ok($iterator, 'hasNext'); can_ok($iterator, 'has_next'); can_ok($iterator, 'next'); can_ok($iterator, 'peek'); can_ok($iterator, 'getNext'); can_ok($iterator, 'get_next'); can_ok($iterator, 'current'); can_ok($iterator, 'currentIndex'); can_ok($iterator, 'current_index'); can_ok($iterator, 'getLength'); can_ok($iterator, 'get_length'); can_ok($iterator, 'iterated'); # now check the behavior ok(!$iterator->iterated(), '... not yet iterated, iterated() is false'); cmp_ok($iterator->getLength(), '==', 5, '... got the right length'); for (my $i = 0; $i < scalar @control; $i++) { # we should still have another one ok($iterator->hasNext(), '... we have more elements'); # and out iterator peek should match our control index # (since we have not incremented the iterator's counter) unless ($i >= (scalar(@control))) { cmp_ok($iterator->peek(), '==', $control[$i], '... our control should match our iterator->peek'); } else { ok(!defined($iterator->peek()), '... this should return undef now'); } # and out iterator should match our control cmp_ok($iterator->next(), '==', $control[$i], '... our control should match our iterator->next'); # and out iterator peek should match our control + 1 (now that we have incremented the counter) unless (($i + 1) >= (scalar(@control))) { cmp_ok($iterator->peek(), '==', $control[$i + 1], '... our control should match our iterator->peek'); } else { ok(!defined($iterator->peek()), '... this should return undef now'); } } ok($iterator->iterated(), '... has been iterated, iterated() is true'); # we should have no more ok(!$iterator->hasNext(), '... we should have no more'); # now use an array ref in the constructor # and try using it in this style loop for (my $i = Array::Iterator->new(\@control); $i->hasNext(); $i->next()) { cmp_ok($i->current(), '==', $control[$i->currentIndex()], '... these should be equal'); } my $iterator2 = Array::Iterator->new(@control); my @acc; push @acc, => $iterator2->next() while $iterator2->hasNext(); # our accumulation and control should be the same ok(eq_array(\@acc, \@control), '... these arrays should be equal'); # we should have no more ok(!$iterator2->hasNext(), '... we should have no more'); { my $iterator3 = Array::Iterator->new(\@control); my $current; while ($current = $iterator3->getNext()) { if ($iterator3->currentIndex() + 1 < (scalar(@control))) { cmp_ok($iterator3->peek(), '==', $control[$iterator3->currentIndex() + 1], '... these should be equal (peek & currentIndex + 1)'); } else { ok(!defined($iterator3->peek()), '... this should return undef now'); } cmp_ok($current, '==', $control[$iterator3->currentIndex()], '... these should be equal (getNext)'); cmp_ok($current, '==', $iterator3->current(), '... these should be equal (getNext)'); } ok(!defined($iterator3->getNext()), '... we should get undef'); # we should have no more ok(!$iterator3->hasNext(), '... we should have no more'); } { # verify that we can pass a hash ref as well my $iterator4 = Array::Iterator->new({ __array__ => \@control }); isa_ok($iterator, 'Array::Iterator'); my $current; while ($current = $iterator4->getNext()) { if ($iterator4->currentIndex() + 1 < (scalar(@control))) { cmp_ok($iterator4->peek(), '==', $control[$iterator4->currentIndex() + 1], '... these should be equal (peek & currentIndex + 1)'); } else { ok(!defined($iterator4->peek()), '... this should return undef now'); } cmp_ok($current, '==', $control[$iterator4->currentIndex()], '... these should be equal (getNext)'); cmp_ok($current, '==', $iterator4->current(), '... these should be equal (getNext)'); } ok(!defined($iterator4->getNext()), '... we should get undef'); # we should have no more ok(!$iterator4->hasNext(), '... we should have no more'); } { # check arbitrary position lookups my $iterator5 = Array::Iterator->new(@control); # when not iterated() ok($iterator5->has_next, '... we should have next element'); ok($iterator5->has_next(1), '... should be the same as has_next()'); ok($iterator5->has_next(2), '... we should have 2nd next element'); ok($iterator5->has_next(5), '... we should have 5th next element'); ok(!$iterator5->has_next(6), '... we should not have 6th next element'); cmp_ok($iterator5->peek(1), '==', $iterator5->peek, '... should be the same as peek()'); cmp_ok($iterator5->peek(2), '==', 2, '... we should get 2nd next element'); cmp_ok($iterator5->peek(5), '==', 5, '... we should get 5th next element'); ok(!defined($iterator5->peek(6)), '... peek() outside of the bounds should return undef'); $iterator5->next; # when iterated() ok($iterator5->has_next(4), '... we should have 4th next element after iterating'); ok(!$iterator5->has_next(5), '... we should not have 5th next element after iterating'); cmp_ok($iterator5->peek(1), '==', $iterator5->peek, '... should be the same as peek() after iterating'); cmp_ok($iterator5->peek(2), '==', 3, '... we should get 2nd next element after iterating'); ok(!defined($iterator5->peek(5)), '... peek() outside of the bounds should return undef after iterating'); } Array-Iterator-0.12/t/30_Array_Iterator_BiDirectional_test.t0000644000175000017500000001007113126720761021451 0ustar u1u1#!/usr/bin/perl use strict; use warnings; use Test::More tests => 48; use Test::Exception; BEGIN { use_ok('Array::Iterator::BiDirectional') }; my @control = (1 .. 5); can_ok("Array::Iterator::BiDirectional", 'new'); my $iterator = Array::Iterator::BiDirectional->new(@control); isa_ok($iterator, 'Array::Iterator::BiDirectional'); isa_ok($iterator, 'Array::Iterator'); # check out public methods can_ok($iterator, 'hasPrevious'); can_ok($iterator, 'has_previous'); can_ok($iterator, 'previous'); can_ok($iterator, 'lookBack'); can_ok($iterator, 'look_back'); can_ok($iterator, 'getPrevious'); can_ok($iterator, 'get_previous'); # now check the behavior # move our counter to the end $iterator->next() while $iterator->hasNext(); for (my $i = $#control; $i > 0; $i--) { # we should still have another one ok($iterator->hasPrevious(), '... we have some previous items'); # and out iterator peek should match our control + 1 unless (($i - 1) <= 0) { cmp_ok($iterator->lookBack(), '==', $control[$i - 1], '... our control should match our iterator->lookBack'); } else { ok(!defined($iterator->lookBack()), '... this should return undef now'); } # and out iterator should match our control cmp_ok($iterator->previous(), '==', $control[$i], '... our control should match our iterator->previous'); } # we should have no more ok(!$iterator->hasPrevious(), '... we should have no more'); # now use an array ref in the constructor # and try using it in this style loop my $iterator2 = Array::Iterator::BiDirectional->new(\@control); isa_ok($iterator2, 'Array::Iterator::BiDirectional'); isa_ok($iterator2, 'Array::Iterator'); # move our iterator to the end $iterator2->next() while $iterator2->hasNext(); for (my $i = $iterator2; $i->hasPrevious(); $i->getPrevious()) { cmp_ok($i->current(), '==', $control[$i->currentIndex()], '... these should be equal'); } ok(!defined($iterator2->getPrevious()), '... this should return undef'); throws_ok { $iterator2->previous(); } qr/Out Of Bounds \: no more elements/, '... this should die if i try again'; my $iterator3 = Array::Iterator::BiDirectional->new(@control); # when not iterated() ok(!$iterator3->has_previous(1), '... should be the same as has_previous()'); ok(!$iterator3->has_previous(2), '... should not have 2nd previous element'); ok(!$iterator3->has_previous(3), '... should not have 3rd previous element'); ok(!defined($iterator3->look_back(1)), '... should be the same as look_back()'); ok(!defined($iterator3->look_back(2)), '... look_back() outside of the bounds should return undef'); ok(!defined($iterator3->look_back(5)), '... look_back() outside of the bounds should return undef'); $iterator3->next while $iterator3->has_next; # when iterated() ok($iterator3->has_previous(1), '... should be the same as has_previous() after iterating'); ok($iterator3->has_previous(2), '... should have 2nd previous element'); cmp_ok($iterator3->look_back(1), '==', $iterator3->look_back, '... should be the same as look_back() after iterating'); cmp_ok($iterator3->look_back(2), '==', 3, '... should get 2nd previous element after iterating'); cmp_ok($iterator3->look_back(3), '==', 2, '... should get 3rd previous element after iterating'); ok(!defined($iterator3->look_back(6)), '... look_back() outside of the bounds should return undef after iterating'); # check arbitrary lookup edge cases throws_ok { $iterator3->has_previous(0) } qr/\Qhas_previous(0) doesn't make sense/, '... should not be able to call has_previous() with zero argument'; throws_ok { $iterator3->has_previous(-1) } qr/\Qhas_previous() with negative argument doesn't make sense/, '... should not be able to call has_previous() with negative argument'; throws_ok { $iterator3->look_back(0) } qr/\Qlook_back(0) doesn't make sense/, '... should not be able to call look_back() with zero argument'; throws_ok { $iterator3->look_back(-1) } qr/\Qlook_back() with negative argument doesn't make sense/, '... should not be able to call look_back() with negative argument'; Array-Iterator-0.12/t/author-pod-syntax.t0000644000175000017500000000045413126720761016003 0ustar u1u1#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print qq{1..0 # SKIP these tests are for testing by the author\n}; exit } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); Array-Iterator-0.12/t/00-compile.t0000644000175000017500000000250613126720761014242 0ustar u1u1use 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.054 use Test::More; plan tests => 4 + ($ENV{AUTHOR_TESTING} ? 1 : 0); my @module_files = ( 'Array/Iterator.pm', 'Array/Iterator/BiDirectional.pm', 'Array/Iterator/Circular.pm', 'Array/Iterator/Reusable.pm' ); # no fake home requested my $inc_switch = -d 'blib' ? '-Mblib' : '-Ilib'; use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L my $stderr = IO::Handle->new; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/ and not eval { require blib; blib->VERSION('1.01') }; if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ) if $ENV{AUTHOR_TESTING}; Array-Iterator-0.12/t/author-pod-coverage.t0000644000175000017500000000053613126720761016251 0ustar u1u1#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print qq{1..0 # SKIP these tests are for testing by the author\n}; exit } } # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); Array-Iterator-0.12/weaver.ini0000644000175000017500000000002513126720761013731 0ustar u1u1[@Author::PERLANCAR] Array-Iterator-0.12/META.json0000644000175000017500000004505713126720761013376 0ustar u1u1{ "abstract" : "A simple class for iterating over Perl arrays", "author" : [ "perlancar " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.008, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Array-Iterator", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Pod::Coverage::TrustPod" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "requires" : { "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "File::Spec" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Test::Exception" : "0", "Test::More" : "0.98" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://rt.cpan.org/Public/Dist/Display.html?Name=Array-Iterator" }, "homepage" : "https://metacpan.org/release/Array-Iterator", "repository" : { "type" : "git", "url" : "git://github.com/sharyanto/perl-Array-Iterator.git", "web" : "https://github.com/sharyanto/perl-Array-Iterator" } }, "version" : "0.12", "x_Dist_Zilla" : { "perl" : { "version" : "5.024000" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::GatherDir", "config" : { "Dist::Zilla::Plugin::GatherDir" : { "exclude_filename" : [], "exclude_match" : [], "follow_symlinks" : 0, "include_dotfiles" : 0, "prefix" : "", "prune_directory" : [], "root" : "." } }, "name" : "@Author::PERLANCAR/@Filter/GatherDir", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@Author::PERLANCAR/@Filter/PruneCruft", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@Author::PERLANCAR/@Filter/ManifestSkip", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@Author::PERLANCAR/@Filter/MetaYAML", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@Author::PERLANCAR/@Filter/License", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::PodCoverageTests", "name" : "@Author::PERLANCAR/@Filter/PodCoverageTests", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::PodSyntaxTests", "name" : "@Author::PERLANCAR/@Filter/PodSyntaxTests", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::ExtraTests", "name" : "@Author::PERLANCAR/@Filter/ExtraTests", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@Author::PERLANCAR/@Filter/ExecDir", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@Author::PERLANCAR/@Filter/ShareDir", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::MakeMaker", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 1 } }, "name" : "@Author::PERLANCAR/@Filter/MakeMaker", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@Author::PERLANCAR/@Filter/Manifest", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@Author::PERLANCAR/@Filter/ConfirmRelease", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::PERLANCAR::BeforeBuild", "name" : "@Author::PERLANCAR/PERLANCAR::BeforeBuild", "version" : "0.55" }, { "class" : "Dist::Zilla::Plugin::Rinci::AbstractFromMeta", "name" : "@Author::PERLANCAR/Rinci::AbstractFromMeta", "version" : "0.09" }, { "class" : "Dist::Zilla::Plugin::PodnameFromFilename", "name" : "@Author::PERLANCAR/PodnameFromFilename", "version" : "0.02" }, { "class" : "Dist::Zilla::Plugin::PERLANCAR::EnsurePrereqToSpec", "name" : "@Author::PERLANCAR/PERLANCAR::EnsurePrereqToSpec", "version" : "0.04" }, { "class" : "Dist::Zilla::Plugin::PERLANCAR::MetaResources", "name" : "@Author::PERLANCAR/PERLANCAR::MetaResources", "version" : "0.03" }, { "class" : "Dist::Zilla::Plugin::CheckChangeLog", "name" : "@Author::PERLANCAR/CheckChangeLog", "version" : "0.02" }, { "class" : "Dist::Zilla::Plugin::CheckMetaResources", "name" : "@Author::PERLANCAR/CheckMetaResources", "version" : "0.001" }, { "class" : "Dist::Zilla::Plugin::CopyrightYearFromGit", "name" : "@Author::PERLANCAR/CopyrightYearFromGit", "version" : "0.003" }, { "class" : "Dist::Zilla::Plugin::IfBuilt", "name" : "@Author::PERLANCAR/IfBuilt", "version" : "0.03" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "@Author::PERLANCAR/MetaJSON", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "@Author::PERLANCAR/MetaConfig", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::GenShellCompletion", "name" : "@Author::PERLANCAR/GenShellCompletion", "version" : "0.11" }, { "class" : "Dist::Zilla::Plugin::Authority", "name" : "@Author::PERLANCAR/Authority", "version" : "1.009" }, { "class" : "Dist::Zilla::Plugin::OurDate", "name" : "@Author::PERLANCAR/OurDate", "version" : "0.03" }, { "class" : "Dist::Zilla::Plugin::OurDist", "name" : "@Author::PERLANCAR/OurDist", "version" : "0.02" }, { "class" : "Dist::Zilla::Plugin::PERLANCAR::OurPkgVersion", "name" : "@Author::PERLANCAR/PERLANCAR::OurPkgVersion", "version" : "0.04" }, { "class" : "Dist::Zilla::Plugin::PodWeaver", "config" : { "Dist::Zilla::Plugin::PodWeaver" : { "finder" : [ ":InstallModules", ":ExecFiles" ], "plugins" : [ { "class" : "Pod::Weaver::Plugin::EnsurePod5", "name" : "@CorePrep/EnsurePod5", "version" : "4.013" }, { "class" : "Pod::Weaver::Plugin::H1Nester", "name" : "@CorePrep/H1Nester", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Name", "name" : "@Author::PERLANCAR/Name", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Version", "name" : "@Author::PERLANCAR/Version", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@Author::PERLANCAR/prelude", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "SYNOPSIS", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "DESCRIPTION", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "OVERVIEW", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "ATTRIBUTES", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "METHODS", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "FUNCTIONS", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Leftovers", "name" : "@Author::PERLANCAR/Leftovers", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@Author::PERLANCAR/postlude", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Completion::GetoptLongComplete", "name" : "@Author::PERLANCAR/Completion::GetoptLongComplete", "version" : "0.08" }, { "class" : "Pod::Weaver::Section::Completion::GetoptLongSubcommand", "name" : "@Author::PERLANCAR/Completion::GetoptLongSubcommand", "version" : "0.04" }, { "class" : "Pod::Weaver::Section::Completion::GetoptLongMore", "name" : "@Author::PERLANCAR/Completion::GetoptLongMore", "version" : "0.001" }, { "class" : "Pod::Weaver::Section::Homepage::DefaultCPAN", "name" : "@Author::PERLANCAR/Homepage::DefaultCPAN", "version" : "0.05" }, { "class" : "Pod::Weaver::Section::Source::DefaultGitHub", "name" : "@Author::PERLANCAR/Source::DefaultGitHub", "version" : "0.07" }, { "class" : "Pod::Weaver::Section::Bugs::DefaultRT", "name" : "@Author::PERLANCAR/Bugs::DefaultRT", "version" : "0.06" }, { "class" : "Pod::Weaver::Section::Authors", "name" : "@Author::PERLANCAR/Authors", "version" : "4.013" }, { "class" : "Pod::Weaver::Section::Legal", "name" : "@Author::PERLANCAR/Legal", "version" : "4.013" }, { "class" : "Pod::Weaver::Plugin::Rinci", "name" : "@Author::PERLANCAR/Rinci", "version" : "0.76" }, { "class" : "Pod::Weaver::Plugin::AppendPrepend", "name" : "@Author::PERLANCAR/AppendPrepend", "version" : "0.01" }, { "class" : "Pod::Weaver::Plugin::EnsureUniqueSections", "name" : "@Author::PERLANCAR/EnsureUniqueSections", "version" : "0.121550" }, { "class" : "Pod::Weaver::Plugin::SingleEncoding", "name" : "@Author::PERLANCAR/SingleEncoding", "version" : "4.013" }, { "class" : "Pod::Weaver::Plugin::PERLANCAR::SortSections", "name" : "@Author::PERLANCAR/PERLANCAR::SortSections", "version" : "0.06" } ] } }, "name" : "@Author::PERLANCAR/PodWeaver", "version" : "4.008" }, { "class" : "Dist::Zilla::Plugin::PruneFiles", "name" : "@Author::PERLANCAR/PruneFiles", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::ReadmeFromPod", "name" : "@Author::PERLANCAR/ReadmeFromPod", "version" : "0.35" }, { "class" : "Dist::Zilla::Plugin::Rinci::AddPrereqs", "name" : "@Author::PERLANCAR/Rinci::AddPrereqs", "version" : "0.13" }, { "class" : "Dist::Zilla::Plugin::Rinci::AddToDb", "name" : "@Author::PERLANCAR/Rinci::AddToDb", "version" : "0.01" }, { "class" : "Dist::Zilla::Plugin::Rinci::Validate", "name" : "@Author::PERLANCAR/Rinci::Validate", "version" : "0.24" }, { "class" : "Dist::Zilla::Plugin::SetScriptShebang", "name" : "@Author::PERLANCAR/SetScriptShebang", "version" : "0.01" }, { "class" : "Dist::Zilla::Plugin::Test::Compile", "config" : { "Dist::Zilla::Plugin::Test::Compile" : { "bail_out_on_fail" : 0, "fail_on_warning" : "author", "fake_home" : 0, "filename" : "t/00-compile.t", "module_finder" : [ ":InstallModules" ], "needs_display" : 0, "phase" : "test", "script_finder" : [ ":PerlExecFiles" ], "skips" : [] } }, "name" : "@Author::PERLANCAR/Test::Compile", "version" : "2.054" }, { "class" : "Dist::Zilla::Plugin::Test::Rinci", "name" : "@Author::PERLANCAR/Test::Rinci", "version" : "0.03" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN::WWWPAUSESimple", "name" : "@Author::PERLANCAR/UploadToCPAN::WWWPAUSESimple", "version" : "0.04" }, { "class" : "Dist::Zilla::Plugin::EnsureSQLSchemaVersionedTest", "name" : "@Author::PERLANCAR/EnsureSQLSchemaVersionedTest", "version" : "0.02" }, { "class" : "Dist::Zilla::Plugin::Acme::CPANLists::Blacklist", "name" : "@Author::PERLANCAR/Acme::CPANLists::Blacklist", "version" : "0.02" }, { "class" : "Dist::Zilla::Plugin::Prereqs::EnsureVersion", "name" : "@Author::PERLANCAR/Prereqs::EnsureVersion", "version" : "0.02" }, { "class" : "Dist::Zilla::Plugin::Prereqs::CheckCircular", "name" : "@Author::PERLANCAR/Prereqs::CheckCircular", "version" : "0.004" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "test", "type" : "requires" } }, "name" : "TestRequires", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "runtime", "type" : "requires" } }, "name" : "Prereqs", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExtraTestFiles", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":PerlExecFiles", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":AllFiles", "version" : "6.008" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":NoFiles", "version" : "6.008" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : 0 }, "version" : "6.008" } }, "x_authority" : "cpan:PERLANCAR", "x_serialization_backend" : "Cpanel::JSON::XS version 3.0217" } Array-Iterator-0.12/MANIFEST0000644000175000017500000000100613126720761013070 0ustar u1u1# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.008. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini lib/Array/Iterator.pm lib/Array/Iterator/BiDirectional.pm lib/Array/Iterator/Circular.pm lib/Array/Iterator/Reusable.pm t/00-compile.t t/10_Array_Iterator_test.t t/20_Array_Iterator_exceptions.t t/30_Array_Iterator_BiDirectional_test.t t/40_Array_Iterator_Circular_test.t t/50_Array_Iterator_Reusable_test.t t/author-pod-coverage.t t/author-pod-syntax.t weaver.ini Array-Iterator-0.12/lib/0000755000175000017500000000000013126720761012510 5ustar u1u1Array-Iterator-0.12/lib/Array/0000755000175000017500000000000013126720761013566 5ustar u1u1Array-Iterator-0.12/lib/Array/Iterator/0000755000175000017500000000000013126720761015357 5ustar u1u1Array-Iterator-0.12/lib/Array/Iterator/Reusable.pm0000644000175000017500000000524113126720761017461 0ustar u1u1 package Array::Iterator::Reusable; use strict; use warnings; our $VERSION = '0.12'; # VERSION use Array::Iterator; our @ISA = qw(Array::Iterator); sub reset { my ($self) = @_; $self->_iterated = 0; $self->_current_index = 0; } 1; # ABSTRACT: A subclass of Array::Iterator to allow reuse of iterators __END__ =pod =encoding UTF-8 =head1 NAME Array::Iterator::Reusable - A subclass of Array::Iterator to allow reuse of iterators =head1 VERSION This document describes version 0.12 of Array::Iterator::Reusable (from Perl distribution Array-Iterator), released on 2017-07-04. =head1 SYNOPSIS use Array::Iterator::Reusable; # create an iterator with an array my $i = Array::Iterator::Reusable->new(1 .. 100); # do something with the iterator my @accumulation; push @accumulation => { item => $iterator->next() } while $iterator->has_next(); # now reset the iterator so we can do it again $iterator->reset(); =head1 DESCRIPTION Sometimes you don't want to have to throw out your iterator each time you have exhausted it. This class adds the C method to allow reuse of an iterator. This is a very simple addition to the Array::Iterator class of a single method. =for Pod::Coverage .+ =head1 ORIGINAL AUTHOR stevan little, Estevan@iinteractive.comE =head1 ORIGINAL COPYRIGHT AND LICENSE Copyright 2004 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 METHODS This is a subclass of Array::Iterator, only those methods that have been added are documented here, refer to the Array::Iterator documentation for more information. =over 4 =item B This resets the interal counter of the iterator back to the start of the array. =back =head1 HOMEPAGE Please visit the project's homepage at L. =head1 SOURCE Source repository is at L. =head1 BUGS Please report any bugs or feature requests on the bugtracker website L When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. =head1 SEE ALSO This is a subclass of B, please refer to it for more documenation. =head1 AUTHOR perlancar =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2017, 2013, 2012, 2011 by perlancar@cpan.org. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Array-Iterator-0.12/lib/Array/Iterator/Circular.pm0000644000175000017500000001102013126720761017453 0ustar u1u1 package Array::Iterator::Circular; use strict; use warnings; our $VERSION = '0.12'; # VERSION use Array::Iterator; our @ISA = qw(Array::Iterator); sub _init { my ($self, @args) = @_; $self->{loop_counter} = 0; $self->SUPER::_init(@args); } # always return true, since # we just keep looping sub has_next { 1 } sub next { my ($self) = @_; unless ($self->_current_index < $self->getLength()) { $self->_current_index = 0; $self->{loop_counter}++; } $self->_iterated = 1; return $self->_getItem($self->_iteratee(), $self->_current_index++); } # since neither of them will # ever stop dispensing items # they can just be aliases of # one another. *get_next = \&next; sub is_start { my ($self) = @_; return ($self->_current_index() == 0); } sub isStart { my $self = shift; $self->is_start(@_) } sub is_end { my ($self) = @_; return ($self->_current_index() == $self->getLength()); } sub isEnd { my $self = shift; $self->is_end(@_) } sub get_loop_count { my ($self) = @_; return $self->{loop_counter}; } sub getLoopCount { my $self = shift; $self->get_loop_count(@_) } 1; # ABSTRACT: A subclass of Array::Iterator to allow circular iteration __END__ =pod =encoding UTF-8 =head1 NAME Array::Iterator::Circular - A subclass of Array::Iterator to allow circular iteration =head1 VERSION This document describes version 0.12 of Array::Iterator::Circular (from Perl distribution Array-Iterator), released on 2017-07-04. =head1 SYNOPSIS use Array::Iterator::Circular; # create an instance with a # small array my $color_iterator = Array::Iterator::Circular->new(qw(red green blue orange)); # this is a large list of # arbitrary items my @long_list_of_items = ( ... ); # as we loop through the items ... foreach my $item (@long_list_of_items) { # we assign color from our color # iterator, which will keep dispensing # as it loops through its set $item->set_color($color_iterator->next()); } # tell us how many times the set # was looped through print $color_iterator->get_loop_count(); =head1 DESCRIPTION This iterator will loop continuosly as long as C or C is called. The C method will always return true (C<1>), since the list will always loop back. This is useful when you need a list to repeat itself, but don't want to (or care to) know that it is doing so. =for Pod::Coverage .+ =head1 ORIGINAL AUTHOR stevan little, Estevan@iinteractive.comE =head1 ORIGINAL COPYRIGHT AND LICENSE Copyright 2004 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 METHODS This is a subclass of Array::Iterator, only those methods that have been added or altered are documented here, refer to the Array::Iterator documentation for more information. =over 4 =item B Since we endlessly loop, this will always return true (C<1>). =item B This will return the next item in the array, and when it reaches the end of the array, it will loop back to the beginning again. =item B This method is now defined in terms of C, since neither will even stop dispensing items, there is no need to differentiate. =item B If at anytime during your looping, you want to know if you have arrived back at the start of you list, you can ask this method. =item B If at anytime during your looping, you want to know if you have gotten to the end of you list, you can ask this method. =item B This method will tell you how many times the iterator has looped back to its start. =back =head1 HOMEPAGE Please visit the project's homepage at L. =head1 SOURCE Source repository is at L. =head1 BUGS Please report any bugs or feature requests on the bugtracker website L When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. =head1 SEE ALSO This is a subclass of B, please refer to it for more documenation. =head1 AUTHOR perlancar =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2017, 2013, 2012, 2011 by perlancar@cpan.org. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Array-Iterator-0.12/lib/Array/Iterator/BiDirectional.pm0000644000175000017500000001163513126720761020433 0ustar u1u1 package Array::Iterator::BiDirectional; use strict; use warnings; our $VERSION = '0.12'; # VERSION use Array::Iterator; our @ISA = qw(Array::Iterator); sub has_previous { my ($self, $n) = @_; if(not defined $n) { $n = 1 } elsif(not $n) { die "has_previous(0) doesn't make sense, did you mean current()?" } elsif($n < 0) { die "has_previous() with negative argument doesn't make sense, did you mean has_next()?" } my $idx = $self->_current_index - $n; return ($idx > 0) ? 1 : 0; } sub hasPrevious { my $self = shift; $self->has_previous(@_) } sub previous { my ($self) = @_; (($self->_current_index - 1) > 0) || die "Out Of Bounds : no more elements"; $self->_iterated = 1; return $self->_getItem($self->_iteratee, --$self->_current_index); } sub get_previous { my ($self) = @_; return undef unless (($self->_current_index - 1) > 0); $self->_iterated = 1; return $self->_getItem($self->_iteratee, --$self->_current_index); } sub getPrevious { my $self = shift; $self->get_previous(@_) } sub look_back { my ($self, $n) = @_; if(not defined $n) { $n = 1 } elsif(not $n) { die "look_back(0) doesn't make sense, did you mean get_previous()?" } elsif($n < 0) { die "look_back() with negative argument doesn't make sense, did you mean get_next()?" } my $idx = $self->_current_index - ($n + 1); return undef unless ($idx > 0); $self->_iterated = 1; return $self->_getItem($self->_iteratee, $idx); } sub lookBack { my $self = shift; $self->look_back(@_) } 1; # ABSTRACT: A subclass of Array::Iterator to allow forwards and backwards iteration __END__ =pod =encoding UTF-8 =head1 NAME Array::Iterator::BiDirectional - A subclass of Array::Iterator to allow forwards and backwards iteration =head1 VERSION This document describes version 0.12 of Array::Iterator::BiDirectional (from Perl distribution Array-Iterator), released on 2017-07-04. =head1 SYNOPSIS use Array::Iterator::BiDirectional; # create an instance of the iterator my $i = Array::Iterator::BiDirectional->new(1 .. 100); while ($some_condition_exists) { # get the latest item from # the iterator my $current = $i->get_next(); # ... if ($something_happens) { # back up the iterator $current = $i->get_previous(); } } =head1 DESCRIPTION Occasionally it is useful for an iterator to go in both directions, forward and backward. One example would be token processing. When looping though tokens it is sometimes necessary to advance forward looking for a match to a rule. If the match fails, a bi-directional iterator can be moved back so that the next rule can be tried. =for Pod::Coverage .+ =head1 ORIGINAL AUTHOR stevan little, Estevan@iinteractive.comE =head1 ORIGINAL COPYRIGHT AND LICENSE Copyright 2004 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 METHODS This is a subclass of Array::Iterator, only those methods that have been added are documented here, refer to the Array::Iterator documentation for more information. =over 4 =item B This method works much like C does, it will return true (C<1>) unless the beginning of the array has been reached, and false (C<0>) otherwise. Optional argument has the same meaning except that it specifies C<$n>th previous element. =item B This method is much like C. It will return the previous item in the iterator, and throw an exception if it attempts to reach past the beginning of the array. =item B This method is much like C. It will return the previous item in the iterator, and return undef if it attempts to reach past the beginning of the array. =item B This is the counterpart to C, it will return the previous items in the iterator, but will not affect the internal counter. Optional argument has the same meaning except that it specifies C<$n>th previous element. =back =head1 HOMEPAGE Please visit the project's homepage at L. =head1 SOURCE Source repository is at L. =head1 BUGS Please report any bugs or feature requests on the bugtracker website L When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. =head1 SEE ALSO This is a subclass of B, please refer to it for more documenation. =head1 AUTHOR perlancar =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2017, 2013, 2012, 2011 by perlancar@cpan.org. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Array-Iterator-0.12/lib/Array/Iterator.pm0000644000175000017500000003610513126720761015722 0ustar u1u1package Array::Iterator; use strict; use warnings; our $VERSION = '0.12'; # VERSION ### constructor sub new { my ($_class, @array) = @_; (@array) || die "Insufficient Arguments : you must provide something to iterate over"; my $class = ref($_class) || $_class; my $_array; if (scalar @array == 1) { if (ref $array[0] eq "ARRAY") { $_array = $array[0]; } elsif (ref $array[0] eq "HASH") { die "Incorrect type : HASH reference must contain the key __array__" unless exists $array[0]->{__array__}; die "Incorrect type : __array__ value must be an ARRAY reference" unless ref $array[0]->{__array__} eq 'ARRAY'; $_array = $array[0]->{__array__}; } else { die "Incorrect Type : the argument must be an array or hash reference"; } } else { $_array = \@array; } my $iterator = { _current_index => 0, _length => 0, _iteratee => [], _iterated => 0, }; bless($iterator, $class); $iterator->_init(scalar(@{$_array}), $_array); return $iterator; } ### methods # private methods sub _init { my ($self, $length, $iteratee) = @_; (defined($length) && defined($iteratee)) || die "Insufficient Arguments : you must provide an length and an iteratee"; $self->{_current_index} = 0; $self->{_length} = $length; $self->{_iteratee} = $iteratee; } # protected method # this can be used in a subclass to access the value # we need to alter this so its an lvalue sub _current_index : lvalue { (UNIVERSAL::isa((caller)[0], __PACKAGE__)) || die "Illegal Operation : This method can only be called by a subclass"; $_[0]->{_current_index} } # this we should never need to alter # so we dont make it a lvalue sub _iteratee { (UNIVERSAL::isa((caller)[0], __PACKAGE__)) || die "Illegal Operation : This method can only be called by a subclass"; $_[0]->{_iteratee} } # we move this from a private method # to a protected one, and check our access # as well sub _getItem { (UNIVERSAL::isa((caller)[0], __PACKAGE__)) || die "Illegal Operation : This method can only be called by a subclass"; my ($self, $iteratee, $index) = @_; return $iteratee->[$index]; } sub _get_item { my $self = shift; $self->_getItem(@_) } # we need to alter this so its an lvalue sub _iterated : lvalue { (UNIVERSAL::isa((caller)[0], __PACKAGE__)) || die "Illegal Operation : This method can only be called by a subclass"; $_[0]->{_iterated} } # public methods # this defines the interface # an iterator object will have sub iterated { my ($self) = @_; return $self->{_iterated}; } sub has_next { my ($self, $n) = @_; if(not defined $n) { $n = 1 } elsif(not $n) { die "has_next(0) doesn't make sense, did you mean current()?" } elsif($n < 0) { die "has_next() with negative argument doesn't make sense, perhaps you should use a BiDirectional iterator" } my $idx = $self->{_current_index} + ($n - 1); return ($idx < $self->{_length}) ? 1 : 0; } sub hasNext { my $self = shift; $self->has_next(@_) } sub next { my ($self) = @_; ($self->{_current_index} < $self->{_length}) || die "Out Of Bounds : no more elements"; $self->{_iterated} = 1; return $self->_getItem($self->{_iteratee}, $self->{_current_index}++); } sub get_next { my ($self) = @_; $self->{_iterated} = 1; return undef unless ($self->{_current_index} < $self->{_length}); return $self->_getItem($self->{_iteratee}, $self->{_current_index}++); } sub getNext { my $self = shift; $self->get_next(@_) } sub peek { my ($self, $n) = @_; if(not defined $n) { $n = 1 } elsif(not $n) { die "peek(0) doesn't make sense, did you mean get_next()?" } elsif($n < 0) { die "peek() with negative argument doesn't make sense, perhaps you should use a BiDirectional iterator" } my $idx = $self->{_current_index} + ($n - 1); return undef unless ($idx < $self->{_length}); return $self->_getItem($self->{_iteratee}, $idx); } sub current { my ($self) = @_; return $self->_getItem($self->{_iteratee}, $self->currentIndex()); } sub current_index { my ($self) = @_; return ($self->{_current_index} != 0) ? $self->{_current_index} - 1 : 0; } sub currentIndex { my $self = shift; $self->current_index(@_) } sub get_length { my ($self) = @_; return $self->{_length}; } sub getLength { my $self = shift; $self->get_length(@_) } 1; # ABSTRACT: A simple class for iterating over Perl arrays __END__ =pod =encoding UTF-8 =head1 NAME Array::Iterator - A simple class for iterating over Perl arrays =head1 VERSION This document describes version 0.12 of Array::Iterator (from Perl distribution Array-Iterator), released on 2017-07-04. =head1 SYNOPSIS use Array::Iterator; # create an iterator with an array my $i = Array::Iterator->new(1 .. 100); # create an iterator with an array reference my $i = Array::Iterator->new(\@array); # create an iterator with a hash reference my $i = Array::Iterator->new({ __array__ => \@array }); # a base iterator example while ($i->has_next()) { if ($i->peek() < 50) { # ... do something because # the next element is over 50 } my $current = $i->next(); # ... do something with current } # shortcut style my @accumulation; push @accumulation => { item => $iterator->next() } while $iterator->has_next(); # C++ ish style iterator for (my $i = Array::Iterator->new(@array); $i->has_next(); $i->next()) { my $current = $i->current(); # .. do something with current } # common perl iterator idiom my $current; while ($current = $i->get_next()) { # ... do something with $current } =head1 DESCRIPTION This class provides a very simple iterator interface. It is is uni-directional and can only be used once. It provides no means of reverseing or reseting the iterator. It is not recommended to alter the array during iteration, however no attempt is made to enforce this (although I will if I can find an efficient means of doing so). This class only intends to provide a clear and simple means of generic iteration, nothing more (yet). =for Pod::Coverage .+ =head1 TO DO =over 4 =item Improve BiDirectional Test suite I want to test the back and forth a little more, make sure they work well with one another. =item Other Iterators Array::Iterator::BiDirectional::Circular, Array::Iterator::Skipable and Array::Iterator::BiDirectional::Skipable are just a few ideas I have had. I am going to hold off for now until I am sure they are actually useful. =back =head1 OTHER ITERATOR MODULES There are a number of modules on CPAN with the word Iterator in them. Most of them are actually iterators included inside other modules, and only really useful within that parent modules context. There are however some other modules out there that are just for pure iteration. I have provided a list below of the ones I have found, if perhaps you don't happen to like the way I do it. =over 4 =item B This module ties the array, something we do not do. But it also makes an attempt to account for, and allow the array to be changed during iteration. It accomplishes this control because the underlying array is tied. As we all know, tie-ing things can be a performance issue, but if you need what this module provides, then it will likely be an acceptable compromise. Array::Iterator makes no attempt to deal with this mid-iteration manipulation problem. In fact it is recommened to not alter your array with Array::Iterator, and if possible we will enforce this in later versions. =item B This module allows for simple iteratation over both hashes and arrays. It does it by importing several functions which can be used to loop over either type (hash or array) in the same way. It is an interesting module, it differs from Array::Iterator in paradigm (Array::Iterator is more OO) as well as in intent. =item B This is essentially a wrapper around a closure based iterator. This method can be very flexible, but at times is difficult to manage due to the inherent complextity of using closures. I actually was a closure-as-iterator fan for a while, but eventually moved away from it in favor of the more plain vanilla means of iteration, like that found Array::Iterator. =item B This is part of the Class::Visitor module, and is a Visitor and Iterator extensions to Class::Template. Array::Iterator is a standalone module not associated with others. =item B Data::Iterator::EasyObj makes your array of arrays into iterator objects. It also has the ability to further nest additional data structures including Data::Iterator::EasyObj objects. Array::Iterator is one dimensional only, and does not attempt to do many of the more advanced features of this module. =back =head1 ACKNOWLEDGEMENTS =over 4 =item Thanks to Hugo Cornelis for pointing out a bug in C =item Thanks to Phillip Moore for providing the patch to allow single element iteration through the hash-ref constructor parameter. =back =head1 ORIGINAL AUTHOR stevan little, Estevan@iinteractive.comE =head1 ORIGINAL COPYRIGHT AND LICENSE Copyright 2004, 2005 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 METHODS =head2 Public Methods =over 4 =item B The constructor can be passed either a plain perl array, an array reference, or a hash reference (with the array specified as a single key off the hash, __array__). Single element arrays are not supported by either of the first two calling conventions, since it is not possible to distinguish between an array of a single element which happens to be an array reference, and an array reference of a single element, thus previous versions of the constructor would raise an exception. If you expect to pass arrays to the constructor which may have only a single element, then the array can be passed as the element of a HASH reference, with the key, __array__: my $i = Array::Iterator->new({ __array__ => \@array }); =item B This methods returns a boolean. True (1) if there are still more elements in the iterator, false (0) if there are not. Takes an optional positive integer (E 0) that specifies the position you want to check. This allows you to check if there an element at arbitrary position. Think of it as an ordinal number you want to check: $i->has_next(2); # 2nd next element $i->has_next(10); # 10th next element Note that C is the same as C. Throws an exception if C<$n> E= 0. =item B This method returns the next item in the iterator, be sure to only call this once per iteration as it will advance the index pointer to the next item. If this method is called after all elements have been exhausted, an exception will be thrown. =item B This method returns the next item in the iterator, be sure to only call this once per iteration as it will advance the index pointer to the next item. If this method is called after all elements have been exhausted, it will return undef. This method was added to allow for a faily common perl iterator idiom of: my $current; while ($current = $i->get_next()) { ... } In this the loop terminates once C<$current> is assigned to a false value. The only problem with this idiom for me is that it does not allow for undefined or false values in the iterator. Of course, if this fits your data, then there is no problem. Otherwise I would recommend the C/C idiom instead. =item B This method can be used to peek ahead at the next item in the iterator. It is non-destructuve, meaning it does not advance the internal pointer. If this method is called and attempts to reach beyond the bounds of the iterator, it will return undef. Takes an optional positive integer (E 0) that specifies how far ahead you want to peek: $i->peek(2); # gives you 2nd next element $i->peek(10); # gives you 10th next element Note that C is the same as C. Throws an exception if C<$n> E= 0. B Prior to version 0.03 this method would throw an exception if called out of bounds. I decided this was not a good practice, as it made it difficult to be able to peek ahead effectively. This not the case when calling with an argument that is E= 0 though, as it's clearly a sign of incorrect usage. =item B This method can be used to get the current item in the iterator. It is non-destructive, meaning that it does not advance the internal pointer. This value will match the last value dispensed by C or C. =item B This method can be used to get the current index in the iterator. It is non-destructive, meaning that it does not advance the internal pointer. This value will match the index of the last value dispensed by C or C. =item B This is a basic accessor for getting the length of the array being iterated over. =back =head2 Protected Methods These methods are I, in the Java/C++ sense of the word. They can only be called internally by subclasses of Array::Iterator, an exception is thrown if that condition is violated. They are documented here only for people interested in subclassing Array::Iterator. =over 4 =item B<_current_index> An lvalue-ed subroutine which allows access to the iterator's internal pointer. =item B<_iteratee> This returns the item being iteratated over, in our case an array. =item B<_get_item ($iteratee, $index)> This method is used by all other routines to access items with. Given the iteratee and an index, it will return the item being stored in the C<$iteratee> at the index of C<$index>. =back =head1 HOMEPAGE Please visit the project's homepage at L. =head1 SOURCE Source repository is at L. =head1 BUGS Please report any bugs or feature requests on the bugtracker website L When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. =head1 SEE ALSO This module now includes several subclasses of Array::Iterator which add certain behaviors to Array::Iterator, they are: =over 4 =item B Adds the ability to move backwards and forwards through the array. =item B When this iterator reaches the end of its list, it will loop back to the start again. =item B This iterator can be reset to its beginning and used again. =back The Design Patterns book by the Gang of Four, specifically the Iterator pattern. Some of the interface for this class is based upon the Java Iterator interface. =head1 AUTHOR perlancar =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2017, 2013, 2012, 2011 by perlancar@cpan.org. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Array-Iterator-0.12/LICENSE0000644000175000017500000004376513126720761012766 0ustar u1u1This software is copyright (c) 2017, 2013, 2012, 2011 by perlancar@cpan.org. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2017, 2013, 2012, 2011 by perlancar@cpan.org. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2017, 2013, 2012, 2011 by perlancar@cpan.org. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Array-Iterator-0.12/Changes0000644000175000017500000000617713126720761013250 0ustar u1u10.12 2017-07-04 (PERLANCAR) - No functional changes. - Re-release to switch PAUSE account. 0.11 2013-09-18 (SHARYANTO) - No functional changes. Rerelease due to inclusion of unneeded files (steven--). 0.10 2013-09-18 (SHARYANTO) - No functional changes. Apply spelling patch from Debian maintainer Gregor Herman [RT#88745]. 0.09 2013-08-22 (SHARYANTO) - No functional changes. Reformat Changes to be more conformant to CPAN::Changes::Spec (thanks Neil Bowers). 0.08 2012-03-28 (SHARYANTO) - peek(), look_back(), has_next(), has_previous() now accept optional integer argument for arbitrary lookup, e.g. peek(2) looks at the next next item, peek(1) is the same as peek() (implemented by Alexey Surikov, github#2). 0.07 2011-09-09 (SHARYANTO) - Take over maintenance from Stevan Little. - Now uses Dist::Zilla and git. - Add lowercase method name aliases (has_next() as well as hasNext(), etc). The lowercase method names are now the documented ones. - Add iterated() to check whether an iteration has been done (i.e. next(), or get_next(), or previous(), etc has been called). 0.06 2005-07-08 (STEVAN) - Fixed bug in Array::Iterator::peek(). Thanks to Hugo Cornelis for pointing it out - added tests for this - Added patch from Phillip Moore to support *single element iteration* using the hash-ref constructor option. - added tests and docs for this (also from Phillip :) 0.05 2004-07-15 (STEVAN) - added a getLegnth method and tested it - changed how currentIndex deals with index of 0, it now does it correctly. - made current use currentIndex to get the current index - made Array::Iterator more subclass friendly by adding some 'protected' methods to access some fields with - added some subclasses: Array::Iterator::BiDirectional, Array::Iterator::Circular, Array::Iterator::Reusable - created tests for all these new modules 0.04 2004-05-06 (STEVAN) - Changed current and currentIndex to refer to the same value (and index) of the last item dispensed by the next method. This is more in line with what they should do. Prior to this version they returned the current index which was actually the one past the last call to next. - tested these changes and altered tests which used the old versions. - updated documentation to reflect change 0.03 2004-05-02 (STEVAN) - Added currentIndex method, and added tests for it. - Added getNext method and added tests for it. - altered the behavior of peek to not throw an exception. - updated all documentation. 0.02 2004-04-12 (STEVAN) - error in the Makefile.PL file, no changes on this release 0.01 2004-03-17 (STEVAN) - original version; created by h2xs 1.22 with options -X -n Array::Iterator