[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[lintian] 01/02: L::Path: Support recursive-mode for children method



This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository lintian.

commit 2a1f71d9be550d6815cd68b5a625b17246eebb17
Author: Niels Thykier <niels@thykier.net>
Date:   Sat Oct 22 10:13:45 2016 +0000

    L::Path: Support recursive-mode for children method
    
    Signed-off-by: Niels Thykier <niels@thykier.net>
---
 lib/Lintian/Path.pm | 37 ++++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/lib/Lintian/Path.pm b/lib/Lintian/Path.pm
index c5da68c..657a82b 100644
--- a/lib/Lintian/Path.pm
+++ b/lib/Lintian/Path.pm
@@ -293,18 +293,49 @@ sub operm {
     return $self->{'_path_info'} & OPERM_MASK;
 }
 
-=item children
+=item children([RECURSIVE_MODE])
 
 Returns a list of children (as Lintian::Path objects) of this entry.
 The list and its contents should not be modified.
 
+The optional RECURSIVE_MODE parameter can be used to control if and
+how descendants of this directory is selected.  The following values
+are supported:
+
+=over 4
+
+=item direct
+
+This is the default and only returns direct children of this
+directory.  The entries are sorted by name.
+
+=item breadth-first
+
+Recursive into subdirectories and return the descendants in
+breadth-first order.  Children of a given directory will be sorted by
+name.
+
+=back
+
 NB: Returns the empty list for non-dir entries.
 
 =cut
 
 sub children {
-    my ($self) = @_;
-    return @{$self->{'_sorted_children'} };
+    my ($self, $recursive) = @_;
+    return @{$self->{'_sorted_children'} }
+      if not defined($recursive)
+      or $recursive eq 'direct';
+    croak("Unsupported recursive mode ${recursive}")
+      if $recursive ne 'breadth-first';
+    my @all = @{$self->{'_sorted_children'} };
+    my @remaining_dirs = grep { $_->is_dir } @all;
+    while (my $dir = shift(@remaining_dirs)) {
+        my @children = $dir->children;
+        push(@all, @children);
+        push(@remaining_dirs, grep { $_->is_dir } @children);
+    }
+    return @all;
 }
 
 =item timestamp

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git


Reply to: