Commits

Anonymous committed 57aa0ae

Now ::PathTop implements the top path instead of $top/$tree.

- Refactoring - made the top path component-handling object a separate
object (::PathTop) instead of $top/$tree . Hopefully, this will later
allow caching _current(), and having a unified directory stack.

  • Participants
  • Parent commits 7f1a678

Comments (0)

Files changed (2)

     was likely not to be evaluated, by re-arranging the order of _mystat
     call. Now _mystat is not an action, but rather called explicitly.
     _is_top() is now PODded-out because it's not used.
+    - Refactoring - made the top path component-handling object a separate
+    object (::PathTop) instead of $top/$tree . Hopefully, this will later 
+    allow caching _current(), and having a unified directory stack.
 
 0.1.5 - Sat Jan  3 17:17:31 IST 2009
     - Unified the two calls to stat() (and several calls to other file

File lib/File/Find/Object.pm

     }
 }
 
+package File::Find::Object::PathTop;
+
+use base 'File::Find::Object::Base';
+
+sub new {
+    my $class = shift;
+    my $top = shift;
+
+    my $self = {};
+    bless $self, $class;
+
+    $top->_fill_actions($self);
+    $self->idx(-1);
+
+    return $self;
+}
+
+
+sub _move_to_next_target
+{
+    my $self = shift;
+    my $top = shift;
+
+    my $target = $self->_curr_file($top->_calc_next_target());
+    @{$top->_curr_comps()} = ($target);
+    $top->_calc_curr_path();
+
+    return $target;
+}
+
+sub _move_next
+{
+    my $self = shift;
+    my $top = shift;
+
+    while ($top->_increment_target_index())
+    {
+        if (-e $self->_move_to_next_target($top))
+        {
+            $top->_fill_actions($self);
+            $top->_mystat();
+            $self->_stat_ret($top->_top_stat_copy());
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
 package File::Find::Object;
 
 use strict;
             _def_actions
             _dir_stack
             item_obj
+            _path_top
             _targets
             _target_index
             _top_stat
 
 our $VERSION = '0.1.5';
 
+sub _actions {
+    Carp::confess "_actions called.";
+}
+
 sub new {
     my ($class, $options, @targets) = @_;
 
     {
         $tree->$opt($options->{$opt});
     }
+
     $tree->_targets(\@targets);
     $tree->_target_index(-1);
 
     $tree->_calc_default_actions();
 
-    $tree->_fill_actions($tree);
+    $tree->_path_top(
+        File::Find::Object::PathTop->new($tree)
+    );
 
     $tree->_last_dir_scanned(undef);
 
 {
     my $self = shift;
 
-    return $self->_dir_stack->[-1] || $self;
+    return $self->_dir_stack->[-1] || $self->_path_top();
 }
 
 =begin Removed
 {
     my ($self, $level) = @_;
 
-    if (!defined($level->idx()))
+    # TODO : Unify.
+    if ($level->idx() < 0)
     {
         return undef;
     }
     }
     else
     {
-        return $self;
+        return $self->_path_top();
     }
 }
 
     return defined($target) ? File::Spec->canonpath($target) : undef;
 }
 
-sub _move_to_next_target
-{
-    my $self = shift; 
-
-    my $target = $self->_curr_file($self->_calc_next_target());
-    @{$self->_curr_comps()} = ($target);
-    $self->_calc_curr_path();
-
-    return $target;
-}
-
-sub _move_next
-{
-    my $self = shift;
-
-    while ($self->_increment_target_index())
-    {
-        if (-e $self->_move_to_next_target())
-        {
-            $self->_fill_actions($self);
-            $self->_mystat();
-            $self->_stat_ret($self->_top_stat_copy());
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
 sub _master_move_to_next {
     my $self = shift;
 
 
     my $st = $self->_dir_stack();
 
-    if ($self eq $father)
+    if ($father->idx < 0)
     {
         @$st = ();
         delete($self->{_st});