Commits

Anonymous committed c5d892d

Converted "subs" (now _subs) to an accessor.

Comments (0)

Files changed (1)

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

 
 $VERSION = '0.0200';
 
+use Class::XSAccessor
+    accessors => {
+        "_subs" => "_subs",
+    }
+    ;
+
 # we'd just inherit from Exporter, but I want the colon
 sub import {
     my $pkg = shift;
         }
         if ($not) {
             $not = 0;
-            @args = $object->new->$method(@args);
+            @args = ref($object)->new->$method(@args);
             $method = "not";
         }
 
 =cut
 
 sub new {
+    # We need this to maintain compatibility with File-Find-Object.
+    # However, Randal Schwartz recommends against this practice in general:
+    # http://www.stonehenge.com/merlyn/UnixReview/col52.html
     my $referent = shift;
     my $class = ref $referent || $referent;
+
+    return 
     bless {
         rules    => [],  # [0]
-        subs     => [],  # [1]
+        _subs     => [],  # [1]
         iterator => [],
         extras   => {},
         maxdepth => undef,
 
 sub _force_object {
     my $object = shift;
-    $object = $object->new()
-      unless ref $object;
-    $object;
+    if (! ref($object))
+    {
+        $object = $object->new();
+    }
+    return $object;
 }
 
 =back
     push @{ $self->{rules} }, {
         rule => 'any',
         code => '(' . join( ' || ', map {
-            "( " . $_->_compile( $self->{subs} ) . " )"
+            "( " . $_->_compile($self->_subs()) . " )"
         } @_ ) . ")",
         args => \@_,
     };
         rule => 'not',
         args => \@rulesets,
         code => '(' . join ( ' && ', map {
-            "!(". $_->_compile( $self->{subs} ) . ")"
+            "!(". $_->_compile($self->_subs()) . ")"
         } @_ ) . ")",
     };
     $self;
     my $self = _force_object shift;
 
     my @found;
-    my $fragment = $self->_compile( $self->{subs} );
-    my @subs = @{ $self->{subs} };
+
+    my $fragment = $self->_compile($self->_subs());
+
+    my @subs = @{$self->_subs()};
 
     warn "relative mode handed multiple paths - that's a bit silly\n"
       if $self->{relative} && @_ > 1;
 
 sub _compile {
     my $self = shift;
-    my $subs = shift; # [1]
+    my $subs = shift;
 
     return '1' unless @{ $self->{rules} };
+
     my $code = join " && ", map {
         if (ref $_->{code}) {
             push @$subs, $_->{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.