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

[lintian] 02/05: L::Path: Add parent_dir and root_dir methods



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

nthykier pushed a commit to branch master
in repository lintian.

commit 64fe9bb0f7af57e2a755cc854a25c8a3cc127461
Author: Niels Thykier <niels@thykier.net>
Date:   Tue Sep 23 21:21:03 2014 +0200

    L::Path: Add parent_dir and root_dir methods
    
    Signed-off-by: Niels Thykier <niels@thykier.net>
---
 lib/Lintian/Path.pm | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/lib/Lintian/Path.pm b/lib/Lintian/Path.pm
index 1aafa46..26c5ad1 100644
--- a/lib/Lintian/Path.pm
+++ b/lib/Lintian/Path.pm
@@ -89,6 +89,11 @@ sub new {
     if ($self->is_file or $self->is_dir) {
         $self->{'_is_open_ok'} = $self->is_file;
         $self->{'_valid_path'} = 1;
+        if ($self->is_dir) {
+            for my $child ($self->children) {
+                $child->_set_parent_dir($self);
+            }
+        }
     }
     return $self;
 }
@@ -162,6 +167,13 @@ NB: This is only well defined for file entries that are subject to
 permissions (e.g. files).  Particularly, the value is not well defined
 for symlinks.
 
+=item parent_dir
+
+Returns the parent directory entry of this entry as a
+L<Lintian::Path>.
+
+NB: Returns C<undef> for the "root" dir.
+
 =item dirname
 
 Returns the "directory" part of the name, similar to dirname(1) or
@@ -183,7 +195,7 @@ NB: Returns the empty string for the "root" dir.
 
 Lintian::Path->mk_ro_accessors(
     qw(name owner group link type uid gid
-      size date operm dirname basename
+      size date operm parent_dir dirname basename
       ));
 
 =item children
@@ -460,6 +472,27 @@ sub open_gz {
     return $self->_do_open(\&Lintian::Util::open_gz);
 }
 
+=item root_dir
+
+Return the root dir entry of this the path entry.
+
+=cut
+
+sub root_dir {
+    my ($self) = @_;
+    my $current = $self;
+    while (my $next = $current->parent_dir) {
+        $current = $next;
+    }
+    return $current;
+}
+
+sub _set_parent_dir {
+    my ($self, $parent) = @_;
+    weaken($self->{'parent_dir'} = $parent);
+    return 1;
+}
+
 ### OVERLOADED OVERATORS ###
 
 # overload apparently does not like the mk_ro_accessor, so use a level

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


Reply to: