Anonymous avatar Anonymous committed c7bd2d0

Converted ->dir() and ->_current_path() to a component-based storage.

Comments (0)

Files changed (2)

lib/File/Find/Object.pm

     my $self = {};
     bless $self, $class;
 
-    $self->dir($top->_current_path());
+    $self->_dir($top->_current_components_copy());
     $self->idx($index);
 
     $self->_last_dir_scanned(undef);
 
-    $from->dir($self->dir());
+    $from->_dir($self->_dir_copy());
 
     $self->_reset_actions();
 
 __PACKAGE__->_top_it([qw(
     _check_subdir_helper
     _current
-    _current_path
+    _current_components
     _me_die 
     )]
 );
 #sub DESTROY {
 #    my ($self) = @_;
 #    print STDERR join(" ", caller)."\n";
-#    printf STDERR "destroy `%s'\n", $self->dir() || "--";
+#    printf STDERR "destroy `%s'\n", $self->_dir_as_string || "--";
 #}
 
+sub _current_components_copy
+{
+    my $self = shift;
+
+    return [ @{$self->_current_components()} ];
+}
+
 sub _top__current
 {
     my $self = shift;
     return ($self->_current_idx() < 0);
 }
 
+sub _NEW_current_path
+{
+    my $self = shift;
+
+    return File::Spec->catfile(@{$self->_current_components_copy()});
+}
+
 sub next {
     my ($self) = @_;
     while (1) {
         if ($self->_process_current())
         {
-            return $self->item($self->_current_path());
+            return $self->item($self->_NEW_current_path());
         }
         if(!$self->_movenext) {
             if ($self->_me_die())
     my $self = shift;
 
     if ($self->callback()) {
-        $self->callback()->($self->_current_path());
+        $self->callback()->($self->_NEW_current_path());
     }
 
     return 1;
     my $self = shift;
 
     return defined($self->filter()) ?
-        $self->filter()->($self->_current_path()) :
+        $self->filter()->($self->_NEW_current_path()) :
         1;
 }
 
 
     # If current is not a directory always return 0, because we may
     # be asked to traverse single-files.
-    my @st = stat($self->_current_path());
+    my @st = stat($self->_NEW_current_path());
     if (!-d _)
     {
         return 0;
 
     my $current = $self->_current();
 
-    if (-l $self->_current_path() && !$self->followlink())
+    if (-l $self->_NEW_current_path() && !$self->followlink())
     {
         return 0;
     }
         $ptr = $self->_father($ptr);
     }
     if ($rc) {
-        printf(STDERR "Avoid loop " . $self->_father($ptr)->dir() . " => %s\n",
-            $self->_current_path());
+        printf(STDERR "Avoid loop " . $self->_father($ptr)->_dir_as_string . " => %s\n",
+            $self->_NEW_current_path());
         return 0;
     }
     return 1;
 }
 
-sub _top__current_path {
+sub _top__current_components {
     my $self = shift; 
 
-    return $self->_current->_curr_file;
+    return [$self->_current->_curr_file];
 }
 
-sub _non_top__current_path
+sub _non_top__current_components
 {
     my $self = shift;
 
-    return File::Spec->catfile(
-        $self->_current_father->dir(),
-        $self->_current->_curr_file
-    );
+    return [
+        @{$self->_current_father->_dir_copy()},
+        $self->_current->_curr_file()
+    ];
 }
 
 sub _open_dir {
     my $current = $self->_current();
 
     if (defined($current->_last_dir_scanned()) &&
-        ($current->_last_dir_scanned() eq $current->dir()
+        ($current->_last_dir_scanned() eq $current->_dir_as_string()
        )
     )
     {
         return $current->_open_dir_ret();
     }
 
-    $current->_last_dir_scanned($current->dir());
+    $current->_last_dir_scanned($current->_dir_as_string());
 
     my $handle;
     my @files;
-    if (!opendir($handle, $current->dir()))
+    if (!opendir($handle, $current->_dir_as_string()))
     {
         # Handle this error gracefully.        
     }
         [ @files ]
     );
     
-    my @st = stat($current->dir());
+    my @st = stat($current->_dir_as_string());
     $current->inode($st[1]);
     $current->dev($st[0]);
 
 {
     my $self = shift;
 
-    $self->_current->dir($self->_current_path());
+    $self->_current->_dir($self->_current_components_copy());
 
     # _open_dir can return undef if $self->_current is not a directory.
     if ($self->_open_dir())
 =head1 SYNOPSIS
 
     use File::Find::Object;
-    my $tree = File::Find::Object->new({}, @dir);
+    my $tree = File::Find::Object->new({}, @targets);
 
     while (my $r = $tree->next()) {
         print $r ."\n";

lib/File/Find/Object/Base.pm

 
 use base 'Class::Accessor';
 
+use File::Spec;
+
 __PACKAGE__->mk_accessors(qw(
     _actions
     _curr_file
     dev
-    dir
+    _dir
     _files
     idx
     inode
     $self->_actions([0,1]);
 }
 
+sub _dir_copy
+{
+    my $self = shift;
+
+    return [ @{$self->_dir()} ];
+}
+
+sub _dir_as_string
+{
+    my $self = shift;
+
+    return File::Spec->catdir(@{$self->_dir()});
+}
+
 1;
 
 =head1 NAME
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.