Anonymous avatar Anonymous committed 1a89848

Bug fix: made sure ->item_obj() is properly synced to the callback.

Comments (0)

Files changed (3)

+    - Bug fix: made sure ->item_obj() is available on the first call
+    to the callback() and is properly synchronized with it.
+
 0.1.3 - Wed Nov 12 18:50:49 IST 2008
     - Refactoring: converted _movenext() from pseudo-conditionals
     to polymorphism by making it a method of ->_current().

lib/File/Find/Object.pm

     while (1) {
         if ($self->_process_current())
         {
-            return $self->_calc_current_item_obj();
+            return $self->item_obj();
         }
         if(!$self->_master_move_to_next) {
             if ($self->_me_die())
             {
+                $self->item_obj(undef());
                 return undef();
             }
         }
 sub next_obj {
     my $self = shift;
 
-    my $obj = $self->_calc_next_obj();
-
-    return $self->item_obj($obj);
+    return $self->_calc_next_obj();
 }
 
 sub next {
 sub _handle_callback {
     my $self = shift;
 
+    # Calculate next_obj now so it will be ready for the callback.
+    $self->item_obj($self->_calc_current_item_obj());
+
     if ($self->callback()) {
         $self->callback()->($self->_current_path());
     }
 use strict;
 use warnings;
 
-use Test::More tests => 39;
+use Test::More tests => 42;
 
 BEGIN
 {
 
     rmtree($t->get_path("./t/sample-data/traverse-1"));
 }
+
+{
+    my $tree =
+    {
+        'name' => "traverse-1/",
+        'subs' =>
+        [
+            {
+                'name' => "b.doc",
+                'contents' => "This file was spotted in the wild.",
+            },            
+            {
+                'name' => "a/",
+            },
+            {
+                'name' => "foo/",
+                'subs' =>
+                [
+                    {
+                        'name' => "yet/",
+                    },
+                ],
+            },
+        ],
+    };
+
+    my $t = File::Find::Object::TreeCreate->new();
+    $t->create_tree("./t/sample-data/", $tree);
+
+    my $ff;
+    my $callback = sub {
+        my $path = shift;
+
+        my $path_obj = $ff->item_obj();
+
+        # TEST
+        ok ($path_obj, "Path object is defined.");
+
+        # TEST
+        is_deeply($path_obj->full_components(),
+            [],
+            "Path empty."
+        );
+
+        # TEST
+        ok ($path_obj->is_dir(), "Path object is a directory");
+    };
+
+    $ff = 
+        File::Find::Object->new(
+            {callback => $callback},
+            $t->get_path("./t/sample-data/traverse-1")
+        );
+
+    my @results;
+
+    # Call $ff->next() and do the tests in $callback .
+    push @results, $ff->next();
+
+    rmtree($t->get_path("./t/sample-data/traverse-1"));
+}
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.