File Coverage

bin/tidyall
Criterion Covered Total %
statement 76 94 80.8
branch 19 38 50.0
condition 7 22 31.8
subroutine 12 12 100.0
pod n/a
total 114 166 68.6


line stmt bran cond sub pod time code
1             #!perl
2 8     8   69028 use Capture::Tiny qw(capture_merged);
  8         391634  
  8         664  
3 8     8   5257 use Code::TidyAll;
  8         49  
  8         441  
4 8     8   77 use Config;
  8         17  
  8         483  
5 8     8   69 use Path::Tiny qw(cwd path);
  8         14  
  8         648  
6 8     8   49 use Module::Runtime qw( use_module );
  8         16  
  8         74  
7 8     8   8143 use Getopt::Long;
  8         132491  
  8         50  
8 8     8   2027 use strict;
  8         19  
  8         251  
9 8     8   43 use warnings;
  8         15  
  8         1390354  
10              
11 8         4172975 our $VERSION = '0.85';
12              
13 8         32 my $usage = <<'EOF';
14             Usage: tidyall [options] [file] ...
15             See https://metacpan.org/module/tidyall for full documentation.
16              
17             Options:
18             -a, --all Process all files in project
19             -i, --ignore Ignore matching files (zglob syntax)
20             -g, --git Process all added/modified files according to git
21             -l, --list List each file along with the plugins it matches
22             -m, --mode Mode (e.g. "editor", "commit") - affects which plugins run
23             -p <path>, --pipe <path> Read from STDIN, output to STDOUT/STDERR
24             -r, --recursive Descend recursively into directories listed on command line
25             -j, --jobs Number of parallel jobs to run - default is 1
26             -s, --svn Process all added/modified files according to svn
27             -q, --quiet Suppress output except for errors
28             -v, --verbose Show extra output
29             -I I<path1,path2,...> Add one or more paths to @INC
30             --backup-ttl <duration> Amount of time before backup files can be purged
31             --check-only Just check each file, don't modify
32             --plugins <name> Explicitly run only the given plugins
33             --conf-file <path> Relative or absolute path to conf file
34             --conf-name <name> Conf file name to search for
35             --data-dir <path> Contains metadata, defaults to root/.tidyall.d
36             --iterations <count> Number of times to repeat each transform - default is 1
37             --no-backups Don't back up files before processing
38             --no-cache Don't cache last processed times
39             --no-cleanup Don't clean up the temporary files
40             --output-suffix <suffix> Suffix to add to tidied file
41             --refresh-cache Erase any existing cache info before processing each file
42             --root-dir Specify root directory explicitly
43             --tidyall-class <class> Subclass to use instead of Code::TidyAll
44             --version Show version
45             -h, --help Print help message
46             EOF
47              
48             sub version {
49 1   50 1   5 my $version = $Code::TidyAll::VERSION || 'unknown';
50 1         27 print "tidyall $version on perl $] built for $Config{archname}\n";
51 1         88 exit;
52             }
53              
54             sub usage {
55 1     1   13 print $usage;
56 1         95 exit;
57             }
58              
59             my (
60 8         45 %params,
61             $all_files,
62             $git_files,
63             $pipe,
64             $svn_files,
65             $conf_file,
66             $conf_name,
67             $iterations,
68             $inc_dirs,
69             $version,
70             $help,
71             );
72              
73 8         130 my @conf_names = Code::TidyAll->default_conf_names;
74              
75 8         74 Getopt::Long::Configure('no_ignore_case');
76             GetOptions(
77             'a|all' => \$all_files,
78             'i|ignore=s@' => \$params{ignore},
79             'g|git' => \$git_files,
80             'l|list' => \$params{list_only},
81             'm|mode=s' => \$params{mode},
82             'p|pipe=s' => \$pipe,
83             'r|recursive' => \$params{recursive},
84             'j|jobs=i' => \$params{jobs},
85             's|svn' => \$svn_files,
86             'q|quiet' => \$params{quiet},
87             'v|verbose' => \$params{verbose},
88             'I=s' => \$inc_dirs,
89             'backup-ttl=i' => \$params{backup_ttl},
90             'check-only' => \$params{check_only},
91             'plugins=s@' => \$params{selected_plugins},
92             'conf-file=s' => \$conf_file,
93             'conf-name=s' => \$conf_name,
94             'data-dir=s' => \$params{data_dir},
95             'iterations=i' => \$iterations,
96             'no-backups' => \$params{no_backups},
97             'no-cache' => \$params{no_cache},
98             'no-cleanup' => \$params{no_cleanup},
99             'output-suffix=s' => \$params{output_suffix},
100             'refresh-cache' => \$params{refresh_cache},
101             'root-dir=s' => \$params{root_dir},
102             'tidyall-class=s' => \$params{tidyall_class},
103 8 50       739 'version' => \$version,
104             'h|help' => \$help,
105             ) or usage();
106 8 100       23021 version() if $version;
107 7 100       32 usage() if $help;
108 6 50       22 @conf_names = ($conf_name) if defined($conf_name);
109              
110 6 50       25 unshift( @INC, split( /\s*,\s*/, $inc_dirs ) ) if defined($inc_dirs);
111              
112 6         42 %params = map { $_ => $params{$_} } grep { defined( $params{$_} ) } keys %params;
  2         10  
  108         185  
113 6         25 for my $key (qw( data_dir root_dir )) {
114 12 50       40 $params{$key} = path( $params{$key} ) if exists $params{$key};
115             }
116 6 50       22 $params{iterations} = $iterations if $iterations;
117              
118 0         0 ($conf_file) = ( grep { $_->is_file } map { $params{root_dir}->child($_) } @conf_names )
  0         0  
119 6 50 33     37 if $params{root_dir} && !$conf_file;
120              
121 6   50     51 my $tidyall_class = $params{tidyall_class} || 'Code::TidyAll';
122              
123 6         64 use_module($tidyall_class);
124              
125 6         309 my ( $ct, @paths );
126              
127 6 100 33     45 if ($pipe) {
    50 33        
    50          
128 4         34 my $status = handle_pipe( path($pipe) );
129 4         410 exit($status);
130             }
131             elsif ( ( $all_files || $svn_files || $git_files ) ) {
132 0 0       0 die 'cannot use filename(s) with -a/--all, -s/--svn, or -g/--git'
133             if @ARGV;
134 0   0     0 $conf_file ||= $tidyall_class->find_conf_file( \@conf_names, cwd() );
135 0         0 $ct = $tidyall_class->new_from_conf_file( $conf_file, %params );
136              
137 0 0       0 if ($all_files) {
    0          
    0          
138 0         0 @paths = $ct->find_matched_files;
139             }
140             elsif ($svn_files) {
141 0         0 require Code::TidyAll::SVN::Util;
142 0         0 @paths = Code::TidyAll::SVN::Util::svn_uncommitted_files( $ct->root_dir );
143             }
144             elsif ($git_files) {
145 0         0 require Code::TidyAll::Git::Util;
146 0         0 @paths = Code::TidyAll::Git::Util::git_modified_files( $ct->root_dir );
147             }
148             }
149 2         14 elsif ( @paths = map { path($_) } @ARGV ) {
150 2   33     143 $conf_file ||= $tidyall_class->find_conf_file( \@conf_names, $paths[0]->parent );
151 2         18 $ct = $tidyall_class->new_from_conf_file( $conf_file, %params );
152             }
153             else {
154 0         0 print "must pass -a/--all, -s/--svn, -g/--git, -p/--pipe, or filename(s)\n";
155 0         0 usage();
156             }
157              
158 2         14 my @results = $ct->process_paths(@paths);
159 2 50       179 my $status = ( grep { $_->error } @results ) ? 1 : 0;
  2         21  
160 2         386 exit($status);
161              
162             sub handle_pipe {
163 4     4   298 my ($pipe_filename) = @_;
164              
165 4         49 $params{$_} = 1 for ( 'no_backups', 'no_cache', 'quiet' );
166 4         17 $params{$_} = 0 for ('verbose');
167              
168 4   33     51 $conf_file ||= $tidyall_class->find_conf_file( \@conf_names, $pipe_filename->parent );
169 4         41 my $ct = $tidyall_class->new_from_conf_file( $conf_file, %params );
170 4         19 my $source = do { local $/; <STDIN> };
  4         23  
  4         241  
171              
172             # Merge stdout and stderr and output all to stderr, so that stdout is
173             # dedicated to the tidied content
174             #
175 4         15 my $result;
176             my $output = capture_merged {
177 4     4   9876 $result = $ct->process_source( $source, $ct->_small_path( $pipe_filename->absolute ) );
178 4         188 };
179 4         24141 print STDERR $output;
180              
181 4 100       66 if ( my $error = $result->error ) {
    50          
    50          
182 2         8 print $source; # Error already printed above
183 2         170 return 1;
184             }
185             elsif ( $result->state eq 'no_match' ) {
186 0         0 print $source;
187 0         0 print STDERR "No plugins apply for '$pipe' in config";
188 0         0 return 1;
189             }
190             elsif ( $result->state eq 'checked' ) {
191 0         0 print $source;
192 0         0 return 0;
193             }
194             else {
195 2         22 print $result->new_contents;
196 2         165 return 0;
197             }
198             }
199              
200             1;
201              
202             __END__
203              
204             =head1 NAME
205              
206             tidyall - Your all-in-one code tidier and validator
207              
208             =head1 SYNOPSIS
209              
210             # Create a tidyall.ini or .tidyallrc at the top of your project
211             #
212             [PerlTidy]
213             select = **/*.{pl,pm,t}
214             argv = -noll -it=2
215              
216             [PerlCritic]
217             select = lib/**/*.pm
218             ignore = lib/UtterHack.pm
219             argv = -severity 3
220              
221             # Process all files in the current project,
222             # look upwards from cwd for conf file
223             #
224             % tidyall -a
225              
226             # Process one or more specific files,
227             # look upwards from the first file for conf file
228             #
229             % tidyall file [file...]
230              
231             # Process a directory recursively
232             #
233             % tidyall -r dir
234              
235             =head1 DESCRIPTION
236              
237             There are a lot of great code tidiers and validators out there. C<tidyall>
238             makes them available from a single unified interface.
239              
240             You can run C<tidyall> on a single file or on an entire project hierarchy, and
241             configure which tidiers/validators are applied to which files. C<tidyall> will
242             back up files beforehand, and for efficiency will only consider files that have
243             changed since they were last processed.
244              
245             =head2 What's a tidier? What's a validator?
246              
247             A I<tidier> transforms a file so as to improve its appearance without changing
248             its semantics. Examples include L<perltidy>, L<podtidy> and
249             L<js-beautify|https://npmjs.org/package/js-beautify>.
250              
251             A I<validator> analyzes a file for some definition of correctness. Examples
252             include L<perlcritic>, L<podchecker> and L<jshint|http://www.jshint.com/>.
253              
254             Many tidiers are also validators, e.g. C<perltidy> will throw an error on badly
255             formed Perl.
256              
257             To use a tidier or validator with C<tidyall> it must have a corresponding
258             plugin class, usually under the prefix C<Code::TidyAll::Plugin::>. This
259             distribution comes with plugins for:
260              
261             =over
262              
263             =item *
264              
265             Perl: L<perlcritic|Code::TidyAll::Plugin::PerlCritic>,
266             L<perltidy|Code::TidyAll::Plugin::PerlTidy>,
267             L<perltidy-sweet|Code::TidyAll::Plugin::PerlTidySweet>
268              
269             =item *
270              
271             Pod: L<podchecker|Code::TidyAll::Plugin::PodChecker>,
272             L<podspell|Code::TidyAll::Plugin::PodSpell>,
273             L<podtidy|Code::TidyAll::Plugin::PodTidy>
274              
275             =item *
276              
277             Mason: L<masontidy|Code::TidyAll::Plugin::MasonTidy>
278              
279             =item *
280              
281             JavaScript: L<js-beautify|Code::TidyAll::Plugin::JSBeautify>,
282             L<jshint|Code::TidyAll::Plugin::JSHint>,
283             L<jslint|Code::TidyAll::Plugin::JSLint>
284              
285             =item *
286              
287             JSON: L<JSON|Code::TidyAll::Plugin::JSON>
288              
289             =item *
290              
291             CSS: L<cssunminifier|Code::TidyAll::Plugin::CSSUnminifier>
292              
293             =item *
294              
295             PHP: L<phpcs|Code::TidyAll::Plugin::PHPCodeSniffer>
296              
297             =item *
298              
299             Misc: L<Code::TidyAll::Plugin::SortLines>
300              
301             =back
302              
303             See L<Code::TidyAll::Plugin> for information about creating your own plugin.
304              
305             =head1 USING TIDYALL
306              
307             C<tidyall> works on a project basis, where a project is just a directory
308             hierarchy of files. svn or git working directories are typical examples of
309             projects.
310              
311             The top of the project is called the I<root directory>. In the root directory
312             you'll need a config file named C<tidyall.ini> or C<.tidyallrc>; it defines how
313             various tidiers and validators will be applied to the files in your project.
314              
315             C<tidyall> will find your root directory and config file automatically
316             depending on how you call it:
317              
318             =over
319              
320             =item C<< tidyall file [file...] >>
321              
322             C<tidyall> will search upwards from the first file for the conf file.
323              
324             =item C<< tidyall -p/--pipe file >>
325              
326             C<tidyall> will search upwards from the specified file for the conf file.
327              
328             =item C<< tidyall -a/--all >> or C<< tidyall -s/--svn >> or C<< tidyall -g/--git >>
329              
330             C<tidyall> will search upwards from the current working directory for the conf
331             file.
332              
333             =item C<< tidyall -a --root-dir dir >>
334              
335             C<tidyall> will expect to find the conf file in the specified root directory.
336              
337             =back
338              
339             You can also pass --conf-name to change the name that is searched for, or
340             --conf-file to specify an explicit path.
341              
342             =head1 CONFIGURATION
343              
344             The config file (C<tidyall.ini> or C<.tidyallrc>) is in L<Config::INI> format.
345             Here's a sample:
346              
347             ignore = **/*.bak
348              
349             [PerlTidy]
350             select = **/*.{pl,pm,t}
351             argv = -noll -it=2
352              
353             [PerlCritic]
354             select = lib/**/*.pm
355             ignore = lib/UtterHack.pm lib/OneTime/*.pm
356             argv = -severity 3
357              
358             [PodTidy]
359             select = lib/**/*.{pm,pod}
360              
361             In order, the four sections declare:
362              
363             =over
364              
365             =item *
366              
367             Always ignore C<*.bak> files.
368              
369             =item *
370              
371             Apply C<PerlTidy> with settings "-noll -it=2" to all *.pl, *.pm, and *.t files.
372              
373             =item *
374              
375             Apply C<PerlCritic> with severity 3 to all Perl modules somewhere underneath
376             "lib/", except for "lib/UtterHack.pm".
377              
378             =item *
379              
380             Apply C<PodTidy> with default settings to all *.pm and *.pod files underneath
381             "lib/".
382              
383             =back
384              
385             =head2 Standard configuration elements
386              
387             =over
388              
389             =item [class] or [class description]
390              
391             The header of each section refers to a tidyall I<plugin>. The name is
392             automatically prefixed with C<Code::TidyAll::Plugin::> unless it begins with a
393             '+', e.g.
394              
395             ; Uses plugin Code::TidyAll::Plugin::PerlTidy
396             ;
397             [PerlTidy]
398              
399             ; Uses plugin My::TidyAll::Plugin
400             ;
401             [+My::TidyAll::Plugin]
402              
403             You can also include an optional description after the class. The description
404             will be ignored and only the first word will be used for the plugin. This
405             allows you to a list a plugin more than once, with different configuration each
406             time. For example, two different C<PerlCritic> configurations:
407              
408             ; Be brutal on libraries
409             ;
410             [PerlCritic strict]
411             select = lib/**/*.pm
412             argv = --brutal
413              
414             ; but gentle on scripts
415             ;
416             [PerlCritic lenient]
417             select = bin/**/*.pl
418             argv = --gentle
419              
420             Warning: If you simply list the same plugin twice with no description (or the
421             same description), one of them will be silently ignored.
422              
423             =item select
424              
425             One or more L<File::Zglob> patterns, separated by whitespace or on multiple
426             lines, indicating which files to select. At least one is required. e.g.
427              
428             ; All .t and .pl somewhere under bin and t;
429             ; plus all .pm files directly under lib/Foo and lib/Bar
430             ;
431             select = {bin,t}/**/*.p[lm]
432             select = lib/{Foo,Bar}/*.pm
433              
434             ; All .txt files anywhere in the project
435             ;
436             select = **/*.txt
437              
438             The pattern is relative to the root directory and should have no leading slash.
439             All standard glob characters (C<*>, C<?>, C<[]>, C<{}>) will work; in addition,
440             C<**> can be used to represent zero or more directories. See L<File::Zglob>
441             documentation for more details.
442              
443             =item ignore
444              
445             One or more L<File::Zglob> patterns, separated by whitespace or on multiple
446             lines, indicating which files to ignore. This is optional and overrides
447             C<select>. e.g.
448              
449             ; All .pl files anywhere under bin, except bin/awful.pl or anywhere
450             ; under bin/tmp
451             ;
452             select = bin/**/*.pl
453             ignore = bin/awful.pl bin/tmp/**/*.pl
454              
455             Ignore patterns can also specified at the beginning of the file before any
456             plugin section was started, thus making them global. These ignores will be
457             applied for all plugins.
458              
459             =item shebang
460              
461             One or more words on multiple lines, indicating which shebang lines to accept.
462             This is optional and further filters C<select>. e.g.
463              
464             ; All files with no extension anywhere under bin that include a "perl" or
465             ; "perl5" shebang line.
466             select = bin/**/*
467             ignore = bin/**/*.*
468             shebang = perl
469             shebang = perl5
470              
471             =item only_modes
472              
473             A list of modes, separated by whitespace. e.g.
474              
475             only_modes = test cli
476              
477             The plugin will I<only> run if one of these modes is passed to C<tidyall> via
478             C<-m> or C<--mode>.
479              
480             =item except_modes
481              
482             A list of modes, separated by whitespace. e.g.
483              
484             except_modes = commit editor
485              
486             The plugin will I<not> run if one of these modes is passed to C<tidyall> via
487             C<-m> or C<--mode>.
488              
489             =item argv
490              
491             Many plugins (such as L<perltidy|Code::TidyAll::Plugin::PerlTidy>,
492             L<perlcritic|Code::TidyAll::Plugin::PerlCritic> and
493             L<podtidy|Code::TidyAll::Plugin::PodTidy>) take this option, which specifies
494             arguments to pass to the underlying command-line utility.
495              
496             =item weight
497              
498             This is an integer that is used to sort plugins. By default, tidier plugins run
499             first, then validator plugins, with each group sorted alphabetically.
500              
501             =back
502              
503             =head1 PLUGIN ORDER AND ATOMICITY
504              
505             If multiple plugins match a file, tidiers are applied before validators so that
506             validators are checking the final result. Within those two groups, the plugins
507             are applied in alphabetical order by plugin name/description.
508              
509             You can also explicitly set the weight of each plugin. By default, tidiers have
510             a weight of 50 and validators have a weight of 60. You can set the weight to
511             any integer to influence when the plugin runs.
512              
513             The application of multiple plugins is all-or-nothing. If an error occurs
514             during the application of any plugin, the file is not modified at all.
515              
516             =head1 COMMAND-LINE OPTIONS
517              
518             =over
519              
520             =item -a, --all
521              
522             Process all files. Does a recursive search for all files in the project
523             hierarchy, starting at the root, and processes any file that matches at least
524             one plugin in the configuration.
525              
526             =item -i, --ignore
527              
528             Ignore matching files. This uses zglob syntax. You can pass this option more
529             than once.
530              
531             =item -g, --git
532              
533             Process all added or modified files in the current git working directory.
534              
535             =item -l, --list
536              
537             List each file along with the list of plugins it matches (files without any
538             matches are skipped). Does not actually process any files and does not care
539             whether files are cached. Generally used with -a, -g, or -s. e.g.
540              
541             % tidyall -a -l
542             lib/CHI.pm (PerlCritic, PerlTidy, PodTidy)
543             lib/CHI/Benchmarks.pod (PodTidy)
544             lib/CHI/CacheObject.pm (PerlCritic, PerlTidy, PodTidy)
545              
546             =item -m, --mode
547              
548             Optional mode that can affect which plugins run. Defaults to C<cli>. See
549             L</MODES>.
550              
551             =item -p path, --pipe path
552              
553             Read content from STDIN and write the resulting content to STDOUT. If
554             successful, tidyall exits with status 0. If an error occurs, tidyall outputs
555             the error message to STDERR, I<mirrors the input content> to STDOUT with no
556             changes, and exits with status 1. The mirroring means that you can safely pipe
557             to your destination regardless of whether an error occurs.
558              
559             When specifying this option you must specify exactly one filename, relative or
560             absolute, which will be used to determine which plugins to apply and also where
561             the root directory and configuration file are. The file will not actually be
562             read and does need even need to exist.
563              
564             This option implies --no-backups and --no-cache (since there's no actual file)
565             and --quiet (since we don't want to mix extraneous output with the tidied
566             result).
567              
568             # Read from STDIN and write to STDOUT, with appropriate plugins
569             # for some/path.pl (which need not exist)
570             #
571             % tidyall --pipe some/path.pl
572              
573             =item -r, --recursive
574              
575             Recursively enter any directories listed on the command-line and process all
576             the files within. By default, directories encountered on the command-line will
577             generate a warning.
578              
579             =item -j, --jobs
580              
581             Specify how many jobs should run in parallel. By default, we only run 1, but if
582             you have multiple cores this should cause tidyall to run faster, especially on
583             larger code bases.
584              
585             =item -s, --svn
586              
587             Process all added or modified files in the current svn working directory.
588              
589             =item -q, --quiet
590              
591             Suppress output except for errors.
592              
593             =item -v, --verbose
594              
595             Show extra output.
596              
597             =item -I I<path1,path2,...>
598              
599             Add one or more library paths to @INC, like Perl's -I. Useful if
600             --tidyall-class or plugins are in an alternate lib directory.
601              
602             =item --backup-ttl I<duration>
603              
604             Amount of time before backup files can be purged. Can be a number of seconds or
605             any string recognized by L<Time::Duration::Parse>, e.g. "4h" or "1day".
606             Defaults to "1h".
607              
608             =item --check-only
609              
610             Instead of actually tidying files, check if each file is tidied (i.e. if its
611             tidied version is equal to its current version) and consider it an error if
612             not. This is used by L<Test::Code::TidyAll> and the
613             L<svn|Code::TidyAll::SVN::Precommit> and L<git|Code::TidyAll::Git::Precommit>
614             pre-commit hooks, for example, to enforce that you've tidied your files.
615              
616             =item --plugins I<name>
617              
618             Only run the specified plugins. The name should match the name given in the
619             config file exactly, including a leading "+" if one exists.
620              
621             This overrides the C<--mode> option.
622              
623             Note that plugins will still only run on files which match their C<select> and
624             C<ignore> configuration.
625              
626             =item --conf-file I<path>
627              
628             Specify relative or absolute path to conf file, instead of searching for it in
629             the usual way.
630              
631             =item --conf-name I<name>
632              
633             Specify a conf file name to search for instead of the defaults (C<tidyall.ini>
634             / C<.tidyallrc>).
635              
636             =item --data-dir I<path>
637              
638             Contains data like backups and cache. Defaults to root_dir/.tidyall.d
639              
640             =item --iterations I<count>
641              
642             Run each tidier transform I<count> times. Default is 1.
643              
644             In some cases (hopefully rare) the output from a tidier can be different if it
645             is applied multiple times. You may want to perform multiple iterations to make
646             sure the content "settles" into its final tidied form -- especially if the
647             tidiness is being enforced with a version-control hook or a test. Of course,
648             performance will suffer a little. You should rarely need to set this higher
649             than 2.
650              
651             This only affects tidiers, not validators; e.g.
652             L<perlcritic|Code::TidyAll::Plugin::PerlCritic> and
653             L<jshint|Code::TidyAll::Plugin::JSHint> would still only be run once.
654              
655             =item --no-backups
656              
657             Don't backup files before processing.
658              
659             =item --no-cache
660              
661             Don't cache last processed times; process all files every time. See also
662             C<--refresh-cache>.
663              
664             =item --no-cleanup
665              
666             Don't clean up temporary files.
667              
668             =item --output-suffix I<suffix>
669              
670             Suffix to add to a filename before outputting the modified version, e.g.
671             C<.tdy>. Default is none, which means overwrite the file.
672              
673             =item --refresh-cache
674              
675             Erase any existing cache info before processing each file, then write new cache
676             info. See also C<--no-cache>.
677              
678             =item --root-dir
679              
680             Specify root directory explicitly. Usually this is inferred from the specified
681             files or the current working directory.
682              
683             =item --tidyall-class I<class>
684              
685             Subclass to use instead of C<Code::TidyAll>.
686              
687             =item --version
688              
689             Show the version of L<Code::TidyAll> that this script invokes.
690              
691             =item -h, --help
692              
693             Print help message
694              
695             =back
696              
697             =head2 Specifying options in configuration
698              
699             Almost any command-line option can be specified at the top of the config file,
700             above the plugin sections. Replace dashes with underscores. e.g.
701              
702             backup_ttl = 4h
703             iterations = 2
704             tidyall_class = My::Code::TidyAll
705              
706             [PerlTidy]
707             select = **/*.{pl,pm,t}
708             argv = -noll -it=2
709              
710             ...
711              
712             If an option is passed in both places, the command-line takes precedence.
713              
714             =head3 inc
715              
716             You can specify C<inc> as a global configuration option outside of any plugin's
717             section. You can specify this more than once to include multiple directories.
718             Any directories you list here will be I<prepended> to C<@INC> before loading
719             plugins or a C<tidyall_class>
720              
721             =head1 EXIT STATUS
722              
723             C<tidyall> will exit with status 1 if any errors occurred while processing
724             files, and 0 otherwise.
725              
726             =head1 MODES
727              
728             You can use tidyall in a number of different contexts, and you may not want to
729             run all plugins in all of them.
730              
731             You can pass a mode to tidyall via C<-m> or C<--mode>, and then specify that
732             certain plugins should only be run in certain modes (via L</only_modes>) or
733             should be run in all but certain modes (via L</except_modes>).
734              
735             Examples of modes:
736              
737             =over
738              
739             =item *
740              
741             C<cli> - when invoking tidyall explicitly from the command-line with no mode
742             specified
743              
744             =item *
745              
746             C<editor> - when invoking from an editor
747              
748             =item *
749              
750             C<commit> - when using a commit hook like L<Code::TidyAll::SVN::Precommit> or
751             L<Code::TidyAll::Git::Precommit>
752              
753             =item *
754              
755             C<test> - when using L<Test::Code::TidyAll>
756              
757             =back
758              
759             Now since L<perlcritic|Code::TidyAll::Plugin::PerlCritic> is a bit
760             time-consuming, you might only want to run it during tests and explicit
761             command-line invocation:
762              
763             [PerlCritic]
764             select = lib/**/*.pm
765             only_modes = test cli
766             ...
767              
768             Or you could specify that it be run in all modes I<except> the editor:
769              
770             [PerlCritic]
771             select = lib/**/*.pm
772             except_modes = editor
773             ...
774              
775             If you specify neither C<only_modes> nor C<except_modes> for a plugin, then it
776             will always run.
777              
778             =head1 LAST-PROCESSED CACHE
779              
780             C<tidyall> keeps track of each file's signature after it was last processed. On
781             subsequent runs, it will only process a file if its signature has changed. The
782             cache is kept in files under the data dir.
783              
784             You can force a refresh of the cache with C<--refresh-cache>, or turn off the
785             behavior entirely with C<--no-cache>.
786              
787             =head1 BACKUPS
788              
789             C<tidyall> will backup each file before modifying it. The timestamped backups
790             are kept in a separate directory hierarchy under the data dir.
791              
792             Old backup files will be purged automatically as part of occasional C<tidyall>
793             runs. The duration specified in C<--backup-ttl> indicates both the minimum
794             amount of time backups should be kept, and the frequency that purges should be
795             run. It may be specified as "30m" or "4 hours" or any string acceptable to
796             L<Time::Duration::Parse>. It defaults to "1h" (1 hour).
797              
798             You can turn off backups with C<--no-backups>.
799              
800             =head1 "MISSING" PREREQS
801              
802             The C<Code::TidyAll> distribution intentionally does not depend on the prereqs
803             needed for each plugin. This means that if you want to use the
804             L<perltidy|Code::TidyAll::Plugin::PerlTidy>, you must install the L<Perl::Tidy>
805             module manually.
806              
807             =head1 RELATED TOOLS
808              
809             =over
810              
811             =item *
812              
813             L<etc/editors/tidyall.el|https://raw.github.com/autarch-code/perl-code-tidyall/master/etc/editors/tidyall.el>
814             and
815             L<etc/editors/tidyall.vim|https://raw.github.com/autarch-code/perl-code-tidyall/master/etc/editors/tidyall.vim>
816             in this distribution contains Emacs and Vim commands for running C<tidyall> on
817             the current buffer. You can assign this to the keystroke of your choice (e.g.
818             ctrl-t or ,t).
819              
820             =item *
821              
822             L<Code::TidyAll::SVN::Precommit> implements a subversion pre-commit hook that
823             checks if all files are tidied and valid according to C<tidyall>, and rejects
824             the commit if not.
825              
826             =item *
827              
828             L<Code::TidyAll::Git::Precommit> and L<Code::TidyAll::Git::Prereceive>
829             implement git pre-commit and pre-receive hooks, respectively, that check if all
830             files are tidied and valid according to C<tidyall>.
831              
832             =item *
833              
834             L<Test::Code::TidyAll> is a testing library to check that all the files in your
835             project are in a tidied and valid state.
836              
837             =back
838              
839             =head1 KNOWN BUGS
840              
841             =over
842              
843             =item *
844              
845             Does not yet work on Windows
846              
847             =back
848              
849             =head1 AUTHOR
850              
851             Jonathan Swartz
852              
853             =head1 ACKNOWLEDGMENTS
854              
855             Thanks to Jeff Thalhammer for helping me refine this API. Thanks to Jeff for
856             perlcritic, Steve Hancock for perltidy, and all the other authors of great open
857             source tidiers and validators.
858              
859             =cut