Commits

Anonymous committed b119566

- Now running canonpath() on the targets in the call to
File::Find::Object->new. That way, trailing slashes are omitted in
the results.

Comments (0)

Files changed (4)

+    - Now running canonpath() on the targets in the call to 
+    File::Find::Object->new. That way, trailing slashes are omitted in
+    the results.
+
 0.0.8 - Tue Jul 31 16:23:34 IDT 2007
     - added the empty PL_FILES key to the Makefile.PL to avoid running 
     Build.PL on older versions of EU::MM.
 t/03traverse.t
 t/04destroy.t
 t/05prune.t
+t/06trailing-slash.t
 t/lib/File/Find/Object/TreeCreate.pm
+t/pod-coverage.t
+t/pod.t
 t/sample-data/h.txt
-t/pod.t
-t/pod-coverage.t

lib/File/Find/Object.pm

     );
 }
 
+sub _calc_next_target
+{
+    my $self = shift;
+
+    my $target = $self->_targets()->[$self->_target_index()];
+
+    return defined($target) ? File::Spec->canonpath($target) : undef;
+}
+
+sub _move_to_next_target
+{
+    my $self = shift; 
+
+    $self->_curr_file($self->_calc_next_target());
+}
+
 sub _movenext_wo_current
 {
     my $self = shift;
     }
     $self->_increment_target_index();
 
-    $self->_curr_file($self->_targets()->[$self->_target_index()]);
+    $self->_move_to_next_target();
+
     $self->_action({});
     1;
 }
 with an iterator. As File::Find is not object oriented, one cannot perform
 multiple searches in the same application. The second problem of File::Find 
 is its file processing: after starting its main loop, one cannot easilly wait 
-for another event an so get the next result.
+for another event and so get the next result.
 
 With File::Find::Object you can get the next file by calling the next() 
 function, but setting a callback is still possible.

t/06trailing-slash.t

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+
+BEGIN
+{
+    use File::Spec;
+    use lib File::Spec->catdir(File::Spec->curdir(), "t", "lib");
+}
+
+use File::Find::Object;
+
+use File::Path;
+
+{
+    my $ff = 
+        File::Find::Object->new(
+            {},
+            "t/",
+        );
+
+    my @results;
+    push @results, $ff->next();
+
+    # TEST
+    is_deeply(\@results, ["t"],
+        "t has no trailing slash"
+    );
+}