blib/lib/File/Find/Rule/VCS.pm

filter: Statementstmt 96.0% 49 / 51 Branchbran 88.4% 23 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 7 totaltotal 87.6% 85 / 97 CC 13 SCAR 19.9
CC
13
Cov
94%
ignore_vcs
13.2
BEGIN
1.0
BEGIN
1.0
CRAP 7.3
↑ Summary
1 package File::Find::Rule::VCS; # git description: b034768
2  
3 =pod
4  
5 =head1 NAME
6  
7 File::Find::Rule::VCS - Exclude files/directories for Version Control Systems
8  
9 =head1 SYNOPSIS
10  
11 use File::Find::Rule ();
12 use File::Find::Rule::VCS ();
13  
14 # Find all files smaller than 10k, ignoring version control files
15 my @files = File::Find::Rule->ignore_vcs
16 ->file
17 ->size('<10Ki')
18 ->in( $dir );
19  
20 =head1 DESCRIPTION
21  
22 Many tools need to be equally useful both on ordinary files, and on code
23 that has been checked out from revision control systems.
24  
25 B<File::Find::Rule::VCS> provides quick and convenient methods to
26 exclude the version control directories of several major Version
27 Control Systems (currently CVS, subversion, and Bazaar).
28  
29 B<File::Find::Rule::VCS> implements methods to ignore the following:
30  
31 =over 4
32  
33 =item B<CVS>
34  
35 =item B<Subversion>
36  
37 =item B<Bazaar>
38  
39 =back
40  
41 In addition, the following version control systems do not create
42 directories in the checkout and do not require the use of any
43 ignore methods
44  
45 =over 4
46  
47 =item B<SVK>
48  
49 =item B<Git>
50  
51 =back
52  
53 =head1 METHODS
54  
55 =cut
56  
57 2 ▶use 5.00503;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
60 2 ▶use Text::Glob 0.08 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
61 2 ▶use File::Find::Rule 0.20 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 2 our $VERSION = '1.09';
64 2 our @ISA = 'File::Find::Rule';
65 2 our @EXPORT = @File::Find::Rule::EXPORT;
66  
67 2 ▶use constant FFR => 'File::Find::Rule';
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 # In some Windows SVN implementations, it uses _svn instead of
70 # .svn, so use both on Win32.
71 2 ▶my @svn = ($^O eq 'MSWin32') ? ('.svn', '_svn') : ('.svn');
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 2 2
72  
73  
74  
75  
76  
77 #####################################################################
78 # File::Find::Rule Method Addition
79  
80 =pod
81  
82 =head2 ignore_vcs
83  
84 # Ignore all common version control systems
85 $find->ignore_vcs;
86  
87 # Ignore a specific named version control systems
88 $find->ignore_vcs($name);
89  
90 # Ignore nothing (silent pass-through)
91 $find->ignore_vcs('');
92  
93 The C<ignore_vcs> method excludes the files for a named Version Control
94 System from your L<File::Find::Rule> search.
95  
96 If passed, the name of the version control system is case in-sensitive.
97 Names currently supported are 'cvs', 'svn', 'subversion', 'bzr', and
98 'bazaar'.
99  
100 As a convenience for high-level APIs, if the VCS name is the defined
101 null string B<''> then the call will be treated as a nullop.
102  
103 If no params at all are passed, this method will ignore all supported
104 version control systems. If ignoring every version control system,
105 please note that any legitimate directories called "CVS" or files
106 starting with .# will be ignored, which is not always desirable.
107  
108 In widely-distributed code, you instead should try to detect the specific
109 version control system used and call ignore_vcs with the specific name.
110  
111 Passing C<undef>, or an unsupported name, will throw an exception.
112  
113 =cut
114  
115 11 ▶sub File::Find::Rule::ignore_vcs {
Subroutine ignore_vcs: called CC=13 SCAR=25.8
Pod undocumented
116 11 my $find = $_[0]->_force_object;
117  
118 # Handle special cases
119 11 ▶ if( 1 == scalar( @_ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (1 == scalar @_) 1 10 11
120 # Logically combine all the ignores. This will be much
121 # faster than just calling them all one after the other.
122 1 return $find->or(
123 FFR->name(@svn, '.bzr', '.git', '.hg', 'CVS', 'RCS')
124 ->directory->prune->discard,
125 FFR->name(qr/^\.\#/, qr/,v$/)->file->discard,
126 FFR->new,
127 );
128 }
129 10 ▶ unless ( defined $_[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[1]) 0 10 10
130 0 Carp::croak("->ignore_vcs: No version control system name provided");
131 }
132  
133 # As a convenience for higher-level APIs
134 # we treat a defined null string as a nullop
135 10 my $vcs = lc $_[1];
136 10 ▶ return $find if $vcs eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $vcs eq "" 1 9 10
137  
138 # Hand off to the rules for each VCS
139 9 ▶ return $find->ignore_cvs if $vcs eq 'cvs';
Branch: 1 branch
BranchTrueFalseTotal
if $vcs eq "cvs" 1 8 9
140 8 ▶ return $find->ignore_rcs if $vcs eq 'rcs';
Branch: 1 branch
BranchTrueFalseTotal
if $vcs eq "rcs" 1 7 8
141 7 ▶ return $find->ignore_svn if $vcs eq 'svn';
Branch: 1 branch
BranchTrueFalseTotal
if $vcs eq "svn" 1 6 7
142 6 ▶ return $find->ignore_svn if $vcs eq 'subversion';
Branch: 1 branch
BranchTrueFalseTotal
if $vcs eq "subversion" 1 5 6
143 5 ▶ return $find->ignore_bzr if $vcs eq 'bzr';
Branch: 1 branch
BranchTrueFalseTotal
if $vcs eq "bzr" 1 4 5
144 4 ▶ return $find->ignore_bzr if $vcs eq 'bazaar';
Branch: 1 branch
BranchTrueFalseTotal
if $vcs eq "bazaar" 1 3 4
145 3 ▶ return $find->ignore_git if $vcs eq 'git';
Branch: 1 branch
BranchTrueFalseTotal
if $vcs eq "git" 1 2 3
146 2 ▶ return $find->ignore_hg if $vcs eq 'hg';
Branch: 1 branch
BranchTrueFalseTotal
if $vcs eq "hg" 1 1 2
147 1 ▶ return $find->ignore_hg if $vcs eq 'mercurial';
Branch: 1 branch
BranchTrueFalseTotal
if $vcs eq "mercurial" 1 0 1
148 0 Carp::croak("->ignore_vcs: '$vcs' is not supported");
149 }
150  
151 =pod
152  
153 =head2 ignore_cvs
154  
155 The C<ignore_cvs> method excluding all CVS directories from your
156 L<File::Find::Rule> search.
157  
158 It will also exclude all the files left around by CVS after an
159 automated merge that start with C<'.#'> (dot-hash).
160  
161 =cut
162  
163 2 ▶sub File::Find::Rule::ignore_cvs {
Subroutine ignore_cvs: called CC=1 SCAR=0.0
Pod undocumented
164 2 my $find = $_[0]->_force_object;
165 2 return $find->or(
166 FFR->name('CVS')->directory->prune->discard,
167 FFR->name(qr/^\.\#/)->file->discard,
168 FFR->new,
169 );
170 }
171  
172 =pod
173  
174 =head2 ignore_rcs
175  
176 The C<ignore_rcs> method excluding all RCS directories from your
177 L<File::Find::Rule> search.
178  
179 It will also exclude all the files used by RCS to store the revisions
180 (end with C<',v'>).
181  
182 =cut
183  
184 2 ▶sub File::Find::Rule::ignore_rcs {
Subroutine ignore_rcs: called CC=1 SCAR=0.0
Pod undocumented
185 2 my $find = $_[0]->_force_object;
186 2 return $find->or(
187 FFR->name('RCS')->directory->prune->discard,
188 FFR->name(qr/,v$/)->file->discard,
189 FFR->new,
190 );
191 }
192  
193 =pod
194  
195 =head2 ignore_svn
196  
197 The C<ignore_svn> method excluding all Subversion (C<.svn>) directories
198 from your L<File::Find::Rule> search.
199  
200 =cut
201  
202 3 ▶sub File::Find::Rule::ignore_svn {
Subroutine ignore_svn: called CC=1 SCAR=0.0
Pod undocumented
203 3 my $find = $_[0]->_force_object;
204 3 return $find->or(
205 FFR->name(@svn)->directory->prune->discard,
206 FFR->new,
207 );
208 }
209  
210 =pod
211  
212 =head2 ignore_bzr
213  
214 The C<ignore_bzr> method excluding all Bazaar (C<.bzr>) directories
215 from your L<File::Find::Rule> search.
216  
217 =cut
218  
219 3 ▶sub File::Find::Rule::ignore_bzr {
Subroutine ignore_bzr: called CC=1 SCAR=0.0
Pod undocumented
220 3 my $find = $_[0]->_force_object;
221 3 return $find->or(
222 FFR->name('.bzr')->directory->prune->discard,
223 FFR->new,
224 );
225 }
226  
227 =pod
228  
229 =head2 ignore_git
230  
231 The C<ignore_git> method excluding all Git (C<.git>) directories
232 from your L<File::Find::Rule> search.
233  
234 =cut
235  
236 2 ▶sub File::Find::Rule::ignore_git {
Subroutine ignore_git: called CC=1 SCAR=0.0
Pod undocumented
237 2 my $find = $_[0]->_force_object;
238 2 return $find->or(
239 FFR->name('.git')->directory->prune->discard,
240 FFR->new,
241 );
242 }
243  
244 =pod
245  
246 =head2 ignore_hg
247  
248 The C<ignore_hg> method excluding all Mercurial/Hg (C<.hg>) directories
249 from your L<File::Find::Rule> search.
250  
251 =cut
252  
253 2 ▶sub File::Find::Rule::ignore_hg {
Subroutine ignore_hg: called CC=1 SCAR=0.0
Pod undocumented
254 2 my $find = $_[0]->_force_object;
255 2 return $find->or(
256 FFR->name('.hg')->directory->prune->discard,
257 FFR->new,
258 );
259 }
260  
261 2 1;
262  
263 =pod
264  
265 =head1 TO DO
266  
267 - Add support for other version control systems.
268  
269 - Add other useful VCS-related methods
270  
271 =head1 SUPPORT
272  
273 Bugs should always be submitted via the CPAN bug tracker
274  
275 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Find-Rule-VCS>
276  
277 For other issues, contact the maintainer
278  
279 =head1 AUTHOR
280  
281 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
282  
283 =head1 SEE ALSO
284  
285 L<http://ali.as/>, L<File::Find::Rule>
286  
287 =head1 COPYRIGHT
288  
289 Copyright 2005 - 2010 Adam Kennedy.
290  
291 This program is free software; you can redistribute
292 it and/or modify it under the same terms as Perl itself.
293  
294 The full text of the license can be found in the
295 LICENSE file included with this module.
296  
297 =cut
↑ Summary