Commits

Anonymous committed 452cfeb

Created the _make_copy_methods method generator to avoid the _copy pattern.

Comments (0)

Files changed (2)

lib/File/Find/Object.pm

     )]
 );
 
+__PACKAGE__->_make_copy_methods([qw(
+    _current_components
+    )]
+);
+
 use Carp;
 
 our $VERSION = '0.1.0';
 #    printf STDERR "destroy `%s'\n", $self->_dir_as_string || "--";
 #}
 
-sub _current_components_copy
-{
-    my $self = shift;
-
-    return [ @{$self->_current_components()} ];
-}
-
 sub _top__current
 {
     my $self = shift;

lib/File/Find/Object/Base.pm

     _traverse_to
 ));
 
+# Create a _copy method that does a flat copy of an array returned by
+# a method as a reference.
+
+sub _make_copy_methods
+{
+    my ($pkg, $methods) = @_;
+
+    no strict 'refs';
+    foreach my $method (@$methods)
+    {
+        *{$pkg."::".$method."_copy"} =
+            do {
+                my $m = $method;
+                sub {
+                    my $self = shift;
+                    return [ @{$self->$m(@_)} ];
+                };
+            };
+    }
+    return;
+}
+
+__PACKAGE__->_make_copy_methods([qw(
+        _dir
+    )]
+);
+
 sub _reset_actions
 {
     my $self = shift;
     $self->_actions([0,1]);
 }
 
-sub _dir_copy
-{
-    my $self = shift;
-
-    return [ @{$self->_dir()} ];
-}
-
 sub _dir_as_string
 {
     my $self = shift;
 sub _set_up_dir
 {
     my $self = shift;
-    my $files = shift;
+
+    my $files = $self->_calc_dir_files();
 
     $self->_files(
         [ @$files ]
         return $self->_open_dir_ret();
     }
 
-    return $self->_set_up_dir(
-        $self->_calc_dir_files(),
-    );
+    return $self->_set_up_dir();
 }
 
 1;