aboutsummaryrefslogtreecommitdiffstats
path: root/lib/LXRng/Repo/Plain/Iterator.pm
blob: b086860a1aa16ada3671f6cc9f0b1c55b476c785 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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;