Anonymous avatar Anonymous committed 86d2b37

- remove nonet
- add doc

Comments (0)

Files changed (3)

-# $Id: Object.pm,v 1.1 2005/06/18 18:21:35 nanardon Exp $
+# $Id: Object.pm,v 1.2 2005/06/18 20:35:38 nanardon Exp $
 
 #- Olivier Thauvin <olivier.thauvin@aerov.jussieu.fr>
 
         depth => $options->{depth},
         nocrossfs => $options->{nocrossfs},
         followlink => $options->{followlink},
-        nonet => $options->{nonet},
         filter => $options->{filter},
         callback => $options->{callback},
     };
     my ($self) = @_;
     while (1) {
         my $current = $self->{_current} || $self;
-        $current->_process_current and return $current->current_path;
+        $current->_process_current and return $self->{item} = $current->current_path;
         $current = $self->{_current} || $self;
         if(!$current->movenext) {
-            $current->me_die and return undef;
+            $current->me_die and return $self->{item} = undef;
         }
     }
 }
 
+sub item {
+    my ($self) = @_;
+    $self->{item}
+}
+
 sub movenext {
     my ($self) = @_;
     $self->{ind} > @{$self->{files}} and return;
 }
 
 1
+
+__END__
+
+=head1 NAME
+
+File::Find::Object - A File::Find object oriented
+
+=head1 SYNOPSIS
+
+    use File::Find::Object;
+    my $tree = File::Find::Object->new({}, @dir);
+
+    while (my $r = $tree->next()) {
+        print $r ."\n";
+    }
+
+=head1 DESCRIPTION
+
+File::Find::Object does same job the File::Find but instead this one, works
+like an object and with an iterator. As File::Find is not object oriented you
+can't perform multiple search in same application. The second problem of
+File::Find is its file processing, after starting its main loop, you can't
+easilly wait another event an so get next result.
+
+With File::Find::Object you get next file by calling next() functions, but
+setting a callback is still possible.
+
+=head1 FUNCTIONS
+
+=head2 new
+
+    my $ffo = File::Find::Object->new( { options }, @files);
+
+Create a new File::Find::Object object. @files is the list of directory
+- or files - the object should explore.
+
+=head3 options
+
+=over 4
+
+=item depth
+
+Boolean, return the directory content before the directory itself
+
+=item nocrossfs
+
+Boolean, don't continue on filesystem different than the parent
+
+=item followlink
+
+Boolean, follow symlink when they point to a directory.
+
+You can safelly set this options, File::Find::Object does not follow the link
+if detect a loop.
+
+=item filter
+
+Function, should point to a function returning TRUE or FALSE. This function is
+call with the filename to filter, if the function return FALSE, the file is
+skiped.
+
+=item callback
+
+Function, should point to a function calle each time a new file is return. The
+function is called with the current filename as argument.
+
+=back
+
+=head2 next
+
+Return the next file find by the File::Find::Object, it return undef at end.
+
+=head2 item
+
+Return the current filename found by the File::Find::Object object, aka the
+latest value return by next().
+
+=head1 BUGS
+
+Currently works only on UNIX as it use '/' as separator.
+
+=head1 SEE ALSO
+
+L<File::Find>
+
+=cut
+

Object/internal.pm

-# $Id: internal.pm,v 1.1 2005/06/18 18:22:49 nanardon Exp $
+# $Id: internal.pm,v 1.2 2005/06/18 20:35:38 nanardon Exp $
 
 #- Olivier Thauvin <olivier.thauvin@aerov.jussieu.fr>
 
     my @st = stat($self->current_path());
     !-d _ and return 0;
     -l $self->current_path() && !$self->{_top}->{followlink} and return 0;
-    $st[0] < 0 && $self->{_top}->{nonet} and return 0;
     $st[0] != $self->{dev} && $self->{_top}->{nocrossfs} and return 0;
     my $ptr = $self; my $rc;
     while($ptr->{_father}) {
 #!/usr/bin/perl
 
-# $Id: tree,v 1.1 2005/06/18 18:21:35 nanardon Exp $
+# $Id: tree,v 1.2 2005/06/18 20:35:38 nanardon Exp $
 
 use strict;
 use warnings;
 use File::Find::Object;
+use Getopt::Long;
 
-my $tree = File::Find::Object->new({}, @ARGV);
+my %options;
+
+GetOptions(
+    'd' => \$options{depth},
+    'n' => \$options{nonet},
+    'f' => \$options{nocrossfs},
+    'l' => \$options{followlink},
+);
+
+my $tree = File::Find::Object->new({ %options }, @ARGV);
 
 while (my $r = $tree->next()) {
     print $r ."\n";
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.