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

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