From e9fa4c98bb5f084739d3418ade3f0c51e34a0aa1 Mon Sep 17 00:00:00 2001 From: Arne Georg Gleditsch Date: Thu, 5 Jul 2007 00:51:08 +0200 Subject: Rebase tree. --- lib/LXRng/Repo/Plain/Iterator.pm | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lib/LXRng/Repo/Plain/Iterator.pm (limited to 'lib/LXRng/Repo/Plain/Iterator.pm') diff --git a/lib/LXRng/Repo/Plain/Iterator.pm b/lib/LXRng/Repo/Plain/Iterator.pm new file mode 100644 index 0000000..b086860 --- /dev/null +++ b/lib/LXRng/Repo/Plain/Iterator.pm @@ -0,0 +1,29 @@ +package LXRng::Repo::Plain::Iterator; + +use strict; +use LXRng::Repo::Plain; + +sub new { + my ($class, $dir) = @_; + + return bless({dir => $dir, stack => [], nodes => [$dir->contents]}, $class); +} + +sub next { + my ($self) = @_; + + while (@{$$self{'nodes'}} == 0) { + return undef unless @{$$self{'stack'}}; + $$self{'nodes'} = pop(@{$$self{'stack'}}); + } + + my $node = shift(@{$$self{'nodes'}}); + if ($node->isa('LXRng::Repo::Directory')) { + push(@{$$self{'stack'}}, $$self{'nodes'}); + $$self{'nodes'} = [$node->contents]; + return $self->next; + } + return $node; +} + +1; -- cgit v1.2.3