Anonymous avatar Anonymous committed b87e384

Converted ->{rules} to ->rules() with Class::XSAccessor.

Comments (0)

Files changed (1)

File-Find-Object-Rule/lib/File/Find/Object/Rule.pm

     accessors => {
         "finder" => "finder",
         "_match_cb" => "_match_cb",
+        "rules" => "rules",
         "_subs" => "_subs",
     }
     ;
 
 The L<File::Find::Object> finder instance itself.
 
+=head2 my @rules = @{$ffor->rules()};
+
+The rules to match against. For internal use only.
+
 =head2 Matching Rules
 
 =over
     return @flat;
 }
 
+sub _add_rule {
+    my $self = shift;
+    my $new_rule = shift;
+
+    push @{$self->rules()}, $new_rule;
+
+    return;
+}
+
 sub name {
     my $self = _force_object shift;
     my @names = map { ref $_ eq "Regexp" ? $_ : glob_to_regex $_ } _flatten( @_ );
 
-    push @{ $self->{rules} }, {
-        rule => 'name',
-        code => join( ' || ', map { "m($_)" } @names ),
-        args => \@_,
-    };
+    $self->_add_rule(
+        {
+            rule => 'name',
+            code => join( ' || ', map { "m($_)" } @names ),
+            args => \@_,
+        }
+    );
 
     $self;
 }
 for my $test (keys %X_tests) {
     my $sub = eval 'sub () {
         my $self = _force_object shift;
-        push @{ $self->{rules} }, {
+        $self->_add_rule({
             code => "' . $test . ' \$path",
             rule => "'.$X_tests{$test}.'",
-        };
+        });
         $self;
     } ';
     no strict 'refs';
 
             my @tests = map { Number::Compare->parse_to_perl($_) } @_;
 
-            push @{ $self->{rules} }, {
+            $self->_add_rule({
                 rule => $test,
                 args => \@_,
                 code => 'do { my $val = (stat $path)['.$index.'] || 0;'.
                   join ('||', map { "(\$val $_)" } @tests ).' }',
-            };
+            });
             $self;
         };
         no strict 'refs';
     my $self = _force_object shift;
     my @rulesets = @_;
 
-    push @{ $self->{rules} }, {
+    $self->_add_rule({
         rule => 'any',
         code => '(' . join( ' || ', map {
             "( " . $_->_compile($self->_subs()) . " )"
         } @_ ) . ")",
         args => \@_,
-    };
+    });
     $self;
 }
 
     my $self = _force_object shift;
     my @rulesets = @_;
 
-    push @{ $self->{rules} }, {
+    $self->_add_rule({
         rule => 'not',
         args => \@rulesets,
         code => '(' . join ( ' && ', map {
             "!(". $_->_compile($self->_subs()) . ")"
         } @_ ) . ")",
-    };
+    });
     $self;
 }
 
 sub prune () {
     my $self = _force_object shift;
 
-    push @{ $self->{rules} },
-      {
-       rule => 'prune',
-       code => 'do { $self->finder->prune(); 1 }'
-      };
-    $self;
+    $self->_add_rule(
+        {
+            rule => 'prune',
+            code => 'do { $self->finder->prune(); 1 }'
+        },
+    );
+
+    return $self;
 }
 
 =item C<discard>
 sub discard () {
     my $self = _force_object shift;
 
-    push @{ $self->{rules} }, {
+    $self->_add_rule({
         rule => 'discard',
         code => '$discarded = 1',
-    };
-    $self;
+    });
+
+    return $self;
 }
 
 =item C<exec( \&subroutine( $shortname, $path, $fullname ) )>
     my $self = _force_object shift;
     my $code = shift;
 
-    push @{ $self->{rules} }, {
-        rule => 'exec',
-        code => $code,
-    };
-    $self;
+    $self->_add_rule(
+        {
+            rule => 'exec',
+            code => $code,
+        }
+    );
+
+    return $self;
 }
 
 =item ->grep( @specifiers );
     my $self = shift;
     my $subs = shift;
 
-    return '1' unless @{ $self->{rules} };
+    return '1' unless @{ $self->rules() };
 
     my $code = join " && ", map {
         if (ref $_->{code}) {
         else {
             "( $_->{code} ) # $_->{rule}\n";
         }
-    } @{ $self->{rules} };
+    } @{ $self->rules() };
 
     return $code;
 }
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.