aboutsummaryrefslogtreecommitdiffstats
path: root/lib/LXRng/Repo/Plain/Iterator.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/LXRng/Repo/Plain/Iterator.pm')
-rw-r--r--lib/LXRng/Repo/Plain/Iterator.pm29
1 files changed, 29 insertions, 0 deletions
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;