Commits

Anonymous committed c28ac3e

Converted all the options into accessors.

Comments (0)

Files changed (1)

lib/File/Find/Object.pm

     _dir_stack
 ));
 
+sub _get_options_ids
+{
+    my $class = shift;
+    return [qw(
+        callback
+        depth
+        filter
+        followlink
+        nocrossfs
+    )];
+}
+
+__PACKAGE__->mk_accessors(@{__PACKAGE__->_get_options_ids()});
+
 use Carp;
 
 our $VERSION = '0.0.4';
 
 sub new {
     my ($class, $options, @files) = @_;
+
     my $tree = {
         files => [ @files ],
         ind => -1,
         
-        depth => $options->{depth},
-        nocrossfs => $options->{nocrossfs},
-        followlink => $options->{followlink},
-        filter => $options->{filter},
-        callback => $options->{callback},
         _dir_stack => [],
     };
+
     bless($tree, $class);
 
+    foreach my $opt (@{$tree->_get_options_ids()})
+    {
+        $tree->set($opt, $options->{$opt});
+    }
+
     return $tree;
 }
 
     $current->_curr_file() or return 0;
 
     $self->isdot($current) and return 0;
-    $self->filter($current) or return 0;  
+    $self->_filter_wrapper($current) or return 0;  
 
-    foreach ($self->{depth} ? qw/b a/ : qw/a b/) {
+    foreach ($self->depth() ? qw/b a/ : qw/a b/) {
         if ($current->_action->{$_}) {
             next;
         }
         $current->_action->{$_} = 1;
         if($_ eq 'a') {
-            if ($self->{callback}) {
-                $self->{callback}->($self->current_path($current));
+            if ($self->callback()) {
+                $self->callback()->($self->current_path($current));
             }
             return 1;
         }
     return ($file eq ".." || $file eq ".");
 }
 
-sub filter {
+sub _filter_wrapper {
     my ($self, $current) = @_;
-    return defined($self->{filter}) ?
-        $self->{filter}->($self->current_path($current)) :
+    return defined($self->filter()) ?
+        $self->filter()->($self->current_path($current)) :
         1;
 }
 
     {
         return 0;
     }
-    if (-l $self->current_path($current) && !$self->{followlink})
+    if (-l $self->current_path($current) && !$self->followlink())
     {
         return 0;
     }
-    if ($st[0] != $self->_father($current)->dev() && $self->{nocrossfs})
+    if ($st[0] != $self->_father($current)->dev() && $self->nocrossfs())
     {
         return 0;
     }
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.