Skip Menu |

This queue is for tickets about the File-Find-Rule CPAN distribution.

Report information
The Basics
Id: 23830
Status: new
Priority: 0/
Queue: File-Find-Rule

People
Owner: Nobody in particular
Requestors: wilco [...] nakedape.cc
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.30
Fixed in: (no value)



Subject: Adding 'clone' method
I've recently had the task of writing some scripts to cleanup directories used for various file exchange tasks and I found File::Find::Rule greatly simplified the implementation. I found that most of my 20-odd rules (and boy, some were odd!) were derived from 3 or 4 simpler rules. I used 'clone' (from http://search.cpan.org/~rdf/Clone-0.22/) to clone the initial objects and this worked well. What concerns me, however, is using an external method that does all sorts of rude things to the insides of my File::Find::Rule objects and, most importantly, the maintainability and being able to count on this working forevermore. So, I would like to request that you implement a 'clone' method, that is an included and supported feature of your module. (You could simply use Clone.pm and make it thin wrapper around it.) In fact, here's a patch that does a basic implementation and a test; I tried to make it have no effect if the user doesn't have 'Clone', to not introduce extra dependencies. The test I added, however, will fail if Clone isn't there.
Subject: File-Find-Rule-0.30-cloner.diff
--- ./t/File-Find-Rule.t.orig 2006-06-01 08:39:18.000000000 -0700 +++ ./t/File-Find-Rule.t 2006-12-06 11:51:47.000000000 -0800 @@ -2,7 +2,7 @@ # $Id: /mirror/lab/perl/File-Find-Rule/t/File-Find-Rule.t 2100 2006-05-28T16:06:50.725367Z richardc $ use strict; -use Test::More tests => 41; +use Test::More tests => 42; my $class; my @tests = qw( t/File-Find-Rule.t t/findrule.t ); @@ -141,11 +141,14 @@ ->discard, $class->new->file ); +my $g = $f->clone(); + is_deeply( [ sort $f->in('t') ], [ @tests, 't/foobar', 't/lib/File/Find/Rule/Test/ATeam.pm' ], "prune/discard .svn" ); +is_deeply( $g, $f, 'clone of previous matches' ); # procedural form of the CVS demo $f = find(or => [ find( directory => --- ./lib/File/Find/Rule.pm.orig 2006-12-06 11:21:46.000000000 -0800 +++ ./lib/File/Find/Rule.pm 2006-12-06 11:51:00.000000000 -0800 @@ -6,7 +6,7 @@ use File::Spec; use Text::Glob 'glob_to_regex'; use Number::Compare; -use Carp qw/croak/; +use Carp qw/croak carp/; use File::Find (); # we're only wrapping for now use Cwd; # 5.00503s File::Find goes screwy with max_depth == 0 @@ -121,6 +121,27 @@ $object; } +=item C<clone> + +A cloner. Generates a new object from an existing one. If you want to +"inherit" more specific rules from a larger, more general rule, you can use +clone and apply the rules to the cloned copy. Use of this method requires +C<Clone.pm>. + +=cut + +eval 'use Clone;'; + +our @ISA; + +if ($@) { +# This might be a good idea, but spurious output breaks tests. +# carp "Warning: Unable to load Clone.pm. clone() method unavailable."; +} +else { + push @ISA, 'Clone'; +} + =back =head2 Matching Rules