Commits

Anonymous committed 0f9fbe8

Refactored _check_subdir_helper_d .

  • Participants
  • Parent commits de7794b

Comments (0)

Files changed (2)

         _non_top__check_subdir_helper
     - Optimization/Refactoring: made the _top_it method names saner,
     and removed an unused one.
+    - Refactoring: refactored _check_subdir_helper_d() to make
+    the conditions clearer.
 
 0.1.7 - Thu Jan 15 16:09:49 IST 2009
     - Fixed the check-for-link and for directory semantics on Windows

File lib/File/Find/Object.pm

     return 1;
 }
 
-sub _find_ancestor_with_same_inode {
-    my $self = shift;
-
-    my $s = $self->_top_stat();
-    my $stack = $self->_dir_stack();
-
-    return List::Util::first { $_->_is_same_inode($s) } @{$stack}[0 .. $#$stack-1];
-}
 
 sub _warn_about_loop
 {
     return;
 }
 
+sub _is_loop {
+    my $self = shift;
+
+    my $s = $self->_top_stat();
+    my $stack = $self->_dir_stack();
+
+    if (defined(my $ptr = List::Util::first { $_->_is_same_inode($s) } @{$stack}[0 .. $#$stack-1])) {
+        $self->_warn_about_loop($ptr);
+        return 1;
+    }
+    else {
+        return;
+    }
+}
+
 sub _check_subdir_helper_d {
     my $self = shift;
 
-    if (!$self->followlink() && $self->_top_is_link())
-    {
-        return 0;
-    }
-
-    if ($self->nocrossfs() 
-        && $self->_top_stat->[0] != $self->_dev()
-    )
-    {
-        return 0;
-    }
-
-    if (my $ptr = $self->_find_ancestor_with_same_inode()) {
-        $self->_warn_about_loop($ptr);
-        return 0;
-    }
-
-    return 1;
+    return
+    !(
+        (!$self->followlink() && $self->_top_is_link())
+            ||
+        ($self->nocrossfs() && $self->_top_stat->[0] != $self->_dev())
+            ||
+        ($self->_is_loop())
+     )
+     ;
 }
 
 sub _open_dir {