Commits

shl...@6f433eb9-a002-0410-945b-ee5462c261ee  committed 5f7424c

Added stat_ret() + Refactoring.

  • Participants
  • Parent commits ccc5e68

Comments (0)

Files changed (4)

     - Unified the two calls to stat() (and several calls to other file
     operators) in order to reduce the number of system calls/disk accesses
     issued by File::Find::Object.
+    - Refactored the code from the last change and added
+    File::Find::Object::Result->stat_ret() for the return value of stat().
 
 0.1.4 - Thu Dec 25 18:27:48 IST 2008
     - Bug fix: made sure ->item_obj() is available on the first call

File lib/File/Find/Object.pm

 
     my $components = $self->_current_components_copy();
     my $base = shift(@$components);
-    
+    my $stat = $self->_top_stat_copy();
+
     my @basename = ();
     my $path = $self->_current_path();
-    my $is_dir = -d $path;
-    if (! $is_dir)
+
+    if (! S_ISDIR($stat->[2]))
     {
         @basename = (basename => pop(@$components));
     }
         {
             @basename,
             path => $path,
-            is_dir => $is_dir,
             dir_components => $components,
             base => $base,
+            stat_ret => $stat,
         }
     );
 }
     {
         @actions = reverse(@actions);
     }
-    return @actions;
+    return ("_mystat", @actions);
+}
+
+sub _mystat {
+    my $self = shift;
+
+    $self->_top_stat([stat($self->_current_path())]);
+
+    return "SKIP";
 }
 
 sub _get_real_action
     # If current is not a directory always return 0, because we may
     # be asked to traverse single-files.
 
-    $self->_top_stat([stat($self->_current_path())]);
-
     if ($self->_is_top()) {
         # Assign to _stat_ret as well, so the _stat_ret field of the top
         # item will be set.    

File lib/File/Find/Object/Base.pm

 {
     my $self = shift;
 
-    $self->_actions([0,1]);
+    $self->_actions([0,1,2]);
 }
 
 sub _dir_as_string

File lib/File/Find/Object/Result.pm

 
 use base 'Class::Accessor';
 
+use Fcntl qw(:mode);
+
 __PACKAGE__->mk_accessors(qw(
     base
     basename
     path
     dir_components
-    is_dir
+    stat_ret
 ));
 
+sub is_dir
+{
+    return S_ISDIR(shift->stat_ret->[2]);
+}
+
 sub full_components
 {
     my $self = shift;
 Returns the full components of the result with the basename if it is
 a file.
 
+=head2 $result->stat_ret()
+
+The return value of L<perlfunc/stat> for the result, placed
+inside an array reference. This is calculated by L<File::Find::Object> and 
+kept here for convenience and for internal use.
+
 =head1 SEE ALSO
 
 L<File::Find::Object>