Commits

Anonymous committed a033486

Refactoring: converted the _action hash to an _actions array ref with 0,1

  • Participants
  • Parent commits 1c4aa45

Comments (0)

Files changed (2)

lib/File/Find/Object.pm

 
     $from->dir($self->dir());
 
+    $self->_reset_actions();
+
     return $top->_open_dir($top->_father($self)) ? $self : undef;
 }
 
     $tree->_targets([ @targets ]);
     $tree->_target_index(-1);
     $tree->_current_idx(-1);
+    $tree->_reset_actions();
 
     $tree->_last_dir_scanned(undef);
 
             shift(@{$self->_father($self->_current)->_traverse_to()})
        ))
     {
-        $self->_current->_action({});
+        $self->_current->_reset_actions();
         return 1;
     } else {
         return 0;
     {
         if (-e $self->_move_to_next_target())
         {
-            $self->_action({});
-
+            $self->_reset_actions();
             return 1;
         }
     }
     return $self->depth() ? qw(b a) : qw(a b);
 }
 
+sub _get_real_action
+{
+    my $self = shift;
+    my $action = shift;
+
+    return ($self->_calc_actions())[$action];
+}
+
 # Return true if there is somthing next
 sub _process_current {
     my $self = shift;
 
     $self->_filter_wrapper() or return 0;  
 
-    foreach my $action ($self->_calc_actions())
+    while (defined(my $action_proto = shift(@{$current->_actions()})))
     {
-        if ($current->_action->{$action}) {
-            next;
-        }
-        $current->_action->{$action} = 1;
+        my $action = $self->_get_real_action($action_proto);
+
         if($action eq 'a') {
             if ($self->callback()) {
                 $self->callback()->($self->_current_path($current));
         }
             
         if ($action eq 'b') {
-            my $status = $self->_recurse($current);
+            my $status = $self->_recurse();
             
             if ($status eq "SKIP")
             {
             }
         }
     }
+
     return 0;
 }
 
 sub _recurse
 {
-    my ($self, $current) = @_;
+    my $self = shift;
 
-    $self->_check_subdir($current) or 
+    $self->_check_subdir($self->_current()) or 
         return "SKIP";
 
-
     push @{$self->_dir_stack()}, 
         File::Find::Object::PathComponent->new(
             $self,
-            $current,
+            $self->_current(),
             scalar(@{$self->_dir_stack()})
         );
 

lib/File/Find/Object/Base.pm

 use base 'Class::Accessor';
 
 __PACKAGE__->mk_accessors(qw(
-    _action
+    _actions
     _curr_file
     dev
     dir
     _traverse_to
 ));
 
+sub _reset_actions
+{
+    my $self = shift;
+
+    $self->_actions([0,1]);
+}
+
 1;
 
 =head1 NAME