]> git.donarmstrong.com Git - perltidy.git/blob - bin/perltidy
fix up debian janitor merge commit to match actual pieces which were comitted
[perltidy.git] / bin / perltidy
1 #!/usr/bin/perl
2 package main;
3
4 use Perl::Tidy;
5
6 my $arg_string = undef;
7
8 # give Macs a chance to provide command line parameters
9 if ( $^O =~ /Mac/ ) {
10     $arg_string = MacPerl::Ask(
11         'Please enter @ARGV (-h for help)',
12         defined $ARGV[0] ? "\"$ARGV[0]\"" : ""
13     );
14 }
15
16 # Exit codes returned by perltidy:
17 #    0 = no errors
18 #    1 = perltidy could not run to completion due to errors
19 #    2 = perltidy ran to completion with error messages
20 exit Perl::Tidy::perltidy( argv => $arg_string );
21
22 __END__
23
24 =head1 NAME
25
26 perltidy - a perl script indenter and reformatter
27
28 =head1 SYNOPSIS
29
30     perltidy [ options ] file1 file2 file3 ...
31             (output goes to file1.tdy, file2.tdy, file3.tdy, ...)
32     perltidy [ options ] file1 -o outfile
33     perltidy [ options ] file1 -st >outfile
34     perltidy [ options ] <infile >outfile
35
36 =head1 DESCRIPTION
37
38 Perltidy reads a perl script and writes an indented, reformatted script.  The
39 formatting process involves converting the script into a string of tokens,
40 removing any non-essential whitespace, and then rewriting the string of tokens
41 with whitespace using whatever rules are specified, or defaults.  This happens
42 in a series of operations which can be controlled with the parameters described
43 in this document.
44
45 Perltidy is a commandline frontend to the module Perl::Tidy.  For documentation
46 describing how to call the Perl::Tidy module from other applications see the
47 separate documentation for Perl::Tidy.  It is the file Perl::Tidy.pod in the source distribution.
48
49 Many users will find enough information in L<"EXAMPLES"> to get
50 started.  New users may benefit from the short tutorial
51 which can be found at
52 http://perltidy.sourceforge.net/tutorial.html
53
54 A convenient aid to systematically defining a set of style parameters
55 can be found at
56 http://perltidy.sourceforge.net/stylekey.html
57
58 Perltidy can produce output on either of two modes, depending on the
59 existence of an B<-html> flag.  Without this flag, the output is passed
60 through a formatter.  The default formatting tries to follow the
61 recommendations in perlstyle(1), but it can be controlled in detail with
62 numerous input parameters, which are described in L<"FORMATTING OPTIONS">.
63
64 When the B<-html> flag is given, the output is passed through an HTML
65 formatter which is described in L<"HTML OPTIONS">.
66
67 =head1 EXAMPLES
68
69   perltidy somefile.pl
70
71 This will produce a file F<somefile.pl.tdy> containing the script reformatted
72 using the default options, which approximate the style suggested in
73 perlstyle(1).  The source file F<somefile.pl> is unchanged.
74
75   perltidy *.pl
76
77 Execute perltidy on all F<.pl> files in the current directory with the
78 default options.  The output will be in files with an appended F<.tdy>
79 extension.  For any file with an error, there will be a file with extension
80 F<.ERR>.
81
82   perltidy -b file1.pl file2.pl
83
84 Modify F<file1.pl> and F<file2.pl> in place, and backup the originals to
85 F<file1.pl.bak> and F<file2.pl.bak>.  If F<file1.pl.bak> and/or F<file2.pl.bak>
86 already exist, they will be overwritten.
87
88   perltidy -b -bext='/' file1.pl file2.pl
89
90 Same as the previous example except that the backup files F<file1.pl.bak> and F<file2.pl.bak> will be deleted if there are no errors.
91
92   perltidy -gnu somefile.pl
93
94 Execute perltidy on file F<somefile.pl> with a style which approximates the
95 GNU Coding Standards for C programs.  The output will be F<somefile.pl.tdy>.
96
97   perltidy -i=3 somefile.pl
98
99 Execute perltidy on file F<somefile.pl>, with 3 columns for each level of
100 indentation (B<-i=3>) instead of the default 4 columns.  There will not be any
101 tabs in the reformatted script, except for any which already exist in comments,
102 pod documents, quotes, and here documents.  Output will be F<somefile.pl.tdy>.
103
104   perltidy -i=3 -et=8 somefile.pl
105
106 Same as the previous example, except that leading whitespace will
107 be entabbed with one tab character per 8 spaces.
108
109   perltidy -ce -l=72 somefile.pl
110
111 Execute perltidy on file F<somefile.pl> with all defaults except use "cuddled
112 elses" (B<-ce>) and a maximum line length of 72 columns (B<-l=72>) instead of
113 the default 80 columns.
114
115   perltidy -g somefile.pl
116
117 Execute perltidy on file F<somefile.pl> and save a log file F<somefile.pl.LOG>
118 which shows the nesting of braces, parentheses, and square brackets at
119 the start of every line.
120
121   perltidy -html somefile.pl
122
123 This will produce a file F<somefile.pl.html> containing the script with
124 html markup.  The output file will contain an embedded style sheet in
125 the <HEAD> section which may be edited to change the appearance.
126
127   perltidy -html -css=mystyle.css somefile.pl
128
129 This will produce a file F<somefile.pl.html> containing the script with
130 html markup.  This output file will contain a link to a separate style
131 sheet file F<mystyle.css>.  If the file F<mystyle.css> does not exist,
132 it will be created.  If it exists, it will not be overwritten.
133
134   perltidy -html -pre somefile.pl
135
136 Write an html snippet with only the PRE section to F<somefile.pl.html>.
137 This is useful when code snippets are being formatted for inclusion in a
138 larger web page.  No style sheet will be written in this case.
139
140   perltidy -html -ss >mystyle.css
141
142 Write a style sheet to F<mystyle.css> and exit.
143
144   perltidy -html -frm mymodule.pm
145
146 Write html with a frame holding a table of contents and the source code.  The
147 output files will be F<mymodule.pm.html> (the frame), F<mymodule.pm.toc.html>
148 (the table of contents), and F<mymodule.pm.src.html> (the source code).
149
150 =head1 OPTIONS - OVERVIEW
151
152 The entire command line is scanned for options, and they are processed
153 before any files are processed.  As a result, it does not matter
154 whether flags are before or after any filenames.  However, the relative
155 order of parameters is important, with later parameters overriding the
156 values of earlier parameters.
157
158 For each parameter, there is a long name and a short name.  The short
159 names are convenient for keyboard input, while the long names are
160 self-documenting and therefore useful in scripts.  It is customary to
161 use two leading dashes for long names, but one may be used.
162
163 Most parameters which serve as on/off flags can be negated with a
164 leading "n" (for the short name) or a leading "no" or "no-" (for the
165 long name).  For example, the flag to outdent long quotes is B<-olq>
166 or B<--outdent-long-quotes>.  The flag to skip this is B<-nolq>
167 or B<--nooutdent-long-quotes> or B<--no-outdent-long-quotes>.
168
169 Options may not be bundled together.  In other words, options B<-q> and
170 B<-g> may NOT be entered as B<-qg>.
171
172 Option names may be terminated early as long as they are uniquely identified.
173 For example, instead of B<--dump-token-types>, it would be sufficient to enter
174 B<--dump-tok>, or even B<--dump-t>, to uniquely identify this command.
175
176 =head2 I/O Control
177
178 The following parameters concern the files which are read and written.
179
180 =over 4
181
182 =item B<-h>,    B<--help>
183
184 Show summary of usage and exit.
185
186 =item   B<-o>=filename,    B<--outfile>=filename
187
188 Name of the output file (only if a single input file is being
189 processed).  If no output file is specified, and output is not
190 redirected to the standard output (see B<-st>), the output will go to
191 F<filename.tdy>. [Note: - does not redirect to standard output. Use
192 B<-st> instead.]
193
194 =item   B<-st>,    B<--standard-output>
195
196 Perltidy must be able to operate on an arbitrarily large number of files
197 in a single run, with each output being directed to a different output
198 file.  Obviously this would conflict with outputting to the single
199 standard output device, so a special flag, B<-st>, is required to
200 request outputting to the standard output.  For example,
201
202   perltidy somefile.pl -st >somefile.new.pl
203
204 This option may only be used if there is just a single input file.
205 The default is B<-nst> or B<--nostandard-output>.
206
207 =item   B<-se>,    B<--standard-error-output>
208
209 If perltidy detects an error when processing file F<somefile.pl>, its
210 default behavior is to write error messages to file F<somefile.pl.ERR>.
211 Use B<-se> to cause all error messages to be sent to the standard error
212 output stream instead.  This directive may be negated with B<-nse>.
213 Thus, you may place B<-se> in a F<.perltidyrc> and override it when
214 desired with B<-nse> on the command line.
215
216 =item   B<-oext>=ext,    B<--output-file-extension>=ext
217
218 Change the extension of the output file to be F<ext> instead of the
219 default F<tdy> (or F<html> in case the -B<-html> option is used).
220 See L<"Specifying File Extensions">.
221
222 =item   B<-opath>=path,    B<--output-path>=path
223
224 When perltidy creates a filename for an output file, by default it merely
225 appends an extension to the path and basename of the input file.  This
226 parameter causes the path to be changed to F<path> instead.
227
228 The path should end in a valid path separator character, but perltidy will try
229 to add one if it is missing.
230
231 For example
232
233  perltidy somefile.pl -opath=/tmp/
234
235 will produce F</tmp/somefile.pl.tdy>.  Otherwise, F<somefile.pl.tdy> will
236 appear in whatever directory contains F<somefile.pl>.
237
238 If the path contains spaces, it should be placed in quotes.
239
240 This parameter will be ignored if output is being directed to standard output,
241 or if it is being specified explicitly with the B<-o=s> parameter.
242
243 =item   B<-b>,    B<--backup-and-modify-in-place>
244
245 Modify the input file or files in-place and save the original with the
246 extension F<.bak>.  Any existing F<.bak> file will be deleted.  See next
247 item for changing the default backup extension, and for eliminating the
248 backup file altogether.
249
250 B<Please Note>: Writing back to the input file increases the risk of data loss
251 or corruption in the event of a software or hardware malfunction. Before using
252 the B<-b> parameter please be sure to have backups and verify that it works
253 correctly in your environment and operating system.
254
255 A B<-b> flag will be ignored if input is from standard input or goes to
256 standard output, or if the B<-html> flag is set.
257
258 In particular, if you want to use both the B<-b> flag and the B<-pbp>
259 (--perl-best-practices) flag, then you must put a B<-nst> flag after the
260 B<-pbp> flag because it contains a B<-st> flag as one of its components,
261 which means that output will go to the standard output stream.
262
263 =item   B<-bext>=ext,    B<--backup-file-extension>=ext
264
265 This parameter serves two purposes: (1) to change the extension of the backup
266 file to be something other than the default F<.bak>, and (2) to indicate
267 that no backup file should be saved.
268
269 To change the default extension to something other than F<.bak> see
270 L<"Specifying File Extensions">.
271
272 A backup file of the source is always written, but you can request that it
273 be deleted at the end of processing if there were no errors.  This is risky
274 unless the source code is being maintained with a source code control
275 system.
276
277 To indicate that the backup should be deleted include one forward slash,
278 B</>, in the extension.  If any text remains after the slash is removed
279 it will be used to define the backup file extension (which is always
280 created and only deleted if there were no errors).
281
282 Here are some examples:
283
284   Parameter           Extension          Backup File Treatment
285   <-bext=bak>         F<.bak>            Keep (same as the default behavior)
286   <-bext='/'>         F<.bak>            Delete if no errors
287   <-bext='/backup'>   F<.backup>         Delete if no errors
288   <-bext='original/'> F<.original>       Delete if no errors
289
290 =item B<-bm=s>,  B<--backup-method=s>
291
292 This parameter should not normally be used but is available in the event that
293 problems arise as a transition is made from an older implementation of the
294 backup logic to a newer implementation.  The newer implementation is the
295 default and is specified with B<-bm='copy'>. The older implementation is
296 specified with B<-bm='move'>.  The difference is that the older implementation
297 made the backup by moving the input file to the backup file, and the newer
298 implementation makes the backup by copying the input file.  The newer
299 implementation preserves the file system B<inode> value. This may avoid
300 problems with other software running simultaneously.  This change was made
301 as part of issue B<git #103> at github.
302
303 =item B<-w>,    B<--warning-output>
304
305 Setting B<-w> causes any non-critical warning
306 messages to be reported as errors.  These include messages
307 about possible pod problems, possibly bad starting indentation level,
308 and cautions about indirect object usage.  The default, B<-nw> or
309 B<--nowarning-output>, is not to include these warnings.
310
311 =item B<-q>,    B<--quiet>
312
313 Deactivate error messages (for running under an editor).
314
315 For example, if you use a vi-style editor, such as vim, you may execute
316 perltidy as a filter from within the editor using something like
317
318  :n1,n2!perltidy -q
319
320 where C<n1,n2> represents the selected text.  Without the B<-q> flag,
321 any error message may mess up your screen, so be prepared to use your
322 "undo" key.
323
324 =item B<-log>,    B<--logfile>
325
326 Save the F<.LOG> file, which has many useful diagnostics.  Perltidy always
327 creates a F<.LOG> file, but by default it is deleted unless a program bug is
328 suspected.  Setting the B<-log> flag forces the log file to be saved.
329
330 =item B<-g=n>, B<--logfile-gap=n>
331
332 Set maximum interval between input code lines in the logfile.  This purpose of
333 this flag is to assist in debugging nesting errors.  The value of C<n> is
334 optional.  If you set the flag B<-g> without the value of C<n>, it will be
335 taken to be 1, meaning that every line will be written to the log file.  This
336 can be helpful if you are looking for a brace, paren, or bracket nesting error.
337
338 Setting B<-g> also causes the logfile to be saved, so it is not necessary to
339 also include B<-log>.
340
341 If no B<-g> flag is given, a value of 50 will be used, meaning that at least
342 every 50th line will be recorded in the logfile.  This helps prevent
343 excessively long log files.
344
345 Setting a negative value of C<n> is the same as not setting B<-g> at all.
346
347 =item B<-npro>  B<--noprofile>
348
349 Ignore any F<.perltidyrc> command file.  Normally, perltidy looks first in
350 your current directory for a F<.perltidyrc> file of parameters.  (The format
351 is described below).  If it finds one, it applies those options to the
352 initial default values, and then it applies any that have been defined
353 on the command line.  If no F<.perltidyrc> file is found, it looks for one
354 in your home directory.
355
356 If you set the B<-npro> flag, perltidy will not look for this file.
357
358 =item B<-pro=filename> or  B<--profile=filename>
359
360 To simplify testing and switching .perltidyrc files, this command may be
361 used to specify a configuration file which will override the default
362 name of .perltidyrc.  There must not be a space on either side of the
363 '=' sign.  For example, the line
364
365    perltidy -pro=testcfg
366
367 would cause file F<testcfg> to be used instead of the
368 default F<.perltidyrc>.
369
370 A pathname begins with three dots, e.g. ".../.perltidyrc", indicates that
371 the file should be searched for starting in the current directory and
372 working upwards. This makes it easier to have multiple projects each with
373 their own .perltidyrc in their root directories.
374
375 =item B<-opt>,   B<--show-options>
376
377 Write a list of all options used to the F<.LOG> file.
378 Please see B<--dump-options> for a simpler way to do this.
379
380 =item B<-f>,   B<--force-read-binary>
381
382 Force perltidy to process binary files.  To avoid producing excessive
383 error messages, perltidy skips files identified by the system as non-text.
384 However, valid perl scripts containing binary data may sometimes be identified
385 as non-text, and this flag forces perltidy to process them.
386
387 =item B<-ast>,   B<--assert-tidy>
388
389 This flag asserts that the input and output code streams are identical, or in
390 other words that the input code is already 'tidy' according to the formatting
391 parameters.  If this is not the case, an error message noting this is produced.
392 This error message will cause the process to return a non-zero exit code.
393 The test for this is made by comparing an MD5 hash value for the input and
394 output code streams. This flag has no other effect on the functioning of
395 perltidy.  This might be useful for certain code maintenance operations.
396 Note: you will not see this message if you have error messages turned off with the
397 -quiet flag.
398
399 =item B<-asu>,   B<--assert-untidy>
400
401 This flag asserts that the input and output code streams are different, or in
402 other words that the input code is 'untidy' according to the formatting
403 parameters.  If this is not the case, an error message noting this is produced.
404 This flag has no other effect on the functioning of perltidy.
405
406 =back
407
408 =head1 FORMATTING OPTIONS
409
410 =head2 Basic Options
411
412 =over 4
413
414 =item B<--notidy>
415
416 This flag disables all formatting and causes the input to be copied unchanged
417 to the output except for possible changes in line ending characters and any
418 pre- and post-filters.  This can be useful in conjunction with a hierarchical
419 set of F<.perltidyrc> files to avoid unwanted code tidying.  See also
420 L<"Skipping Selected Sections of Code"> for a way to avoid tidying specific
421 sections of code.
422
423 =item B<-i=n>,  B<--indent-columns=n>
424
425 Use n columns per indentation level (default n=4).
426
427 =item B<-l=n>, B<--maximum-line-length=n>
428
429 The default maximum line length is n=80 characters.  Perltidy will try
430 to find line break points to keep lines below this length. However, long
431 quotes and side comments may cause lines to exceed this length.
432
433 The default length of 80 comes from the past when this was the standard CRT
434 screen width.  Many programmers prefer to increase this to something like 120.
435
436 Setting B<-l=0> is equivalent to setting B<-l=(a very large number)>.  But this is
437 not recommended because, for example, a very long list will be formatted in a
438 single long line.
439
440 =item B<-vmll>, B<--variable-maximum-line-length>
441
442 A problem arises using a fixed maximum line length with very deeply nested code
443 and data structures because eventually the amount of leading whitespace used
444 for indicating indentation takes up most or all of the available line width,
445 leaving little or no space for the actual code or data.  One solution is to use
446 a very long line length.  Another solution is to use the B<-vmll> flag, which
447 basically tells perltidy to ignore leading whitespace when measuring the line
448 length.
449
450 To be precise, when the B<-vmll> parameter is set, the maximum line length of a
451 line of code will be M+L*I, where
452
453       M is the value of --maximum-line-length=M (-l=M), default 80,
454       I is the value of --indent-columns=I (-i=I), default 4,
455       L is the indentation level of the line of code
456
457 When this flag is set, the choice of breakpoints for a block of code should be
458 essentially independent of its nesting depth.  However, the absolute line
459 lengths, including leading whitespace, can still be arbitrarily large.  This
460 problem can be avoided by including the next parameter.
461
462 The default is not to do this (B<-nvmll>).
463
464 =item B<-wc=n>, B<--whitespace-cycle=n>
465
466 This flag also addresses problems with very deeply nested code and data
467 structures.  When the nesting depth exceeds the value B<n> the leading
468 whitespace will be reduced and start at a depth of 1 again.  The result is that
469 blocks of code will shift back to the left rather than moving arbitrarily far
470 to the right.  This occurs cyclically to any depth.
471
472 For example if one level of indentation equals 4 spaces (B<-i=4>, the default),
473 and one uses B<-wc=15>, then if the leading whitespace on a line exceeds about
474 4*15=60 spaces it will be reduced back to 4*1=4 spaces and continue increasing
475 from there.  If the whitespace never exceeds this limit the formatting remains
476 unchanged.
477
478 The combination of B<-vmll> and B<-wc=n> provides a solution to the problem of
479 displaying arbitrarily deep data structures and code in a finite window,
480 although B<-wc=n> may of course be used without B<-vmll>.
481
482 The default is not to use this, which can also be indicated using B<-wc=0>.
483
484 =item B<Tabs>
485
486 Using tab characters will almost certainly lead to future portability
487 and maintenance problems, so the default and recommendation is not to
488 use them.  For those who prefer tabs, however, there are two different
489 options.
490
491 Except for possibly introducing tab indentation characters, as outlined
492 below, perltidy does not introduce any tab characters into your file,
493 and it removes any tabs from the code (unless requested not to do so
494 with B<-fws>).  If you have any tabs in your comments, quotes, or
495 here-documents, they will remain.
496
497 =over 4
498
499 =item B<-et=n>,   B<--entab-leading-whitespace>
500
501 This flag causes each B<n> leading space characters produced by the
502 formatting process to be replaced by one tab character.  The
503 formatting process itself works with space characters. The B<-et=n> parameter is applied
504 as a last step, after formatting is complete, to convert leading spaces into tabs.
505 Before starting to use tabs, it is essential to first get the indentation
506 controls set as desired without tabs, particularly the two parameters B<--indent-columns=n> (or B<-i=n>) and B<--continuation-indentation=n> (or B<-ci=n>).
507
508 The value of the integer B<n> can be any value but can be coordinated with the
509 number of spaces used for indentation. For example, B<-et=4 -ci=4 -i=4> will
510 produce one tab for each indentation level and and one for each continuation
511 indentation level.  You may want to coordinate the value of B<n> with what your
512 display software assumes for the spacing of a tab.
513
514 =item B<-t>,   B<--tabs>
515
516 This flag causes one leading tab character to be inserted for each level
517 of indentation.  Certain other features are incompatible with this
518 option, and if these options are also given, then a warning message will
519 be issued and this flag will be unset.  One example is the B<-lp>
520 option. This flag is retained for backwards compatibility, but
521 if you use tabs, the B<-et=n> flag is recommended.  If both B<-t> and
522 B<-et=n> are set, the B<-et=n> is used.
523
524 =item B<-dt=n>,   B<--default-tabsize=n>
525
526 If the first line of code passed to perltidy contains leading tabs but no
527 tab scheme is specified for the output stream then perltidy must guess how many
528 spaces correspond to each leading tab.  This number of spaces B<n>
529 corresponding to each leading tab of the input stream may be specified with
530 B<-dt=n>.  The default is B<n=8>.
531
532 This flag has no effect if a tab scheme is specified for the output stream,
533 because then the input stream is assumed to use the same tab scheme and
534 indentation spaces as for the output stream (any other assumption would lead to
535 unstable editing).
536
537 =back
538
539 =item B<-io>,   B<--indent-only>
540
541 This flag is used to deactivate all whitespace and line break changes
542 within non-blank lines of code.
543 When it is in effect, the only change to the script will be
544 to the indentation and to the number of blank lines.
545 And any flags controlling whitespace and newlines will be ignored.  You
546 might want to use this if you are perfectly happy with your whitespace
547 and line breaks, and merely want perltidy to handle the indentation.
548 (This also speeds up perltidy by well over a factor of two, so it might be
549 useful when perltidy is merely being used to help find a brace error in
550 a large script).
551
552 Setting this flag is equivalent to setting B<--freeze-newlines> and
553 B<--freeze-whitespace>.
554
555 If you also want to keep your existing blank lines exactly
556 as they are, you can add B<--freeze-blank-lines>.
557
558 With this option perltidy is still free to modify the indenting (and
559 outdenting) of code and comments as it normally would.  If you also want to
560 prevent long comment lines from being outdented, you can add either B<-noll> or
561 B<-l=0>.
562
563 Setting this flag will prevent perltidy from doing any special operations on
564 closing side comments.  You may still delete all side comments however when
565 this flag is in effect.
566
567
568 =item B<-enc=s>,  B<--character-encoding=s>
569
570 This flag indicates if the input data stream use a character encoding.
571 Perltidy does not look for the encoding directives in the source stream, such
572 as B<use utf8>, and instead relies on this flag to determine the encoding.
573 (Note that perltidy often works on snippets of code rather than complete files
574 so it cannot rely on B<use utf8> directives).
575
576 The possible values for B<s> are:
577
578  -enc=none if no encoding is used, or
579  -enc=utf8 for encoding in utf8
580  -enc=guess if perltidy should guess between these two possibilities.
581
582 The value B<none> causes the stream to be processed without special encoding
583 assumptions.  This is appropriate for files which are written in single-byte
584 character encodings such as latin-1.
585
586 The value B<utf8> causes the stream to be read and written as
587 UTF-8.  If the input stream cannot be decoded with this encoding then
588 processing is not done.
589
590 The value B<guess> tells perltidy to guess between either utf8 encoding or no
591 encoding (meaning one character per byte).  The B<guess> option uses the
592 Encode::Guess module which has been found to be reliable at detecting
593 if a file is encoded in utf8 or not.
594
595 The current default is B<guess>.
596
597 The abbreviations B<-utf8> or B<-UTF8> are equivalent to B<-enc=utf8>, and the
598 abbreviation B<-guess> is equivalent to B<-enc=guess>.  So to process a file
599 named B<file.pl> which is encoded in UTF-8 you can use:
600
601    perltidy -utf8 file.pl
602
603 or
604
605    perltidy -guess file.pl
606
607 or simply
608
609    perltidy file.pl
610
611 since B<-guess> is the default.
612
613 To process files with an encoding other than UTF-8, it would be necessary to
614 write a short program which calls the Perl::Tidy module with some pre- and
615 post-processing to handle decoding and encoding.
616
617 =item B<-eos=s>,   B<--encode-output-strings=s>
618
619 This flag was added to resolve an issue involving the interface between
620 Perl::Tidy and calling programs, and in particular B<Code::TidyAll (tidyall)>.
621
622 If you only run the B<perltidy> binary this flag has no effect.  If you run a
623 program which calls the Perl::Tidy module and receives a string in return, then
624 the meaning of the flag is as follows:
625
626 =over 4
627
628 =item *
629
630 The setting B<-eos> means Perl::Tidy should encode any string which it decodes.
631 This is the default because it makes perltidy behave well as a filter,
632 and is the correct setting for most programs.
633
634 =item *
635
636 The setting B<-neos> means that a string should remain decoded if it was
637 decoded by Perl::Tidy.  This is only appropriate if the calling program will
638 handle any needed encoding before outputting the string.
639
640 =back
641
642 The default was changed from B<-neos> to B<-eos> in versions after 20220217.
643 If this change causes a program to start running incorrectly on encoded files,
644 an emergency fix might be to set B<-neos>.  Additional information can be found
645 in the man pages for the B<Perl::Tidy> module and also in
646 L<https://github.com/perltidy/perltidy/blob/master/docs/eos_flag.md>.
647
648 =item B<-gcs>,  B<--use-unicode-gcstring>
649
650 This flag controls whether or not perltidy may use module Unicode::GCString to
651 obtain accurate display widths of wide characters.  The default
652 is B<--nouse-unicode-gcstring>.
653
654 If this flag is set, and text is encoded, perltidy will look for the module
655 Unicode::GCString and, if found, will use it to obtain character display
656 widths.  This can improve displayed vertical alignment for files with wide
657 characters.  It is a nice feature but it is off by default to avoid conflicting
658 formatting when there are multiple developers.  Perltidy installation does not
659 require Unicode::GCString, so users wanting to use this feature need set this
660 flag and also to install Unicode::GCString separately.
661
662 If this flag is set and perltidy does not find module Unicode::GCString,
663 a warning message will be produced and processing will continue but without
664 the potential benefit provided by the module.
665
666 Also note that actual vertical alignment depends upon the fonts used by the
667 text display software, so vertical alignment may not be optimal even when
668 Unicode::GCString is used.
669
670 =item B<-ole=s>,  B<--output-line-ending=s>
671
672 where s=C<win>, C<dos>, C<unix>, or C<mac>.  This flag tells perltidy
673 to output line endings for a specific system.  Normally,
674 perltidy writes files with the line separator character of the host
675 system.  The C<win> and C<dos> flags have an identical result.
676
677 =item B<-ple>,  B<--preserve-line-endings>
678
679 This flag tells perltidy to write its output files with the same line
680 endings as the input file, if possible.  It should work for
681 B<dos>, B<unix>, and B<mac> line endings.  It will only work if perltidy
682 input comes from a filename (rather than stdin, for example).  If
683 perltidy has trouble determining the input file line ending, it will
684 revert to the default behavior of using the line ending of the host system.
685
686 =item B<-atnl>,  B<--add-terminal-newline>
687
688 This flag, which is enabled by default, allows perltidy to terminate the last
689 line of the output stream with a newline character, regardless of whether or
690 not the input stream was terminated with a newline character.  If this flag is
691 negated, with B<-natnl>, then perltidy will add a terminal newline to the the
692 output stream only if the input stream is terminated with a newline.
693
694 Negating this flag may be useful for manipulating one-line scripts intended for
695 use on a command line.
696
697 =item B<-it=n>,   B<--iterations=n>
698
699 This flag causes perltidy to do B<n> complete iterations.  The reason for this
700 flag is that code beautification is an iterative process and in some
701 cases the output from perltidy can be different if it is applied a second time.
702 For most purposes the default of B<n=1> should be satisfactory.  However B<n=2>
703 can be useful when a major style change is being made, or when code is being
704 beautified on check-in to a source code control system.  It has been found to
705 be extremely rare for the output to change after 2 iterations.  If a value
706 B<n> is greater than 2 is input then a convergence test will be used to stop
707 the iterations as soon as possible, almost always after 2 iterations.  See
708 the next item for a simplified iteration control.
709
710 This flag has no effect when perltidy is used to generate html.
711
712 =item B<-conv>,   B<--converge>
713
714 This flag is equivalent to B<-it=4> and is included to simplify iteration
715 control.  For all practical purposes one either does or does not want to be
716 sure that the output is converged, and there is no penalty to using a large
717 iteration limit since perltidy will check for convergence and stop iterating as
718 soon as possible.  The default is B<-nconv> (no convergence check).  Using
719 B<-conv> will approximately double run time since typically one extra iteration
720 is required to verify convergence.  No extra iterations are required if no new
721 line breaks are made, and two extra iterations are occasionally needed when
722 reformatting complex code structures, such as deeply nested ternary statements.
723
724 =back
725
726 =head2 Code Indentation Control
727
728 =over 4
729
730 =item B<-ci=n>, B<--continuation-indentation=n>
731
732 Continuation indentation is extra indentation spaces applied when
733 a long line is broken.  The default is n=2, illustrated here:
734
735  my $level =   # -ci=2
736    ( $max_index_to_go >= 0 ) ? $levels_to_go[0] : $last_output_level;
737
738 The same example, with n=0, is a little harder to read:
739
740  my $level =   # -ci=0
741  ( $max_index_to_go >= 0 ) ? $levels_to_go[0] : $last_output_level;
742
743 The value given to B<-ci> is also used by some commands when a small
744 space is required.  Examples are commands for outdenting labels,
745 B<-ola>, and control keywords, B<-okw>.
746
747 When default values are not used, it is recommended that either
748
749 (1) the value B<n> given with B<-ci=n> be no more than about one-half of the
750 number of spaces assigned to a full indentation level on the B<-i=n> command, or
751
752 (2) the flag B<-extended-continuation-indentation> is used (see next section).
753
754 =item B<-xci>, B<--extended-continuation-indentation>
755
756 This flag allows perltidy to use some improvements which have been made to its
757 indentation model. One of the things it does is "extend" continuation
758 indentation deeper into structures, hence the name.  The improved indentation
759 is particularly noticeable when the flags B<-ci=n> and B<-i=n> use the same value of
760 B<n>. There are no significant disadvantages to using this flag, but to avoid
761 disturbing existing formatting the default is not to use it, B<-nxci>.
762
763 Please see the section L<"B<-pbp>, B<--perl-best-practices>"> for an example of
764 how this flag can improve the formatting of ternary statements.  It can also
765 improve indentation of some multi-line qw lists as shown below.
766
767             # perltidy
768             foreach $color (
769                 qw(
770                 AntiqueWhite3 Bisque1 Bisque2 Bisque3 Bisque4
771                 SlateBlue3 RoyalBlue1 SteelBlue2 DeepSkyBlue3
772                 ),
773                 qw(
774                 LightBlue1 DarkSlateGray1 Aquamarine2 DarkSeaGreen2
775                 SeaGreen1 Yellow1 IndianRed1 IndianRed2 Tan1 Tan4
776                 )
777               )
778
779             # perltidy -xci
780             foreach $color (
781                 qw(
782                     AntiqueWhite3 Bisque1 Bisque2 Bisque3 Bisque4
783                     SlateBlue3 RoyalBlue1 SteelBlue2 DeepSkyBlue3
784                 ),
785                 qw(
786                     LightBlue1 DarkSlateGray1 Aquamarine2 DarkSeaGreen2
787                     SeaGreen1 Yellow1 IndianRed1 IndianRed2 Tan1 Tan4
788                 )
789               )
790
791 =item B<-sil=n> B<--starting-indentation-level=n>
792
793 By default, perltidy examines the input file and tries to determine the
794 starting indentation level.  While it is often zero, it may not be
795 zero for a code snippet being sent from an editing session.
796
797 To guess the starting indentation level perltidy simply assumes that
798 indentation scheme used to create the code snippet is the same as is being used
799 for the current perltidy process.  This is the only sensible guess that can be
800 made.  It should be correct if this is true, but otherwise it probably won't.
801 For example, if the input script was written with -i=2 and the current perltidy
802 flags have -i=4, the wrong initial indentation will be guessed for a code
803 snippet which has non-zero initial indentation. Likewise, if an entabbing
804 scheme is used in the input script and not in the current process then the
805 guessed indentation will be wrong.
806
807 If the default method does not work correctly, or you want to change the
808 starting level, use B<-sil=n>, to force the starting level to be n.
809
810 =item B<List indentation> using B<--line-up-parentheses>, B<-lp> or B<--extended--line-up-parentheses> , B<-xlp>
811
812 These flags provide an alternative indentation method for list data.  The
813 original flag for this is B<-lp>, but it has some limitations (explained below)
814 which are avoided with the newer B<-xlp> flag.  So B<-xlp> is probably the better
815 choice for new work, but the B<-lp> flag is retained to minimize changes to
816 existing formatting.
817 If you enter both B<-lp> and B<-xlp>, then B<-xlp> will be used.
818
819
820 In the default indentation method perltidy indents lists with 4 spaces, or
821 whatever value is specified with B<-i=n>.  Here is a small list formatted in
822 this way:
823
824     # perltidy (default)
825     @month_of_year = (
826         'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
827         'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
828     );
829
830 The B<-lp> or B<-xlp> flags add extra indentation to cause the data to begin
831 past the opening parentheses of a sub call or list, or opening square bracket
832 of an anonymous array, or opening curly brace of an anonymous hash.  With this
833 option, the above list would become:
834
835     # perltidy -lp or -xlp
836     @month_of_year = (
837                        'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
838                        'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
839     );
840
841 If the available line length (see B<-l=n> ) does not permit this much
842 space, perltidy will use less.   For alternate placement of the
843 closing paren, see the next section.
844
845 These flags have no effect on code BLOCKS, such as if/then/else blocks,
846 which always use whatever is specified with B<-i=n>.
847
848 Some limitations on these flags are:
849
850 =over 4
851
852 =item *
853
854 A limitation on B<-lp>, but not B<-xlp>, occurs in situations where perltidy
855 does not have complete freedom to choose line breaks. Then it may temporarily revert
856 to its default indentation method.  This can occur for example if there are
857 blank lines, block comments, multi-line quotes, or side comments between the
858 opening and closing parens, braces, or brackets.  It will also occur if a
859 multi-line anonymous sub occurs within a container since that will impose
860 specific line breaks (such as line breaks after statements).
861
862 =item *
863
864 For both the B<-lp> and B<-xlp> flags, any parameter which significantly
865 restricts the ability of perltidy to choose newlines will conflict with these
866 flags and will cause them to be deactivated.  These include B<-io>, B<-fnl>,
867 B<-nanl>, and B<-ndnl>.
868
869 =item *
870
871 The B<-lp> and B<-xlp> options may not be used together with the B<-t> tabs option.
872 They may, however, be used with the B<-et=n> tab method
873
874 =back
875
876 There are some potential disadvantages of this indentation method compared to
877 the default method that should be noted:
878
879 =over 4
880
881 =item *
882
883 The available line length can quickly be used up if variable names are
884 long.  This can cause deeply nested code to quickly reach the line length
885 limit, and become badly formatted, much sooner than would occur with the
886 default indentation method.
887
888 =item *
889
890 Since the indentation depends on the lengths of variable names, small
891 changes in variable names can cause changes in indentation over many lines in a
892 file.  This means that minor name changes can produce significant file
893 differences.  This can be annoying and does not occur with the default
894 indentation method.
895
896 =back
897
898 Some things that can be done to minimize these problems are:
899
900 =over 4
901
902 =item *
903
904 Increase B<--maximum-line-length=n> above the default B<n=80> characters if
905 necessary.
906
907 =item *
908
909 If you use B<-xlp> then long side comments can limit the indentation over
910 multiple lines.  Consider adding the flag B<--ignore-side-comment-lengths> to
911 prevent this, or minimizing the use of side comments.
912
913 =item *
914
915 Apply this style in a limited way.  By default, it applies to all list
916 containers (not just lists in parentheses).  The next section describes how to
917 limit this style to, for example, just function calls.  The default indentation
918 method will be applied elsewhere.
919
920 =back
921
922 =item B<-lpil=s>, B<--line-up-parentheses-inclusion-list> and B<-lpxl=s>,  B<--line-up-parentheses-exclusion-list>
923
924 The following discussion is written for B<-lp> but applies equally to the newer B<-xlp> version.
925 By default, the B<-lp> flag applies to as many containers as possible.
926 The set of containers to which the B<-lp> style applies can be reduced by
927 either one of these two flags:
928
929 Use B<-lpil=s> to specify the containers to which B<-lp> applies, or
930
931 use B<-lpxl=s> to specify the containers to which B<-lp> does NOT apply.
932
933 Only one of these two flags may be used.  Both flags can achieve the same
934 result, but the B<-lpil=s> flag is much easier to describe and use and is
935 recommended.  The B<-lpxl=s> flag was the original implementation and is
936 only retained for backwards compatibility.
937
938 This list B<s> for these parameters is a string with space-separated items.
939 Each item consists of up to three pieces of information in this order: (1) an
940 optional letter code (2) a required container type, and (3) an optional numeric
941 code.
942
943 The only required piece of information is a container type, which is one of
944 '(', '[', or '{'.  For example the string
945
946   -lpil='('
947
948 means use -lp formatting only on lists within parentheses, not lists in square-brackets or braces.
949 The same thing could alternatively be specified with
950
951   -lpxl = '[ {'
952
953 which says to exclude lists within square-brackets and braces.  So what remains is lists within parentheses.
954
955 A second optional item of information which can be given for parentheses is an alphanumeric
956 letter which is used to limit the selection further depending on the type of
957 token immediately before the paren.  The possible letters are currently 'k',
958 'K', 'f', 'F', 'w', and 'W', with these meanings for matching whatever precedes an opening paren:
959
960  'k' matches if the previous nonblank token is a perl built-in keyword (such as 'if', 'while'),
961  'K' matches if 'k' does not, meaning that the previous token is not a keyword.
962  'f' matches if the previous token is a function other than a keyword.
963  'F' matches if 'f' does not.
964  'w' matches if either 'k' or 'f' match.
965  'W' matches if 'w' does not.
966
967 For example:
968
969   -lpil = 'f('
970
971 means only apply -lp to function calls, and
972
973   -lpil = 'w('
974
975 means only apply -lp to parenthesized lists which follow a function or a keyword.
976
977 This last example could alternatively be written using the B<-lpxl=s> flag as
978
979   -lpxl = '[ { W('
980
981 which says exclude B<-lp> for lists within square-brackets, braces, and parens NOT preceded by
982 a keyword or function.   Clearly, the B<-lpil=s> method is easier to understand.
983
984 An optional numeric code may follow any of the container types to further refine the selection based
985 on container contents.  The numeric codes are:
986
987   '0' or blank: no check on contents is made
988   '1' exclude B<-lp> unless the contents is a simple list without sublists
989   '2' exclude B<-lp> unless the contents is a simple list without sublists, without
990       code blocks, and without ternary operators
991
992 For example,
993
994   -lpil = 'f(2'
995
996 means only apply -lp to function call lists which do not contain any sublists,
997 code blocks or ternary expressions.
998
999 =item B<-cti=n>, B<--closing-token-indentation>
1000
1001 The B<-cti=n> flag controls the indentation of a line beginning with
1002 a C<)>, C<]>, or a non-block C<}>.  Such a line receives:
1003
1004  -cti = 0 no extra indentation (default)
1005  -cti = 1 extra indentation such that the closing token
1006         aligns with its opening token.
1007  -cti = 2 one extra indentation level if the line looks like:
1008         );  or  ];  or  };
1009  -cti = 3 one extra indentation level always
1010
1011 The flags B<-cti=1> and B<-cti=2> work well with the B<-lp> flag (previous
1012 section).
1013
1014     # perltidy -lp -cti=1
1015     @month_of_year = (
1016                        'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
1017                        'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
1018                      );
1019
1020     # perltidy -lp -cti=2
1021     @month_of_year = (
1022                        'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
1023                        'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
1024                        );
1025
1026 These flags are merely hints to the formatter and they may not always be
1027 followed.  In particular, if -lp is not being used, the indentation for
1028 B<cti=1> is constrained to be no more than one indentation level.
1029
1030 If desired, this control can be applied independently to each of the
1031 closing container token types.  In fact, B<-cti=n> is merely an
1032 abbreviation for B<-cpi=n -csbi=n -cbi=n>, where:
1033 B<-cpi> or B<--closing-paren-indentation> controls B<)>'s,
1034 B<-csbi> or B<--closing-square-bracket-indentation> controls B<]>'s,
1035 B<-cbi> or B<--closing-brace-indentation> controls non-block B<}>'s.
1036
1037 =item B<-icp>, B<--indent-closing-paren>
1038
1039 The B<-icp> flag is equivalent to
1040 B<-cti=2>, described in the previous section.  The B<-nicp> flag is
1041 equivalent B<-cti=0>.  They are included for backwards compatibility.
1042
1043 =item B<-icb>, B<--indent-closing-brace>
1044
1045 The B<-icb> option gives one extra level of indentation to a brace which
1046 terminates a code block .  For example,
1047
1048         if ($task) {
1049             yyy();
1050             }    # -icb
1051         else {
1052             zzz();
1053             }
1054
1055 The default is not to do this, indicated by B<-nicb>.
1056
1057
1058 =item B<-nib>, B<--non-indenting-braces>
1059
1060 Normally, lines of code contained within a pair of block braces receive one
1061 additional level of indentation.  This flag, which is enabled by default,
1062 causes perltidy to look for
1063 opening block braces which are followed by a special side comment. This special
1064 side comment is B<#<<<> by default.  If found, the code between this opening brace and its
1065 corresponding closing brace will not be given the normal extra indentation
1066 level.  For example:
1067
1068             { #<<<   a closure to contain lexical vars
1069
1070             my $var;  # this line does not get one level of indentation
1071             ...
1072
1073             }
1074
1075             # this line does not 'see' $var;
1076
1077 This can be useful, for example, when combining code from different files.
1078 Different sections of code can be placed within braces to keep their lexical
1079 variables from being visible to the end of the file.  To keep the new braces
1080 from causing all of their contained code to be indented if you run perltidy,
1081 and possibly introducing new line breaks in long lines, you can mark the
1082 opening braces with this special side comment.
1083
1084 Only the opening brace needs to be marked, since perltidy knows where the
1085 closing brace is.  Braces contained within marked braces may also be marked
1086 as non-indenting.
1087
1088 If your code happens to have some opening braces followed by '#<<<', and you
1089 don't want this behavior, you can use B<-nnib> to deactivate it.  To make it
1090 easy to remember, the default string is the same as the string for starting a
1091 B<format-skipping> section. There is no confusion because in that case it is
1092 for a block comment rather than a side-comment.
1093
1094 The special side comment can be changed with the next parameter.
1095
1096
1097 =item B<-nibp=s>, B<--non-indenting-brace-prefix=s>
1098
1099 The B<-nibp=string> parameter may be used to change the marker for
1100 non-indenting braces.  The default is equivalent to -nibp='#<<<'.  The string
1101 that you enter must begin with a # and should be in quotes as necessary to get
1102 past the command shell of your system.  This string is the leading text of a
1103 regex pattern that is constructed by appending pre-pending a '^' and appending
1104 a'\s', so you must also include backslashes for characters to be taken
1105 literally rather than as patterns.
1106
1107 For example, to match the side comment '#++', the parameter would be
1108
1109   -nibp='#\+\+'
1110
1111
1112 =item B<-olq>, B<--outdent-long-quotes>
1113
1114 When B<-olq> is set, lines which is a quoted string longer than the
1115 value B<maximum-line-length> will have their indentation removed to make
1116 them more readable.  This is the default.  To prevent such out-denting,
1117 use B<-nolq> or B<--nooutdent-long-lines>.
1118
1119 =item B<-oll>, B<--outdent-long-lines>
1120
1121 This command is equivalent to B<--outdent-long-quotes> and
1122 B<--outdent-long-comments>, and it is included for compatibility with previous
1123 versions of perltidy.  The negation of this also works, B<-noll> or
1124 B<--nooutdent-long-lines>, and is equivalent to setting B<-nolq> and B<-nolc>.
1125
1126 =item B<Outdenting Labels:> B<-ola>,  B<--outdent-labels>
1127
1128 This command will cause labels to be outdented by 2 spaces (or whatever B<-ci>
1129 has been set to), if possible.  This is the default.  For example:
1130
1131         my $i;
1132       LOOP: while ( $i = <FOTOS> ) {
1133             chomp($i);
1134             next unless $i;
1135             fixit($i);
1136         }
1137
1138 Use B<-nola> to not outdent labels.  To control line breaks after labels see L<"-bal=n, --break-after-labels=n">.
1139
1140 =item B<Outdenting Keywords>
1141
1142 =over 4
1143
1144 =item B<-okw>,  B<--outdent-keywords>
1145
1146 The command B<-okw> will cause certain leading control keywords to
1147 be outdented by 2 spaces (or whatever B<-ci> has been set to), if
1148 possible.  By default, these keywords are C<redo>, C<next>, C<last>,
1149 C<goto>, and C<return>.  The intention is to make these control keywords
1150 easier to see.  To change this list of keywords being outdented, see
1151 the next section.
1152
1153 For example, using C<perltidy -okw> on the previous example gives:
1154
1155         my $i;
1156       LOOP: while ( $i = <FOTOS> ) {
1157             chomp($i);
1158           next unless $i;
1159             fixit($i);
1160         }
1161
1162 The default is not to do this.
1163
1164 =item B<Specifying Outdented Keywords:> B<-okwl=string>,  B<--outdent-keyword-list=string>
1165
1166 This command can be used to change the keywords which are outdented with
1167 the B<-okw> command.  The parameter B<string> is a required list of perl
1168 keywords, which should be placed in quotes if there are more than one.
1169 By itself, it does not cause any outdenting to occur, so the B<-okw>
1170 command is still required.
1171
1172 For example, the commands C<-okwl="next last redo goto" -okw> will cause
1173 those four keywords to be outdented.  It is probably simplest to place
1174 any B<-okwl> command in a F<.perltidyrc> file.
1175
1176 =back
1177
1178 =back
1179
1180 =head2 Whitespace Control
1181
1182 Whitespace refers to the blank space between variables, operators,
1183 and other code tokens.
1184
1185 =over 4
1186
1187 =item B<-fws>,  B<--freeze-whitespace>
1188
1189 This flag causes your original whitespace to remain unchanged, and
1190 causes the rest of the whitespace commands in this section, the
1191 Code Indentation section, and
1192 the Comment Control section to be ignored.
1193
1194 =item B<Tightness of curly braces, parentheses, and square brackets>
1195
1196 Here the term "tightness" will mean the closeness with which
1197 pairs of enclosing tokens, such as parentheses, contain the quantities
1198 within.  A numerical value of 0, 1, or 2 defines the tightness, with
1199 0 being least tight and 2 being most tight.  Spaces within containers
1200 are always symmetric, so if there is a space after a C<(> then there
1201 will be a space before the corresponding C<)>.
1202
1203 The B<-pt=n> or B<--paren-tightness=n> parameter controls the space within
1204 parens.  The example below shows the effect of the three possible
1205 values, 0, 1, and 2:
1206
1207  if ( ( my $len_tab = length( $tabstr ) ) > 0 ) {  # -pt=0
1208  if ( ( my $len_tab = length($tabstr) ) > 0 ) {    # -pt=1 (default)
1209  if ((my $len_tab = length($tabstr)) > 0) {        # -pt=2
1210
1211 When n is 0, there is always a space to the right of a '(' and to the left
1212 of a ')'.  For n=2 there is never a space.  For n=1, the default, there
1213 is a space unless the quantity within the parens is a single token, such
1214 as an identifier or quoted string.
1215
1216 Likewise, the parameter B<-sbt=n> or B<--square-bracket-tightness=n>
1217 controls the space within square brackets, as illustrated below.
1218
1219  $width = $col[ $j + $k ] - $col[ $j ];  # -sbt=0
1220  $width = $col[ $j + $k ] - $col[$j];    # -sbt=1 (default)
1221  $width = $col[$j + $k] - $col[$j];      # -sbt=2
1222
1223 Curly braces which do not contain code blocks are controlled by
1224 the parameter B<-bt=n> or B<--brace-tightness=n>.
1225
1226  $obj->{ $parsed_sql->{ 'table' }[0] };    # -bt=0
1227  $obj->{ $parsed_sql->{'table'}[0] };      # -bt=1 (default)
1228  $obj->{$parsed_sql->{'table'}[0]};        # -bt=2
1229
1230 And finally, curly braces which contain blocks of code are controlled by the
1231 parameter B<-bbt=n> or B<--block-brace-tightness=n> as illustrated in the
1232 example below.
1233
1234  %bf = map { $_ => -M $_ } grep { /\.deb$/ } dirents '.'; # -bbt=0 (default)
1235  %bf = map { $_ => -M $_ } grep {/\.deb$/} dirents '.';   # -bbt=1
1236  %bf = map {$_ => -M $_} grep {/\.deb$/} dirents '.';     # -bbt=2
1237
1238 To simplify input in the case that all of the tightness flags have the same
1239 value <n>, the parameter <-act=n> or B<--all-containers-tightness=n> is an
1240 abbreviation for the combination <-pt=n -sbt=n -bt=n -bbt=n>.
1241
1242
1243 =item B<-tso>,   B<--tight-secret-operators>
1244
1245 The flag B<-tso> causes certain perl token sequences (secret operators)
1246 which might be considered to be a single operator to be formatted "tightly"
1247 (without spaces).  The operators currently modified by this flag are:
1248
1249      0+  +0  ()x!! ~~<>  ,=>   =( )=
1250
1251 For example the sequence B<0 +>,  which converts a string to a number,
1252 would be formatted without a space: B<0+> when the B<-tso> flag is set.  This
1253 flag is off by default.
1254
1255 =item B<-sts>,   B<--space-terminal-semicolon>
1256
1257 Some programmers prefer a space before all terminal semicolons.  The
1258 default is for no such space, and is indicated with B<-nsts> or
1259 B<--nospace-terminal-semicolon>.
1260
1261         $i = 1 ;     #  -sts
1262         $i = 1;      #  -nsts   (default)
1263
1264 =item B<-sfs>,   B<--space-for-semicolon>
1265
1266 Semicolons within B<for> loops may sometimes be hard to see,
1267 particularly when commas are also present.  This option places spaces on
1268 both sides of these special semicolons, and is the default.  Use
1269 B<-nsfs> or B<--nospace-for-semicolon> to deactivate it.
1270
1271  for ( @a = @$ap, $u = shift @a ; @a ; $u = $v ) {  # -sfs (default)
1272  for ( @a = @$ap, $u = shift @a; @a; $u = $v ) {    # -nsfs
1273
1274 =item B<-asc>,  B<--add-semicolons>
1275
1276 Setting B<-asc> allows perltidy to add any missing optional semicolon at the end
1277 of a line which is followed by a closing curly brace on the next line.  This
1278 is the default, and may be deactivated with B<-nasc> or B<--noadd-semicolons>.
1279
1280 =item B<-dsm>,  B<--delete-semicolons>
1281
1282 Setting B<-dsm> allows perltidy to delete extra semicolons which are
1283 simply empty statements.  This is the default, and may be deactivated
1284 with B<-ndsm> or B<--nodelete-semicolons>.  (Such semicolons are not
1285 deleted, however, if they would promote a side comment to a block
1286 comment).
1287
1288 =item B<-aws>,  B<--add-whitespace>
1289
1290 Setting this option allows perltidy to add certain whitespace to improve
1291 code readability.  This is the default. If you do not want any
1292 whitespace added, but are willing to have some whitespace deleted, use
1293 B<-naws>.  (Use B<-fws> to leave whitespace completely unchanged).
1294
1295 =item B<-dws>,  B<--delete-old-whitespace>
1296
1297 Setting this option allows perltidy to remove some old whitespace
1298 between characters, if necessary.  This is the default.  If you
1299 do not want any old whitespace removed, use B<-ndws> or
1300 B<--nodelete-old-whitespace>.
1301
1302 =item B<Detailed whitespace controls around tokens>
1303
1304 For those who want more detailed control over the whitespace around
1305 tokens, there are four parameters which can directly modify the default
1306 whitespace rules built into perltidy for any token.  They are:
1307
1308 B<-wls=s> or B<--want-left-space=s>,
1309
1310 B<-nwls=s> or B<--nowant-left-space=s>,
1311
1312 B<-wrs=s> or B<--want-right-space=s>,
1313
1314 B<-nwrs=s> or B<--nowant-right-space=s>.
1315
1316 These parameters are each followed by a quoted string, B<s>, containing a
1317 list of token types.  No more than one of each of these parameters
1318 should be specified, because repeating a command-line parameter
1319 always overwrites the previous one before perltidy ever sees it.
1320
1321 To illustrate how these are used, suppose it is desired that there be no
1322 space on either side of the token types B<= + - / *>.  The following two
1323 parameters would specify this desire:
1324
1325   -nwls="= + - / *"    -nwrs="= + - / *"
1326
1327 (Note that the token types are in quotes, and that they are separated by
1328 spaces).  With these modified whitespace rules, the following line of math:
1329
1330   $root = -$b + sqrt( $b * $b - 4. * $a * $c ) / ( 2. * $a );
1331
1332 becomes this:
1333
1334   $root=-$b+sqrt( $b*$b-4.*$a*$c )/( 2.*$a );
1335
1336 These parameters should be considered to be hints to perltidy rather
1337 than fixed rules, because perltidy must try to resolve conflicts that
1338 arise between them and all of the other rules that it uses.  One
1339 conflict that can arise is if, between two tokens, the left token wants
1340 a space and the right one doesn't.  In this case, the token not wanting
1341 a space takes priority.
1342
1343 It is necessary to have a list of all token types in order to create
1344 this type of input.  Such a list can be obtained by the command
1345 B<--dump-token-types>.  Also try the B<-D> flag on a short snippet of code
1346 and look at the .DEBUG file to see the tokenization.
1347
1348 B<WARNING> Be sure to put these tokens in quotes to avoid having them
1349 misinterpreted by your command shell.
1350
1351 =item B<Note1: Perltidy does always follow whitespace controls>
1352
1353 The various parameters controlling whitespace within a program are requests which perltidy follows as well as possible, but there are a number of situations where changing whitespace could change program behavior and is not done.  Some of these are obvious; for example, we should not remove the space between the two plus symbols in '$x+ +$y' to avoid creating a '++' operator. Some are more subtle and involve the whitespace around bareword symbols and locations of possible filehandles.  For example, consider the problem of formatting the following subroutine:
1354
1355    sub print_div {
1356       my ($x,$y)=@_;
1357       print $x/$y;
1358    }
1359
1360 Suppose the user requests that / signs have a space to the left but not to the right. Perltidy will refuse to do this, but if this were done the result would be
1361
1362    sub print_div {
1363        my ($x,$y)=@_;
1364        print $x /$y;
1365    }
1366
1367 If formatted in this way, the program will not run (at least with recent versions of perl) because the $x is taken to be a filehandle and / is assumed to start a quote. In a complex program, there might happen to be a / which terminates the multiline quote without a syntax error, allowing the program to run, but not as intended.
1368
1369 Related issues arise with other binary operator symbols, such as + and -, and in older versions of perl there could be problems with ternary operators.  So to avoid changing program behavior, perltidy has the simple rule that whitespace around possible filehandles is left unchanged.  Likewise, whitespace around barewords is left unchanged.  The reason is that if the barewords are defined in other modules, or in code that has not even been written yet, perltidy will not have seen their prototypes and must treat them cautiously.
1370
1371 In perltidy this is implemented in the tokenizer by marking token following a
1372 B<print> keyword as a special type B<Z>.  When formatting is being done,
1373 whitespace following this token type is generally left unchanged as a precaution
1374 against changing program behavior.  This is excessively conservative but simple
1375 and easy to implement.  Keywords which are treated similarly to B<print> include
1376 B<printf>, B<sort>, B<exec>, B<system>.  Changes in spacing around parameters
1377 following these keywords may have to be made manually.  For example, the space,
1378 or lack of space, after the parameter $foo in the following line will be
1379 unchanged in formatting.
1380
1381    system($foo );
1382    system($foo);
1383
1384 To find if a token is of type B<Z> you can use B<perltidy -DEBUG>. For the
1385 first line above the result is
1386
1387    1: system($foo );
1388    1: kkkkkk{ZZZZb};
1389
1390 which shows that B<system> is type B<k> (keyword) and $foo is type B<Z>.
1391
1392 =item B<Note2: Perltidy's whitespace rules are not perfect>
1393
1394 Despite these precautions, it is still possible to introduce syntax errors with
1395 some asymmetric whitespace rules, particularly when call parameters are not
1396 placed in containing parens or braces.  For example, the following two lines will
1397 be parsed by perl without a syntax error:
1398
1399   # original programming, syntax ok
1400   my @newkeys = map $_-$nrecs+@data, @oldkeys;
1401
1402   # perltidy default, syntax ok
1403   my @newkeys = map $_ - $nrecs + @data, @oldkeys;
1404
1405 But the following will give a syntax error:
1406
1407   # perltidy -nwrs='-'
1408   my @newkeys = map $_ -$nrecs + @data, @oldkeys;
1409
1410 For another example, the following two lines will be parsed without syntax error:
1411
1412   # original programming, syntax ok
1413   for my $severity ( reverse $SEVERITY_LOWEST+1 .. $SEVERITY_HIGHEST ) { ...  }
1414
1415   # perltidy default, syntax ok
1416   for my $severity ( reverse $SEVERITY_LOWEST + 1 .. $SEVERITY_HIGHEST ) { ... }
1417
1418 But the following will give a syntax error:
1419
1420   # perltidy -nwrs='+', syntax error:
1421   for my $severity ( reverse $SEVERITY_LOWEST +1 .. $SEVERITY_HIGHEST ) { ... }
1422
1423 To avoid subtle parsing problems like this, it is best to avoid spacing a
1424 binary operator asymmetrically with a space on the left but not on the right.
1425
1426 =item B<Space between specific keywords and opening paren>
1427
1428 When an opening paren follows a Perl keyword, no space is introduced after the
1429 keyword, unless it is (by default) one of these:
1430
1431    my local our and or xor eq ne if else elsif until unless
1432    while for foreach return switch case given when
1433
1434 These defaults can be modified with two commands:
1435
1436 B<-sak=s>  or B<--space-after-keyword=s>  adds keywords.
1437
1438 B<-nsak=s>  or B<--nospace-after-keyword=s>  removes keywords.
1439
1440 where B<s> is a list of keywords (in quotes if necessary).  For example,
1441
1442   my ( $a, $b, $c ) = @_;    # default
1443   my( $a, $b, $c ) = @_;     # -nsak="my local our"
1444
1445 The abbreviation B<-nsak='*'> is equivalent to including all of the
1446 keywords in the above list.
1447
1448 When both B<-nsak=s> and B<-sak=s> commands are included, the B<-nsak=s>
1449 command is executed first.  For example, to have space after only the
1450 keywords (my, local, our) you could use B<-nsak="*" -sak="my local our">.
1451
1452 To put a space after all keywords, see the next item.
1453
1454 =item B<Space between all keywords and opening parens>
1455
1456 When an opening paren follows a function or keyword, no space is introduced
1457 after the keyword except for the keywords noted in the previous item.  To
1458 always put a space between a function or keyword and its opening paren,
1459 use the command:
1460
1461 B<-skp>  or B<--space-keyword-paren>
1462
1463 You may also want to use the flag B<-sfp> (next item) too.
1464
1465 =item B<Space between all function names and opening parens>
1466
1467 When an opening paren follows a function the default and recommended formatting
1468 is not to introduce a space.  To cause a space to be introduced use:
1469
1470 B<-sfp>  or B<--space-function-paren>
1471
1472   myfunc( $a, $b, $c );    # default
1473   myfunc ( $a, $b, $c );   # -sfp
1474
1475 You will probably also want to use the flag B<-skp> (previous item) too.
1476
1477 The parameter is not recommended because spacing a function paren can make a
1478 program vulnerable to parsing problems by Perl.  For example, the following
1479 two-line program will run as written but will have a syntax error if
1480 reformatted with -sfp:
1481
1482   if ( -e filename() ) { print "I'm here\n"; }
1483   sub filename { return $0 }
1484
1485 In this particular case the syntax error can be removed if the line order is
1486 reversed, so that Perl parses 'sub filename' first.
1487
1488 =item B<-fpva>  or B<--function-paren-vertical-alignment>
1489
1490 A side-effect of using the B<-sfp> flag is that the parens may become vertically
1491 aligned. For example,
1492
1493     # perltidy -sfp
1494     myfun     ( $aaa, $b, $cc );
1495     mylongfun ( $a, $b, $c );
1496
1497 This is the default behavior.  To prevent this alignment use B<-nfpva>:
1498
1499     # perltidy -sfp -nfpva
1500     myfun ( $aaa, $b, $cc );
1501     mylongfun ( $a, $b, $c );
1502
1503 =item B<-spp=n>  or B<--space-prototype-paren=n>
1504
1505 This flag can be used to control whether a function prototype is preceded by a space.  For example, the following prototype does not have a space.
1506
1507       sub usage();
1508
1509 This integer B<n> may have the value 0, 1, or 2 as follows:
1510
1511     -spp=0 means no space before the paren
1512     -spp=1 means follow the example of the source code [DEFAULT]
1513     -spp=2 means always put a space before the paren
1514
1515 The default is B<-spp=1>, meaning that a space will be used if and only if there is one in the source code.  Given the above line of code, the result of
1516 applying the different options would be:
1517
1518         sub usage();    # n=0 [no space]
1519         sub usage();    # n=1 [default; follows input]
1520         sub usage ();   # n=2 [space]
1521
1522 =item B<-kpit=n> or B<--keyword-paren-inner-tightness=n>
1523
1524 The space inside of an opening paren, which itself follows a certain keyword,
1525 can be controlled by this parameter.  The space on the inside of the
1526 corresponding closing paren will be treated in the same (balanced) manner.
1527 This parameter has precedence over any other paren spacing rules.  The values
1528 of B<n> are as follows:
1529
1530    -kpit=0 means always put a space (not tight)
1531    -kpit=1 means ignore this parameter [default]
1532    -kpit=2 means never put a space (tight)
1533
1534 To illustrate, the following snippet is shown formatted in three ways:
1535
1536     if ( seek( DATA, 0, 0 ) ) { ... }    # perltidy (default)
1537     if (seek(DATA, 0, 0)) { ... }        # perltidy -pt=2
1538     if ( seek(DATA, 0, 0) ) { ... }      # perltidy -pt=2 -kpit=0
1539
1540 In the second case the -pt=2 parameter makes all of the parens tight. In the
1541 third case the -kpit=0 flag causes the space within the 'if' parens to have a
1542 space, since 'if' is one of the keywords to which the -kpit flag applies by
1543 default.  The remaining parens are still tight because of the -pt=2 parameter.
1544
1545 The set of keywords to which this parameter applies are by default are:
1546
1547    if elsif unless while until for foreach
1548
1549 These can be changed with the parameter B<-kpitl=s> described in the next section.
1550
1551
1552 =item B<-kpitl=string> or B<--keyword-paren-inner-tightness=string>
1553
1554 This command can be used to change the keywords to which the the B<-kpit=n>
1555 command applies.  The parameter B<string> is a required list either keywords or
1556 functions, which should be placed in quotes if there are more than one.  By
1557 itself, this parameter does not cause any change in spacing, so the B<-kpit=n>
1558 command is still required.
1559
1560 For example, the commands C<-kpitl="if else while" -kpit=2> will cause the just
1561 the spaces inside parens following  'if', 'else', and 'while' keywords to
1562 follow the tightness value indicated by the B<-kpit=2> flag.
1563
1564 =item B<-lop>  or B<--logical-padding>
1565
1566 In the following example some extra space has been inserted on the second
1567 line between the two open parens. This extra space is called "logical padding"
1568 and is intended to help align similar things vertically in some logical
1569 or ternary expressions.
1570
1571     # perltidy [default formatting]
1572     $same =
1573       (      ( $aP eq $bP )
1574           && ( $aS eq $bS )
1575           && ( $aT eq $bT )
1576           && ( $a->{'title'} eq $b->{'title'} )
1577           && ( $a->{'href'} eq $b->{'href'} ) );
1578
1579 Note that this is considered to be a different operation from "vertical
1580 alignment" because space at just one line is being adjusted, whereas in
1581 "vertical alignment" the spaces at all lines are being adjusted. So it sort of
1582 a local version of vertical alignment.
1583
1584 Here is an example involving a ternary operator:
1585
1586     # perltidy [default formatting]
1587     $bits =
1588         $top > 0xffff ? 32
1589       : $top > 0xff   ? 16
1590       : $top > 1      ? 8
1591       :                 1;
1592
1593 This behavior is controlled with the flag B<--logical-padding>, which is set
1594 'on' by default.  If it is not desired it can be turned off using
1595 B<--nological-padding> or B<-nlop>.  The above two examples become, with
1596 B<-nlop>:
1597
1598     # perltidy -nlop
1599     $same =
1600       ( ( $aP eq $bP )
1601           && ( $aS eq $bS )
1602           && ( $aT eq $bT )
1603           && ( $a->{'title'} eq $b->{'title'} )
1604           && ( $a->{'href'} eq $b->{'href'} ) );
1605
1606     # perltidy -nlop
1607     $bits =
1608       $top > 0xffff ? 32
1609       : $top > 0xff ? 16
1610       : $top > 1    ? 8
1611       :               1;
1612
1613
1614 =item B<Trimming whitespace around C<qw> quotes>
1615
1616 B<-tqw> or B<--trim-qw> provide the default behavior of trimming
1617 spaces around multi-line C<qw> quotes and indenting them appropriately.
1618
1619 B<-ntqw> or B<--notrim-qw> cause leading and trailing whitespace around
1620 multi-line C<qw> quotes to be left unchanged.  This option will not
1621 normally be necessary, but was added for testing purposes, because in
1622 some versions of perl, trimming C<qw> quotes changes the syntax tree.
1623
1624 =item B<-sbq=n>  or B<--space-backslash-quote=n>
1625
1626 lines like
1627
1628        $str1=\"string1";
1629        $str2=\'string2';
1630
1631 can confuse syntax highlighters unless a space is included between the backslash and the single or double quotation mark.
1632
1633 this can be controlled with the value of B<n> as follows:
1634
1635     -sbq=0 means no space between the backslash and quote
1636     -sbq=1 means follow the example of the source code
1637     -sbq=2 means always put a space between the backslash and quote
1638
1639 The default is B<-sbq=1>, meaning that a space will be used if there is one in the source code.
1640
1641 =item B<Trimming trailing whitespace from lines of POD>
1642
1643 B<-trp> or B<--trim-pod> will remove trailing whitespace from lines of POD.
1644 The default is not to do this.
1645
1646 =back
1647
1648 =head2 Comment Controls
1649
1650 Perltidy has a number of ways to control the appearance of both block comments
1651 and side comments.  The term B<block comment> here refers to a full-line
1652 comment, whereas B<side comment> will refer to a comment which appears on a
1653 line to the right of some code.
1654
1655 =over 4
1656
1657 =item B<-ibc>,  B<--indent-block-comments>
1658
1659 Block comments normally look best when they are indented to the same
1660 level as the code which follows them.  This is the default behavior, but
1661 you may use B<-nibc> to keep block comments left-justified.  Here is an
1662 example:
1663
1664              # this comment is indented      (-ibc, default)
1665              if ($task) { yyy(); }
1666
1667 The alternative is B<-nibc>:
1668
1669  # this comment is not indented              (-nibc)
1670              if ($task) { yyy(); }
1671
1672 See also the next item, B<-isbc>, as well as B<-sbc>, for other ways to
1673 have some indented and some outdented block comments.
1674
1675 =item B<-isbc>,  B<--indent-spaced-block-comments>
1676
1677 If there is no leading space on the line, then the comment will not be
1678 indented, and otherwise it may be.
1679
1680 If both B<-ibc> and B<-isbc> are set, then B<-isbc> takes priority.
1681
1682 =item B<-olc>, B<--outdent-long-comments>
1683
1684 When B<-olc> is set, lines which are full-line (block) comments longer
1685 than the value B<maximum-line-length> will have their indentation
1686 removed.  This is the default; use B<-nolc> to prevent outdenting.
1687
1688 =item B<-msc=n>,  B<--minimum-space-to-comment=n>
1689
1690 Side comments look best when lined up several spaces to the right of
1691 code.  Perltidy will try to keep comments at least n spaces to the
1692 right.  The default is n=4 spaces.
1693
1694 =item B<-fpsc=n>,  B<--fixed-position-side-comment=n>
1695
1696 This parameter tells perltidy to line up side comments in column number B<n>
1697 whenever possible.  The default, n=0, will not do this.
1698
1699 =item B<-iscl>,  B<--ignore-side-comment-lengths>
1700
1701 This parameter causes perltidy to ignore the length of side comments when
1702 setting line breaks.  The default, B<-niscl>, is to include the length of
1703 side comments when breaking lines to stay within the length prescribed
1704 by the B<-l=n> maximum line length parameter.  For example, the following
1705 long single line would remain intact with -l=80 and -iscl:
1706
1707      perltidy -l=80 -iscl
1708         $vmsfile =~ s/;[\d\-]*$//; # Clip off version number; we can use a newer version as well
1709
1710 whereas without the -iscl flag the line will be broken:
1711
1712      perltidy -l=80
1713         $vmsfile =~ s/;[\d\-]*$//
1714           ;    # Clip off version number; we can use a newer version as well
1715
1716
1717 =item B<-hsc>, B<--hanging-side-comments>
1718
1719 By default, perltidy tries to identify and align "hanging side
1720 comments", which are something like this:
1721
1722         my $IGNORE = 0;    # This is a side comment
1723                            # This is a hanging side comment
1724                            # And so is this
1725
1726 A comment is considered to be a hanging side comment if (1) it immediately
1727 follows a line with a side comment, or another hanging side comment, and
1728 (2) there is some leading whitespace on the line.
1729 To deactivate this feature, use B<-nhsc> or B<--nohanging-side-comments>.
1730 If block comments are preceded by a blank line, or have no leading
1731 whitespace, they will not be mistaken as hanging side comments.
1732
1733 =item B<Closing Side Comments>
1734
1735 A closing side comment is a special comment which perltidy can
1736 automatically create and place after the closing brace of a code block.
1737 They can be useful for code maintenance and debugging.  The command
1738 B<-csc> (or B<--closing-side-comments>) adds or updates closing side
1739 comments.  For example, here is a small code snippet
1740
1741         sub message {
1742             if ( !defined( $_[0] ) ) {
1743                 print("Hello, World\n");
1744             }
1745             else {
1746                 print( $_[0], "\n" );
1747             }
1748         }
1749
1750 And here is the result of processing with C<perltidy -csc>:
1751
1752         sub message {
1753             if ( !defined( $_[0] ) ) {
1754                 print("Hello, World\n");
1755             }
1756             else {
1757                 print( $_[0], "\n" );
1758             }
1759         } ## end sub message
1760
1761 A closing side comment was added for C<sub message> in this case, but not
1762 for the C<if> and C<else> blocks, because they were below the 6 line
1763 cutoff limit for adding closing side comments.  This limit may be
1764 changed with the B<-csci> command, described below.
1765
1766 The command B<-dcsc> (or B<--delete-closing-side-comments>) reverses this
1767 process and removes these comments.
1768
1769 Several commands are available to modify the behavior of these two basic
1770 commands, B<-csc> and B<-dcsc>:
1771
1772 =over 4
1773
1774 =item B<-csci=n>, or B<--closing-side-comment-interval=n>
1775
1776 where C<n> is the minimum number of lines that a block must have in
1777 order for a closing side comment to be added.  The default value is
1778 C<n=6>.  To illustrate:
1779
1780         # perltidy -csci=2 -csc
1781         sub message {
1782             if ( !defined( $_[0] ) ) {
1783                 print("Hello, World\n");
1784             } ## end if ( !defined( $_[0] ))
1785             else {
1786                 print( $_[0], "\n" );
1787             } ## end else [ if ( !defined( $_[0] ))
1788         } ## end sub message
1789
1790 Now the C<if> and C<else> blocks are commented.  However, now this has
1791 become very cluttered.
1792
1793 =item B<-cscp=string>, or B<--closing-side-comment-prefix=string>
1794
1795 where string is the prefix used before the name of the block type.  The
1796 default prefix, shown above, is C<## end>.  This string will be added to
1797 closing side comments, and it will also be used to recognize them in
1798 order to update, delete, and format them.  Any comment identified as a
1799 closing side comment will be placed just a single space to the right of
1800 its closing brace.
1801
1802 =item B<-cscl=string>, or B<--closing-side-comment-list>
1803
1804 where C<string> is a list of block types to be tagged with closing side
1805 comments.  By default, all code block types preceded by a keyword or
1806 label (such as C<if>, C<sub>, and so on) will be tagged.  The B<-cscl>
1807 command changes the default list to be any selected block types; see
1808 L<"Specifying Block Types">.
1809 For example, the following command
1810 requests that only C<sub>'s, labels, C<BEGIN>, and C<END> blocks be
1811 affected by any B<-csc> or B<-dcsc> operation:
1812
1813    -cscl="sub : BEGIN END"
1814
1815 =item B<-csct=n>, or B<--closing-side-comment-maximum-text=n>
1816
1817 The text appended to certain block types, such as an C<if> block, is
1818 whatever lies between the keyword introducing the block, such as C<if>,
1819 and the opening brace.  Since this might be too much text for a side
1820 comment, there needs to be a limit, and that is the purpose of this
1821 parameter.  The default value is C<n=20>, meaning that no additional
1822 tokens will be appended to this text after its length reaches 20
1823 characters.  Omitted text is indicated with C<...>.  (Tokens, including
1824 sub names, are never truncated, however, so actual lengths may exceed
1825 this).  To illustrate, in the above example, the appended text of the
1826 first block is C< ( !defined( $_[0] )...>.  The existing limit of
1827 C<n=20> caused this text to be truncated, as indicated by the C<...>.  See
1828 the next flag for additional control of the abbreviated text.
1829
1830 =item B<-cscb>, or B<--closing-side-comments-balanced>
1831
1832 As discussed in the previous item, when the
1833 closing-side-comment-maximum-text limit is exceeded the comment text must
1834 be truncated.  Older versions of perltidy terminated with three dots, and this
1835 can still be achieved with -ncscb:
1836
1837   perltidy -csc -ncscb
1838   } ## end foreach my $foo (sort { $b cmp $a ...
1839
1840 However this causes a problem with editors which cannot recognize
1841 comments or are not configured to do so because they cannot "bounce" around in
1842 the text correctly.  The B<-cscb> flag has been added to
1843 help them by appending appropriate balancing structure:
1844
1845   perltidy -csc -cscb
1846   } ## end foreach my $foo (sort { $b cmp $a ... })
1847
1848 The default is B<-cscb>.
1849
1850 =item B<-csce=n>, or B<--closing-side-comment-else-flag=n>
1851
1852 The default, B<n=0>, places the text of the opening C<if> statement after any
1853 terminal C<else>.
1854
1855 If B<n=2> is used, then each C<elsif> is also given the text of the opening
1856 C<if> statement.  Also, an C<else> will include the text of a preceding
1857 C<elsif> statement.  Note that this may result some long closing
1858 side comments.
1859
1860 If B<n=1> is used, the results will be the same as B<n=2> whenever the
1861 resulting line length is less than the maximum allowed.
1862
1863 =item B<-cscb>, or B<--closing-side-comments-balanced>
1864
1865 When using closing-side-comments, and the closing-side-comment-maximum-text
1866 limit is exceeded, then the comment text must be abbreviated.
1867 It is terminated with three dots if the B<-cscb> flag is negated:
1868
1869   perltidy -csc -ncscb
1870   } ## end foreach my $foo (sort { $b cmp $a ...
1871
1872 This causes a problem with older editors which do not recognize comments
1873 because they cannot "bounce" around in the text correctly.  The B<-cscb>
1874 flag tries to help them by appending appropriate terminal balancing structures:
1875
1876   perltidy -csc -cscb
1877   } ## end foreach my $foo (sort { $b cmp $a ... })
1878
1879 The default is B<-cscb>.
1880
1881
1882 =item B<-cscw>, or B<--closing-side-comment-warnings>
1883
1884 This parameter is intended to help make the initial transition to the use of
1885 closing side comments.
1886 It causes two
1887 things to happen if a closing side comment replaces an existing, different
1888 closing side comment:  first, an error message will be issued, and second, the
1889 original side comment will be placed alone on a new specially marked comment
1890 line for later attention.
1891
1892 The intent is to avoid clobbering existing hand-written side comments
1893 which happen to match the pattern of closing side comments. This flag
1894 should only be needed on the first run with B<-csc>.
1895
1896 =back
1897
1898 B<Important Notes on Closing Side Comments:>
1899
1900 =over 4
1901
1902 =item *
1903
1904 Closing side comments are only placed on lines terminated with a closing
1905 brace.  Certain closing styles, such as the use of cuddled elses
1906 (B<-ce>), preclude the generation of some closing side comments.
1907
1908 =item *
1909
1910 Please note that adding or deleting of closing side comments takes
1911 place only through the commands B<-csc> or B<-dcsc>.  The other commands,
1912 if used, merely modify the behavior of these two commands.
1913
1914 =item *
1915
1916 It is recommended that the B<-cscw> flag be used along with B<-csc> on
1917 the first use of perltidy on a given file.  This will prevent loss of
1918 any existing side comment data which happens to have the csc prefix.
1919
1920 =item *
1921
1922 Once you use B<-csc>, you should continue to use it so that any
1923 closing side comments remain correct as code changes.  Otherwise, these
1924 comments will become incorrect as the code is updated.
1925
1926 =item *
1927
1928 If you edit the closing side comments generated by perltidy, you must also
1929 change the prefix to be different from the closing side comment prefix.
1930 Otherwise, your edits will be lost when you rerun perltidy with B<-csc>.   For
1931 example, you could simply change C<## end> to be C<## End>, since the test is
1932 case sensitive.  You may also want to use the B<-ssc> flag to keep these
1933 modified closing side comments spaced the same as actual closing side comments.
1934
1935 =item *
1936
1937 Temporarily generating closing side comments is a useful technique for
1938 exploring and/or debugging a perl script, especially one written by someone
1939 else.  You can always remove them with B<-dcsc>.
1940
1941 =back
1942
1943 =item B<Static Block Comments>
1944
1945 Static block comments are block comments with a special leading pattern,
1946 C<##> by default, which will be treated slightly differently from other
1947 block comments.  They effectively behave as if they had glue along their
1948 left and top edges, because they stick to the left edge and previous line
1949 when there is no blank spaces in those places.  This option is
1950 particularly useful for controlling how commented code is displayed.
1951
1952 =over 4
1953
1954 =item B<-sbc>, B<--static-block-comments>
1955
1956 When B<-sbc> is used, a block comment with a special leading pattern, C<##> by
1957 default, will be treated specially.
1958
1959 Comments so identified  are treated as follows:
1960
1961 =over 4
1962
1963 =item *
1964
1965 If there is no leading space on the line, then the comment will not
1966 be indented, and otherwise it may be,
1967
1968 =item *
1969
1970 no new blank line will be
1971 inserted before such a comment, and
1972
1973 =item *
1974
1975 such a comment will never become
1976 a hanging side comment.
1977
1978 =back
1979
1980 For example, assuming C<@month_of_year> is
1981 left-adjusted:
1982
1983     @month_of_year = (    # -sbc (default)
1984         'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
1985     ##  'Dec', 'Nov'
1986         'Nov', 'Dec');
1987
1988 Without this convention, the above code would become
1989
1990     @month_of_year = (   # -nsbc
1991         'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
1992
1993         ##  'Dec', 'Nov'
1994         'Nov', 'Dec'
1995     );
1996
1997 which is not as clear.
1998 The default is to use B<-sbc>.  This may be deactivated with B<-nsbc>.
1999
2000 =item B<-sbcp=string>, B<--static-block-comment-prefix=string>
2001
2002 This parameter defines the prefix used to identify static block comments
2003 when the B<-sbc> parameter is set.  The default prefix is C<##>,
2004 corresponding to C<-sbcp=##>.  The prefix is actually part of a perl
2005 pattern used to match lines and it must either begin with C<#> or C<^#>.
2006 In the first case a prefix ^\s* will be added to match any leading
2007 whitespace, while in the second case the pattern will match only
2008 comments with no leading whitespace.  For example, to
2009 identify all comments as static block comments, one would use C<-sbcp=#>.
2010 To identify all left-adjusted comments as static block comments, use C<-sbcp='^#'>.
2011
2012 Please note that B<-sbcp> merely defines the pattern used to identify static
2013 block comments; it will not be used unless the switch B<-sbc> is set.  Also,
2014 please be aware that since this string is used in a perl regular expression
2015 which identifies these comments, it must enable a valid regular expression to
2016 be formed.
2017
2018 A pattern which can be useful is:
2019
2020     -sbcp=^#{2,}[^\s#]
2021
2022 This pattern requires a static block comment to have at least one character
2023 which is neither a # nor a space.  It allows a line containing only '#'
2024 characters to be rejected as a static block comment.  Such lines are often used
2025 at the start and end of header information in subroutines and should not be
2026 separated from the intervening comments, which typically begin with just a
2027 single '#'.
2028
2029 =item B<-osbc>, B<--outdent-static-block-comments>
2030
2031 The command B<-osbc> will cause static block comments to be outdented by 2
2032 spaces (or whatever B<-ci=n> has been set to), if possible.
2033
2034 =back
2035
2036 =item B<Static Side Comments>
2037
2038 Static side comments are side comments with a special leading pattern.
2039 This option can be useful for controlling how commented code is displayed
2040 when it is a side comment.
2041
2042 =over 4
2043
2044 =item B<-ssc>, B<--static-side-comments>
2045
2046 When B<-ssc> is used, a side comment with a static leading pattern, which is
2047 C<##> by default, will be spaced only a single space from previous
2048 character, and it will not be vertically aligned with other side comments.
2049
2050 The default is B<-nssc>.
2051
2052 =item B<-sscp=string>, B<--static-side-comment-prefix=string>
2053
2054 This parameter defines the prefix used to identify static side comments
2055 when the B<-ssc> parameter is set.  The default prefix is C<##>,
2056 corresponding to C<-sscp=##>.
2057
2058 Please note that B<-sscp> merely defines the pattern used to identify
2059 static side comments; it will not be used unless the switch B<-ssc> is
2060 set.  Also, note that this string is used in a perl regular expression
2061 which identifies these comments, so it must enable a valid regular
2062 expression to be formed.
2063
2064 =back
2065
2066 =back
2067
2068 =head2 Skipping Selected Sections of Code
2069
2070 Selected lines of code may be passed verbatim to the output without any
2071 formatting by marking the starting and ending lines with special comments.
2072 There are two options for doing this.  The first option is called
2073 B<--format-skipping> or B<-fs>, and the second option is called
2074 B<--code-skipping> or B<-cs>.
2075
2076 In both cases the lines of code will be output without any changes.
2077 The difference is that in B<--format-skipping>
2078 perltidy will still parse the marked lines of code and check for errors,
2079 whereas in B<--code-skipping> perltidy will simply pass the lines to the output without any checking.
2080
2081 Both of these features are enabled by default and are invoked with special
2082 comment markers.  B<--format-skipping> uses starting and ending markers '#<<<'
2083 and '#>>>', like this:
2084
2085  #<<<  format skipping: do not let perltidy change my nice formatting
2086     my @list = (1,
2087                 1, 1,
2088                 1, 2, 1,
2089                 1, 3, 3, 1,
2090                 1, 4, 6, 4, 1,);
2091  #>>>
2092
2093 B<--code-skipping> uses starting and ending markers '#<<V' and '#>>V', like
2094 this:
2095
2096  #<<V  code skipping: perltidy will pass this verbatim without error checking
2097
2098     token ident_digit {
2099         [ [ <?word> | _ | <?digit> ] <?ident_digit>
2100         |   <''>
2101         ]
2102     };
2103
2104  #>>V
2105
2106 Additional text may appear on the special comment lines provided that it
2107 is separated from the marker by at least one space, as in the above examples.
2108
2109 Any number of code-skipping or format-skipping sections may appear in a file.
2110 If an opening code-skipping or format-skipping comment is not followed by a
2111 corresponding closing comment, then skipping continues to the end of the file.
2112 If a closing code-skipping or format-skipping comment appears in a file but
2113 does not follow a corresponding opening comment, then it is treated as an
2114 ordinary comment without any special meaning.
2115
2116 It is recommended to use B<--code-skipping> only if you need to hide a block of
2117 an extended syntax which would produce errors if parsed by perltidy, and use
2118 B<--format-skipping> otherwise.  This is because the B<--format-skipping>
2119 option provides the benefits of error checking, and there are essentially no
2120 limitations on which lines to which it can be applied.  The B<--code-skipping>
2121 option, on the other hand, does not do error checking and its use is more
2122 restrictive because the code which remains, after skipping the marked lines,
2123 must be syntactically correct code with balanced containers.
2124
2125 These features should be used sparingly to avoid littering code with markers,
2126 but they can be helpful for working around occasional problems.
2127
2128 Note that it may be possible to avoid the use of B<--format-skipping> for the
2129 specific case of a comma-separated list of values, as in the above example, by
2130 simply inserting a blank or comment somewhere between the opening and closing
2131 parens.  See the section L<"Controlling List Formatting">.
2132
2133 The following sections describe the available controls for these options.  They
2134 should not normally be needed.
2135
2136 =over 4
2137
2138 =item B<-fs>,  B<--format-skipping>
2139
2140 As explained above, this flag, which is enabled by default, causes any code
2141 between special beginning and ending comment markers to be passed to the output
2142 without formatting.  The code between the comments is still checked for errors
2143 however.  The default beginning marker is #<<< and the default ending marker is
2144 #>>>.
2145
2146 Format skipping begins when a format skipping beginning comment is seen and
2147 continues until a format-skipping ending comment is found.
2148
2149 This feature can be disabled with B<-nfs>.   This should not normally be necessary.
2150
2151 =item B<-fsb=string>,  B<--format-skipping-begin=string>
2152
2153 This and the next parameter allow the special beginning and ending comments to
2154 be changed.  However, it is recommended that they only be changed if there is a
2155 conflict between the default values and some other use.  If they are used, it
2156 is recommended that they only be entered in a B<.perltidyrc> file, rather than
2157 on a command line.  This is because properly escaping these parameters on a
2158 command line can be difficult.
2159
2160 If changed comment markers do not appear to be working, use the B<-log> flag and
2161 examine the F<.LOG> file to see if and where they are being detected.
2162
2163 The B<-fsb=string> parameter may be used to change the beginning marker for
2164 format skipping.  The default is equivalent to -fsb='#<<<'.  The string that
2165 you enter must begin with a # and should be in quotes as necessary to get past
2166 the command shell of your system.  It is actually the leading text of a pattern
2167 that is constructed by appending a '\s', so you must also include backslashes
2168 for characters to be taken literally rather than as patterns.
2169
2170 Some examples show how example strings become patterns:
2171
2172  -fsb='#\{\{\{' becomes /^#\{\{\{\s/  which matches  #{{{ but not #{{{{
2173  -fsb='#\*\*'   becomes /^#\*\*\s/    which matches  #** but not #***
2174  -fsb='#\*{2,}' becomes /^#\*{2,}\s/  which matches  #** and #*****
2175
2176 =item B<-fse=string>,  B<--format-skipping-end=string>
2177
2178 The B<-fse=string> is the corresponding parameter used to change the
2179 ending marker for format skipping.  The default is equivalent to
2180 -fse='#<<<'.
2181
2182 The beginning and ending strings may be the same, but it is preferable
2183 to make them different for clarity.
2184
2185 =item B<-cs>,  B<--code-skipping>
2186
2187 As explained above, this flag, which is enabled by default, causes any code
2188 between special beginning and ending comment markers to be directly passed to
2189 the output without any error checking or formatting.  Essentially, perltidy
2190 treats it as if it were a block of arbitrary text.  The default beginning
2191 marker is #<<V and the default ending marker is #>>V.
2192
2193 This feature can be disabled with B<-ncs>.   This should not normally be
2194 necessary.
2195
2196 =item B<-csb=string>,  B<--code-skipping-begin=string>
2197
2198 This may be used to change the beginning comment for a B<--code-skipping> section, and its use is similar to the B<-fsb=string>.
2199 The default is equivalent to -csb='#<<V'.
2200
2201 =item B<-cse=string>,  B<--code-skipping-end=string>
2202
2203 This may be used to change the ending comment for a B<--code-skipping> section, and its use is similar to the B<-fse=string>.
2204 The default is equivalent to -cse='#>>V'.
2205
2206 =back
2207
2208 =head2 Line Break Control
2209
2210 The parameters in this and the next sections control breaks after
2211 non-blank lines of code.  Blank lines are controlled
2212 separately by parameters in the section L<"Blank Line Control">.
2213
2214 =over 4
2215
2216 =item B<-dnl>,  B<--delete-old-newlines>
2217
2218 By default, perltidy first deletes all old line break locations, and then it
2219 looks for good break points to match the desired line length.  Use B<-ndnl>
2220 or  B<--nodelete-old-newlines> to force perltidy to retain all old line break
2221 points.
2222
2223 =item B<-anl>,  B<--add-newlines>
2224
2225 By default, perltidy will add line breaks when necessary to create
2226 continuations of long lines and to improve the script appearance.  Use
2227 B<-nanl> or B<--noadd-newlines> to prevent any new line breaks.
2228
2229 This flag does not prevent perltidy from eliminating existing line
2230 breaks; see B<--freeze-newlines> to completely prevent changes to line
2231 break points.
2232
2233 =item B<-fnl>,  B<--freeze-newlines>
2234
2235 If you do not want any changes to the line breaks within
2236 lines of code in your script, set
2237 B<-fnl>, and they will remain fixed, and the rest of the commands in
2238 this section and sections
2239 L<"Controlling List Formatting">,
2240 L<"Retaining or Ignoring Existing Line Breaks">.
2241 You may want to use B<-noll> with this.
2242
2243 Note: If you also want to keep your blank lines exactly
2244 as they are, you can use the B<-fbl> flag which is described
2245 in the section L<"Blank Line Control">.
2246
2247 =back
2248
2249 =head2 Controlling Breaks at Braces, Parens, and Square Brackets
2250
2251 =over 4
2252
2253 =item B<-ce>,   B<--cuddled-else>
2254
2255 Enable the "cuddled else" style, in which C<else> and C<elsif> are
2256 follow immediately after the curly brace closing the previous block.
2257 The default is not to use cuddled elses, and is indicated with the flag
2258 B<-nce> or B<--nocuddled-else>.  Here is a comparison of the
2259 alternatives:
2260
2261   # -ce
2262   if ($task) {
2263       yyy();
2264   } else {
2265       zzz();
2266   }
2267
2268   # -nce (default)
2269   if ($task) {
2270         yyy();
2271   }
2272   else {
2273         zzz();
2274   }
2275
2276 In this example the keyword B<else> is placed on the same line which begins with
2277 the preceding closing block brace and is followed by its own opening block brace
2278 on the same line.  Other keywords and function names which are formatted with
2279 this "cuddled" style are B<elsif>, B<continue>, B<catch>, B<finally>.
2280
2281 Other block types can be formatted by specifying their names on a
2282 separate parameter B<-cbl>, described in a later section.
2283
2284 Cuddling between a pair of code blocks requires that the closing brace of the
2285 first block start a new line.  If this block is entirely on one line in the
2286 input file, it is necessary to decide if it should be broken to allow cuddling.
2287 This decision is controlled by the flag B<-cbo=n> discussed below.  The default
2288 and recommended value of B<-cbo=1> bases this decision on the first block in
2289 the chain.  If it spans multiple lines then cuddling is made and continues
2290 along the chain, regardless of the sizes of subsequent blocks. Otherwise, short
2291 lines remain intact.
2292
2293 So for example, the B<-ce> flag would not have any effect if the above snippet
2294 is rewritten as
2295
2296   if ($task) { yyy() }
2297   else {    zzz() }
2298
2299 If the first block spans multiple lines, then cuddling can be done and will
2300 continue for the subsequent blocks in the chain, as illustrated in the previous
2301 snippet.
2302
2303 If there are blank lines between cuddled blocks they will be eliminated.  If
2304 there are comments after the closing brace where cuddling would occur then
2305 cuddling will be prevented.  If this occurs, cuddling will restart later in the
2306 chain if possible.
2307
2308 =item B<-cb>,   B<--cuddled-blocks>
2309
2310 This flag is equivalent to B<-ce>.
2311
2312
2313 =item B<-cbl>,    B<--cuddled-block-list>
2314
2315 The built-in default cuddled block types are B<else, elsif, continue, catch, finally>.
2316
2317 Additional block types to which the B<-cuddled-blocks> style applies can be defined by
2318 this parameter.  This parameter is a character string, giving a list of
2319 block types separated by commas or spaces.  For example, to cuddle code blocks
2320 of type sort, map and grep, in addition to the default types, the string could
2321 be set to
2322
2323   -cbl="sort map grep"
2324
2325 or equivalently
2326
2327   -cbl=sort,map,grep
2328
2329 Note however that these particular block types are typically short so there might not be much
2330 opportunity for the cuddled format style.
2331
2332 Using commas avoids the need to protect spaces with quotes.
2333
2334 As a diagnostic check, the flag B<--dump-cuddled-block-list> or B<-dcbl> can be
2335 used to view the hash of values that are generated by this flag.
2336
2337 Finally, note that the B<-cbl> flag by itself merely specifies which blocks are formatted
2338 with the cuddled format. It has no effect unless this formatting style is activated with
2339 B<-ce>.
2340
2341 =item B<-cblx>,    B<--cuddled-block-list-exclusive>
2342
2343 When cuddled else formatting is selected with B<-ce>, setting this flag causes
2344 perltidy to ignore its built-in defaults and rely exclusively on the block types
2345 specified on the B<-cbl> flag described in the previous section.  For example,
2346 to avoid using cuddled B<catch> and B<finally>, which are among the defaults, the
2347 following set of parameters could be used:
2348
2349   perltidy -ce -cbl='else elsif continue' -cblx
2350
2351
2352 =item B<-cbo=n>, B<--cuddled-break-option=n>
2353
2354 Cuddled formatting is only possible between a pair of code blocks if the
2355 closing brace of the first block starts a new line. If a block is encountered
2356 which is entirely on a single line, and cuddled formatting is selected, it is
2357 necessary to make a decision as to whether or not to "break" the block, meaning
2358 to cause it to span multiple lines.  This parameter controls that decision. The
2359 options are:
2360
2361    cbo=0  Never force a short block to break.
2362    cbo=1  If the first of a pair of blocks is broken in the input file,
2363           then break the second [DEFAULT].
2364    cbo=2  Break open all blocks for maximal cuddled formatting.
2365
2366 The default and recommended value is B<cbo=1>.  With this value, if the starting
2367 block of a chain spans multiple lines, then a cascade of breaks will occur for
2368 remaining blocks causing the entire chain to be cuddled.
2369
2370 The option B<cbo=0> can produce erratic cuddling if there are numerous one-line
2371 blocks.
2372
2373 The option B<cbo=2> produces maximal cuddling but will not allow any short blocks.
2374
2375
2376 =item B<-bl>, B<--opening-brace-on-new-line>, or B<--brace-left>
2377
2378 Use the flag B<-bl> to place an opening block brace on a new line:
2379
2380   if ( $input_file eq '-' )
2381   {
2382       ...
2383   }
2384
2385 By default it applies to all structural blocks except B<sort map grep eval> and
2386 anonymous subs.
2387
2388 The default is B<-nbl> which places an opening brace on the same line as
2389 the keyword introducing it if possible.  For example,
2390
2391   # default
2392   if ( $input_file eq '-' ) {
2393      ...
2394   }
2395
2396 When B<-bl> is set, the blocks to which this applies can be controlled with the
2397 parameters B<--brace-left-list> and B<-brace-left-exclusion-list> described in the next sections.
2398
2399 =item B<-bll=s>, B<--brace-left-list=s>
2400
2401 Use this parameter to change the types of block braces for which the
2402 B<-bl> flag applies; see L<"Specifying Block Types">.  For example,
2403 B<-bll='if elsif else sub'> would apply it to only C<if/elsif/else>
2404 and named sub blocks.  The default is all blocks, B<-bll='*'>.
2405
2406 =item B<-blxl=s>, B<--brace-left-exclusion-list=s>
2407
2408 Use this parameter to exclude types of block braces for which the
2409 B<-bl> flag applies; see L<"Specifying Block Types">.  For example,
2410 the default settings B<-bll='*'> and B<-blxl='sort map grep eval asub'>
2411 mean all blocks except B<sort map grep eval> and anonymous sub blocks.
2412
2413 Note that the lists B<-bll=s> and B<-blxl=s> control the behavior of the
2414 B<-bl> flag but have no effect unless the B<-bl> flag is set.
2415
2416 =item B<-sbl>,    B<--opening-sub-brace-on-new-line>
2417
2418 The flag B<-sbl> provides a shortcut way to turn on B<-bl> just for named
2419 subs.  The same effect can be achieved by turning on B<-bl>
2420 with the block list set as B<-bll='sub'>.
2421
2422 For example,
2423
2424  perltidy -sbl
2425
2426 produces this result:
2427
2428  sub message
2429  {
2430     if (!defined($_[0])) {
2431         print("Hello, World\n");
2432     }
2433     else {
2434         print($_[0], "\n");
2435     }
2436  }
2437
2438 This flag is negated with B<-nsbl>, which is the default.
2439
2440 =item B<-asbl>,    B<--opening-anonymous-sub-brace-on-new-line>
2441
2442 The flag B<-asbl> is like the B<-sbl> flag except that it applies
2443 to anonymous sub's instead of named subs. For example
2444
2445  perltidy -asbl
2446
2447 produces this result:
2448
2449  $a = sub
2450  {
2451      if ( !defined( $_[0] ) ) {
2452          print("Hello, World\n");
2453      }
2454      else {
2455          print( $_[0], "\n" );
2456      }
2457  };
2458
2459 This flag is negated with B<-nasbl>, and the default is B<-nasbl>.
2460
2461 =item B<-bli>,    B<--brace-left-and-indent>
2462
2463 The flag B<-bli> is similar to the B<-bl> flag but in addition it causes one
2464 unit of continuation indentation ( see B<-ci> ) to be placed before
2465 an opening and closing block braces.
2466
2467 For example, perltidy -bli gives
2468
2469         if ( $input_file eq '-' )
2470           {
2471             important_function();
2472           }
2473
2474 By default, this extra indentation occurs for block types:
2475 B<if>, B<elsif>, B<else>, B<unless>, B<while>, B<for>, B<foreach>, B<do>, and
2476 also B<named subs> and blocks preceded by a B<label>.  The next item shows how to
2477 change this.
2478
2479 B<Note>: The B<-bli> flag is similar to the B<-bl> flag, with the difference being
2480 that braces get indented.  But these two flags are implemented independently,
2481 and have different default settings for historical reasons.  If desired, a
2482 mixture of effects can be achieved if desired by turning them both on with
2483 different B<-list> settings.  In the event that both settings are selected for
2484 a certain block type, the B<-bli> style has priority.
2485
2486 =item B<-blil=s>,    B<--brace-left-and-indent-list=s>
2487
2488 Use this parameter to change the types of block braces for which the
2489 B<-bli> flag applies; see L<"Specifying Block Types">.
2490
2491 The default is B<-blil='if else elsif unless while for foreach do : sub'>.
2492
2493 =item B<-blixl=s>, B<--brace-left-and-indent-exclusion-list=s>
2494
2495 Use this parameter to exclude types of block braces for which the B<-bli> flag
2496 applies; see L<"Specifying Block Types">.
2497
2498 This might be useful in conjunction with selecting all blocks B<-blil='*'>.
2499 The default setting is B<-blixl=' '>, which does not exclude any blocks.
2500
2501 Note that the two parameters B<-blil> and B<-blixl> control the behavior of
2502 the B<-bli> flag but have no effect unless the B<-bli> flag is set.
2503
2504 =item B<-bar>,    B<--opening-brace-always-on-right>
2505
2506 The default style, B<-nbl> places the opening code block brace on a new
2507 line if it does not fit on the same line as the opening keyword, like
2508 this:
2509
2510         if ( $bigwasteofspace1 && $bigwasteofspace2
2511           || $bigwasteofspace3 && $bigwasteofspace4 )
2512         {
2513             big_waste_of_time();
2514         }
2515
2516 To force the opening brace to always be on the right, use the B<-bar>
2517 flag.  In this case, the above example becomes
2518
2519         if ( $bigwasteofspace1 && $bigwasteofspace2
2520           || $bigwasteofspace3 && $bigwasteofspace4 ) {
2521             big_waste_of_time();
2522         }
2523
2524 A conflict occurs if both B<-bl> and B<-bar> are specified.
2525
2526 =item B<-otr>,  B<--opening-token-right> and related flags
2527
2528 The B<-otr> flag is a hint that perltidy should not place a break between a
2529 comma and an opening token.  For example:
2530
2531     # default formatting
2532     push @{ $self->{$module}{$key} },
2533       {
2534         accno       => $ref->{accno},
2535         description => $ref->{description}
2536       };
2537
2538     # perltidy -otr
2539     push @{ $self->{$module}{$key} }, {
2540         accno       => $ref->{accno},
2541         description => $ref->{description}
2542       };
2543
2544 The flag B<-otr> is actually an abbreviation for three other flags
2545 which can be used to control parens, hash braces, and square brackets
2546 separately if desired:
2547
2548   -opr  or --opening-paren-right
2549   -ohbr or --opening-hash-brace-right
2550   -osbr or --opening-square-bracket-right
2551
2552 =item B<-bbhb=n>,  B<--break-before-hash-brace=n> and related flags
2553
2554 When a list of items spans multiple lines, the default formatting is to place
2555 the opening brace (or other container token) at the end of the starting line,
2556 like this:
2557
2558     $romanNumerals = {
2559         one   => 'I',
2560         two   => 'II',
2561         three => 'III',
2562         four  => 'IV',
2563     };
2564
2565 This flag can change the default behavior to cause a line break to be placed
2566 before the opening brace according to the value given to the integer B<n>:
2567
2568   -bbhb=0 never break [default]
2569   -bbhb=1 stable: break if the input script had a break
2570   -bbhb=2 break if list is 'complex' (see note below)
2571   -bbhb=3 always break
2572
2573 For example,
2574
2575     # perltidy -bbhb=3
2576     $romanNumerals =
2577       {
2578         one   => 'I',
2579         two   => 'II',
2580         three => 'III',
2581         four  => 'IV',
2582       };
2583
2584 There are several points to note about this flag:
2585
2586 =over 4
2587
2588 =item *
2589
2590 This parameter only applies if the opening brace is preceded by an '='
2591 or '=>'.
2592
2593 =item *
2594
2595 This parameter only applies if the contents of the container looks like a list.
2596 The contents need to contain some commas or '=>'s at the next interior level to
2597 be considered a list.
2598
2599 =item *
2600
2601 For the B<n=2> option, a list is considered 'complex' if it is part of a nested list
2602 structure which spans multiple lines in the input file.
2603
2604 =item *
2605
2606 If multiple opening tokens have been 'welded' together with the B<-wn> parameter, then
2607 this parameter has no effect.
2608
2609 =item *
2610
2611 The indentation of the braces will normally be one level of continuation
2612 indentation by default.  This can be changed with the parameter
2613 B<-bbhbi=n> in the next section.
2614
2615 =item *
2616
2617 Similar flags for controlling parens and square brackets are given in the subsequent section.
2618
2619 =back
2620
2621 =item B<-bbhbi=n>,  B<--break-before-hash-brace-and-indent=n>
2622
2623 This flag is a companion to B<-bbhb=n> for controlling the indentation of an opening hash brace
2624 which is placed on a new line by that parameter.  The indentation is as follows:
2625
2626   -bbhbi=0 one continuation level [default]
2627   -bbhbi=1 outdent by one continuation level
2628   -bbhbi=2 indent one full indentation level
2629
2630 For example:
2631
2632     # perltidy -bbhb=3 -bbhbi=1
2633     $romanNumerals =
2634     {
2635         one   => 'I',
2636         two   => 'II',
2637         three => 'III',
2638         four  => 'IV',
2639     };
2640
2641     # perltidy -bbhb=3 -bbhbi=2
2642     $romanNumerals =
2643         {
2644         one   => 'I',
2645         two   => 'II',
2646         three => 'III',
2647         four  => 'IV',
2648         };
2649
2650 Note that this parameter has no effect unless B<-bbhb=n> is also set.
2651
2652 =item B<-bbsb=n>,  B<--break-before-square-bracket=n>
2653
2654 This flag is similar to the flag described above, except it applies to lists contained within square brackets.
2655
2656   -bbsb=0 never break [default]
2657   -bbsb=1 stable: break if the input script had a break
2658   -bbsb=2 break if list is 'complex' (part of nested list structure)
2659   -bbsb=3 always break
2660
2661 =item B<-bbsbi=n>,  B<--break-before-square-bracket-and-indent=n>
2662
2663 This flag is a companion to B<-bbsb=n> for controlling the indentation of an opening square bracket
2664 which is placed on a new line by that parameter.  The indentation is as follows:
2665
2666   -bbsbi=0 one continuation level [default]
2667   -bbsbi=1 outdent by one continuation level
2668   -bbsbi=2 indent one full indentation level
2669
2670 =item B<-bbp=n>,  B<--break-before-paren=n>
2671
2672 This flag is similar to B<-bbhb=n>, described above, except it applies to lists contained within parens.
2673
2674   -bbp=0 never break [default]
2675   -bbp=1 stable: break if the input script had a break
2676   -bpb=2 break if list is 'complex' (part of nested list structure)
2677   -bbp=3 always break
2678
2679 =item B<-bbpi=n>,  B<--break-before-paren-and-indent=n>
2680
2681 This flag is a companion to B<-bbp=n> for controlling the indentation of an opening paren
2682 which is placed on a new line by that parameter.  The indentation is as follows:
2683
2684   -bbpi=0 one continuation level [default]
2685   -bbpi=1 outdent by one continuation level
2686   -bbpi=2 indent one full indentation level
2687
2688 =back
2689
2690 =head2 Welding
2691
2692 =over 4
2693
2694 =item B<-wn>,  B<--weld-nested-containers>
2695
2696 The B<-wn> flag causes closely nested pairs of opening and closing container
2697 symbols (curly braces, brackets, or parens) to be "welded" together, meaning
2698 that they are treated as if combined into a single unit, with the indentation
2699 of the innermost code reduced to be as if there were just a single container
2700 symbol.
2701
2702 For example:
2703
2704         # default formatting
2705         do {
2706             {
2707                 next if $x == $y;
2708             }
2709         } until $x++ > $z;
2710
2711         # perltidy -wn
2712         do { {
2713             next if $x == $y;
2714         } } until $x++ > $z;
2715
2716 When this flag is set perltidy makes a preliminary pass through the file and
2717 identifies all nested pairs of containers.  To qualify as a nested pair, the
2718 closing container symbols must be immediately adjacent and the opening symbols
2719 must either (1) be adjacent as in the above example, or (2) have an anonymous
2720 sub declaration following an outer opening container symbol which is not a
2721 code block brace, or (3) have an outer opening paren separated from the inner
2722 opening symbol by any single non-container symbol or something that looks like
2723 a function evaluation, as illustrated in the next examples. An additional
2724 option (4) which can be turned on with the flag B<--weld-fat-comma> is when the opening container symbols are separated by a hash key and fat comma (=>).
2725
2726 Any container symbol may serve as both the inner container of one pair and as
2727 the outer container of an adjacent pair. Consequently, any number of adjacent
2728 opening or closing symbols may join together in weld.  For example, here are
2729 three levels of wrapped function calls:
2730
2731         # default formatting
2732         my (@date_time) = Localtime(
2733             Date_to_Time(
2734                 Add_Delta_DHMS(
2735                     $year, $month,  $day, $hour, $minute, $second,
2736                     '0',   $offset, '0',  '0'
2737                 )
2738             )
2739         );
2740
2741         # perltidy -wn
2742         my (@date_time) = Localtime( Date_to_Time( Add_Delta_DHMS(
2743             $year, $month,  $day, $hour, $minute, $second,
2744             '0',   $offset, '0',  '0'
2745         ) ) );
2746
2747 Notice how the indentation of the inner lines are reduced by two levels in this
2748 case.  This example also shows the typical result of this formatting, namely it
2749 is a sandwich consisting of an initial opening layer, a central section of any
2750 complexity forming the "meat" of the sandwich, and a final closing layer.  This
2751 predictable structure helps keep the compacted structure readable.
2752
2753 The inner sandwich layer is required to be at least one line thick.  If this
2754 cannot be achieved, welding does not occur.  This constraint can cause
2755 formatting to take a couple of iterations to stabilize when it is first applied
2756 to a script. The B<-conv> flag can be used to insure that the final format is
2757 achieved in a single run.
2758
2759 Here is an example illustrating a welded container within a welded containers:
2760
2761         # default formatting
2762         $x->badd(
2763             bmul(
2764                 $class->new(
2765                     abs(
2766                         $sx * int( $xr->numify() ) & $sy * int( $yr->numify() )
2767                     )
2768                 ),
2769                 $m
2770             )
2771         );
2772
2773         # perltidy -wn
2774         $x->badd( bmul(
2775             $class->new( abs(
2776                 $sx * int( $xr->numify() ) & $sy * int( $yr->numify() )
2777             ) ),
2778             $m
2779         ) );
2780
2781 The welded closing tokens are by default on a separate line but this can be
2782 modified with the B<-vtc=n> flag (described in the next section).  For example,
2783 the same example adding B<-vtc=2> is
2784
2785         # perltidy -wn -vtc=2
2786         $x->badd( bmul(
2787             $class->new( abs(
2788                 $sx * int( $xr->numify() ) & $sy * int( $yr->numify() ) ) ),
2789             $m ) );
2790
2791 This format option is quite general but there are some limitations.
2792
2793 One limitation is that any line length limit still applies and can cause long
2794 welded sections to be broken into multiple lines.
2795
2796 Another limitation is that an opening symbol which delimits quoted text cannot
2797 be included in a welded pair.  This is because quote delimiters are treated
2798 specially in perltidy.
2799
2800 Finally, the stacking of containers defined by this flag have priority over
2801 any other container stacking flags.  This is because any welding is done first.
2802
2803 =item B<-wfc>,  B<--weld-fat-comma >
2804
2805 When the B<-wfc> flag is set, along with B<-wn>, perltidy is allowed to weld
2806 an opening paren to an inner opening container when they are separated by a hash key and fat comma (=>). for example
2807
2808     # perltidy -wn -wfc
2809     elf->call_method( method_name_foo => {
2810         some_arg1       => $foo,
2811         some_other_arg3 => $bar->{'baz'},
2812     } );
2813
2814 This option is off by default.
2815
2816 =item B<-wnxl=s>,  B<--weld-nested-exclusion-list>
2817
2818 The B<-wnxl=s> flag provides some control over the types of containers which
2819 can be welded.  The B<-wn> flag by default is "greedy" in welding adjacent
2820 containers.  If it welds more types of containers than desired, this flag
2821 provides a capability to reduce the amount of welding by specifying a list
2822 of things which should B<not> be welded.
2823
2824 The logic in perltidy to apply this is straightforward.  As each container
2825 token is being considered for joining a weld, any exclusion rules are consulted
2826 and used to reject the weld if necessary.
2827
2828 This list is a string with space-separated items.  Each item consists of up to
2829 three pieces of information: (1) an optional position, (2) an optional
2830 preceding type, and (3) a container type.
2831
2832 The only required piece of information is a container type, which is one of
2833 '(', '[', '{' or 'q'.  The first three of these are container tokens and the
2834 last represents a quoted list.  For example the string
2835
2836   -wnxl='[ { q'
2837
2838 means do B<NOT> include square-brackets, braces, or quotes in any welds.  The only unspecified
2839 container is '(', so this string means that only welds involving parens will be made.
2840
2841 To illustrate, following welded snippet consists of a chain of three welded
2842 containers with types '(' '[' and 'q':
2843
2844     # perltidy -wn
2845     skip_symbols( [ qw(
2846         Perl_dump_fds
2847         Perl_ErrorNo
2848         Perl_GetVars
2849         PL_sys_intern
2850     ) ] );
2851
2852 Even though the qw term uses parens as the quote delimiter, it has a special
2853 type 'q' here. If it appears in a weld it always appears at the end of the
2854 welded chain.
2855
2856 Any of the container types '[', '{', and '(' may be prefixed with a position
2857 indicator which is either '^', to indicate the first token of a welded
2858 sequence, or '.', to indicate an interior token of a welded sequence.  (Since
2859 a quoted string 'q' always ends a chain it does need a position indicator).
2860
2861 For example, if we do not want a sequence of welded containers to start with a
2862 square bracket we could use
2863
2864   -wnxl='^['
2865
2866 In the above snippet, there is a square bracket but it does not start the chain,
2867 so the formatting would be unchanged if it were formatted with this restriction.
2868
2869 A third optional item of information which can be given is an alphanumeric
2870 letter which is used to limit the selection further depending on the type of
2871 token immediately before the container.  If given, it goes just before the
2872 container symbol.  The possible letters are currently 'k', 'K', 'f', 'F',
2873 'w', and 'W', with these meanings:
2874
2875  'k' matches if the previous nonblank token is a perl built-in keyword (such as 'if', 'while'),
2876  'K' matches if 'k' does not, meaning that the previous token is not a keyword.
2877  'f' matches if the previous token is a function other than a keyword.
2878  'F' matches if 'f' does not.
2879  'w' matches if either 'k' or 'f' match.
2880  'W' matches if 'w' does not.
2881
2882 For example, compare
2883
2884         # perltidy -wn
2885         if ( defined( $_Cgi_Query{
2886             $Config{'methods'}{'authentication'}{'remote'}{'cgi'}{'username'}
2887         } ) )
2888
2889 with
2890
2891         # perltidy -wn -wnxl='^K( {'
2892         if ( defined(
2893             $_Cgi_Query{ $Config{'methods'}{'authentication'}{'remote'}{'cgi'}
2894                   {'username'} }
2895         ) )
2896
2897 The first case does maximum welding. In the second case the leading paren is
2898 retained by the rule (it would have been rejected if preceded by a non-keyword)
2899 but the curly brace is rejected by the rule.
2900
2901 Here are some additional example strings and their meanings:
2902
2903     '^('   - the weld must not start with a paren
2904     '.('   - the second and later tokens may not be parens
2905     '.w('  - the second and later tokens may not keyword or function call parens
2906     '('    - no parens in a weld
2907     '^K('  - exclude a leading paren preceded by a non-keyword
2908     '.k('  - exclude a secondary paren preceded by a keyword
2909     '[ {'  - exclude all brackets and braces
2910     '[ ( ^K{' - exclude everything except nested structures like do {{  ... }}
2911
2912
2913 =item B<Vertical tightness> of non-block curly braces, parentheses, and square brackets.
2914
2915 These parameters control what shall be called vertical tightness.  Here are the
2916 main points:
2917
2918 =over 4
2919
2920 =item *
2921
2922 Opening tokens (except for block braces) are controlled by B<-vt=n>, or
2923 B<--vertical-tightness=n>, where
2924
2925  -vt=0 always break a line after opening token (default).
2926  -vt=1 do not break unless this would produce more than one
2927          step in indentation in a line.
2928  -vt=2 never break a line after opening token
2929
2930 =item *
2931
2932 You must also use the B<-lp> flag when you use the B<-vt> flag; the
2933 reason is explained below.
2934
2935 =item *
2936
2937 Closing tokens (except for block braces) are controlled by B<-vtc=n>, or
2938 B<--vertical-tightness-closing=n>, where
2939
2940  -vtc=0 always break a line before a closing token (default),
2941  -vtc=1 do not break before a closing token which is followed
2942         by a semicolon or another closing token, and is not in
2943         a list environment.
2944  -vtc=2 never break before a closing token.
2945  -vtc=3 Like -vtc=1 except always break before a closing token
2946         if the corresponding opening token follows an = or =>.
2947
2948 The rules for B<-vtc=1> and B<-vtc=3> are designed to maintain a reasonable
2949 balance between tightness and readability in complex lists.
2950
2951 =item *
2952
2953 Different controls may be applied to different token types,
2954 and it is also possible to control block braces; see below.
2955
2956 =item *
2957
2958 Finally, please note that these vertical tightness flags are merely
2959 hints to the formatter, and it cannot always follow them.  Things which
2960 make it difficult or impossible include comments, blank lines, blocks of
2961 code within a list, and possibly the lack of the B<-lp> parameter.
2962 Also, these flags may be ignored for very small lists (2 or 3 lines in
2963 length).
2964
2965 =back
2966
2967 Here are some examples:
2968
2969     # perltidy -lp -vt=0 -vtc=0
2970     %romanNumerals = (
2971                        one   => 'I',
2972                        two   => 'II',
2973                        three => 'III',
2974                        four  => 'IV',
2975     );
2976
2977     # perltidy -lp -vt=1 -vtc=0
2978     %romanNumerals = ( one   => 'I',
2979                        two   => 'II',
2980                        three => 'III',
2981                        four  => 'IV',
2982     );
2983
2984     # perltidy -lp -vt=1 -vtc=1
2985     %romanNumerals = ( one   => 'I',
2986                        two   => 'II',
2987                        three => 'III',
2988                        four  => 'IV', );
2989
2990     # perltidy -vtc=3
2991     my_function(
2992         one   => 'I',
2993         two   => 'II',
2994         three => 'III',
2995         four  => 'IV', );
2996
2997     # perltidy -vtc=3
2998     %romanNumerals = (
2999         one   => 'I',
3000         two   => 'II',
3001         three => 'III',
3002         four  => 'IV',
3003     );
3004
3005 In the last example for B<-vtc=3>, the opening paren is preceded by an equals
3006 so the closing paren is placed on a new line.
3007
3008 The difference between B<-vt=1> and B<-vt=2> is shown here:
3009
3010     # perltidy -lp -vt=1
3011     $init->add(
3012                 mysprintf( "(void)find_threadsv(%s);",
3013                            cstring( $threadsv_names[ $op->targ ] )
3014                 )
3015     );
3016
3017     # perltidy -lp -vt=2
3018     $init->add( mysprintf( "(void)find_threadsv(%s);",
3019                            cstring( $threadsv_names[ $op->targ ] )
3020                 )
3021     );
3022
3023 With B<-vt=1>, the line ending in C<add(> does not combine with the next
3024 line because the next line is not balanced.  This can help with
3025 readability, but B<-vt=2> can be used to ignore this rule.
3026
3027 The tightest, and least readable, code is produced with both C<-vt=2> and
3028 C<-vtc=2>:
3029
3030     # perltidy -lp -vt=2 -vtc=2
3031     $init->add( mysprintf( "(void)find_threadsv(%s);",
3032                            cstring( $threadsv_names[ $op->targ ] ) ) );
3033
3034 Notice how the code in all of these examples collapses vertically as
3035 B<-vt> increases, but the indentation remains unchanged.  This is
3036 because perltidy implements the B<-vt> parameter by first formatting as
3037 if B<-vt=0>, and then simply overwriting one output line on top of the
3038 next, if possible, to achieve the desired vertical tightness.  The
3039 B<-lp> indentation style has been designed to allow this vertical
3040 collapse to occur, which is why it is required for the B<-vt> parameter.
3041
3042 The B<-vt=n> and B<-vtc=n> parameters apply to each type of container
3043 token.  If desired, vertical tightness controls can be applied
3044 independently to each of the closing container token types.
3045
3046 The parameters for controlling parentheses are B<-pvt=n> or
3047 B<--paren-vertical-tightness=n>, and B<-pvtc=n> or
3048 B<--paren-vertical-tightness-closing=n>.
3049
3050 Likewise, the parameters for square brackets are B<-sbvt=n> or
3051 B<--square-bracket-vertical-tightness=n>, and B<-sbvtc=n> or
3052 B<--square-bracket-vertical-tightness-closing=n>.
3053
3054 Finally, the parameters for controlling non-code block braces are
3055 B<-bvt=n> or B<--brace-vertical-tightness=n>, and B<-bvtc=n> or
3056 B<--brace-vertical-tightness-closing=n>.
3057
3058 In fact, the parameter B<-vt=n> is actually just an abbreviation for
3059 B<-pvt=n -bvt=n sbvt=n>, and likewise B<-vtc=n> is an abbreviation
3060 for B<-pvtc=n -bvtc=n -sbvtc=n>.
3061
3062 =item B<-bbvt=n> or B<--block-brace-vertical-tightness=n>
3063
3064 The B<-bbvt=n> flag is just like the B<-vt=n> flag but applies
3065 to opening code block braces.
3066
3067  -bbvt=0 break after opening block brace (default).
3068  -bbvt=1 do not break unless this would produce more than one
3069          step in indentation in a line.
3070  -bbvt=2 do not break after opening block brace.
3071
3072 It is necessary to also use either B<-bl> or B<-bli> for this to work,
3073 because, as with other vertical tightness controls, it is implemented by
3074 simply overwriting a line ending with an opening block brace with the
3075 subsequent line.  For example:
3076
3077     # perltidy -bli -bbvt=0
3078     if ( open( FILE, "< $File" ) )
3079       {
3080         while ( $File = <FILE> )
3081           {
3082             $In .= $File;
3083             $count++;
3084           }
3085         close(FILE);
3086       }
3087
3088     # perltidy -bli -bbvt=1
3089     if ( open( FILE, "< $File" ) )
3090       { while ( $File = <FILE> )
3091           { $In .= $File;
3092             $count++;
3093           }
3094         close(FILE);
3095       }
3096
3097 By default this applies to blocks associated with keywords B<if>,
3098 B<elsif>, B<else>, B<unless>, B<for>, B<foreach>, B<sub>, B<while>,
3099 B<until>, and also with a preceding label.  This can be changed with
3100 the parameter B<-bbvtl=string>, or
3101 B<--block-brace-vertical-tightness-list=string>, where B<string> is a
3102 space-separated list of block types.  For more information on the
3103 possible values of this string, see L<"Specifying Block Types">
3104
3105 For example, if we want to just apply this style to C<if>,
3106 C<elsif>, and C<else> blocks, we could use
3107 C<perltidy -bli -bbvt=1 -bbvtl='if elsif else'>.
3108
3109 There is no vertical tightness control for closing block braces; with
3110 one exception they will be placed on separate lines.
3111 The exception is that a cascade of closing block braces may
3112 be stacked on a single line.  See B<-scbb>.
3113
3114 =item B<-sot>,  B<--stack-opening-tokens> and related flags
3115
3116 The B<-sot> flag tells perltidy to "stack" opening tokens
3117 when possible to avoid lines with isolated opening tokens.
3118
3119 For example:
3120
3121     # default
3122     $opt_c = Text::CSV_XS->new(
3123         {
3124             binary       => 1,
3125             sep_char     => $opt_c,
3126             always_quote => 1,
3127         }
3128     );
3129
3130     # -sot
3131     $opt_c = Text::CSV_XS->new( {
3132             binary       => 1,
3133             sep_char     => $opt_c,
3134             always_quote => 1,
3135         }
3136     );
3137
3138 For detailed control of individual closing tokens the following
3139 controls can be used:
3140
3141   -sop  or --stack-opening-paren
3142   -sohb or --stack-opening-hash-brace
3143   -sosb or --stack-opening-square-bracket
3144   -sobb or --stack-opening-block-brace
3145
3146 The flag B<-sot> is an abbreviation for B<-sop -sohb -sosb>.
3147
3148 The flag B<-sobb> is an abbreviation for B<-bbvt=2 -bbvtl='*'>.  This
3149 will case a cascade of opening block braces to appear on a single line,
3150 although this an uncommon occurrence except in test scripts.
3151
3152 =item B<-sct>,  B<--stack-closing-tokens> and related flags
3153
3154 The B<-sct> flag tells perltidy to "stack" closing tokens
3155 when possible to avoid lines with isolated closing tokens.
3156
3157 For example:
3158
3159     # default
3160     $opt_c = Text::CSV_XS->new(
3161         {
3162             binary       => 1,
3163             sep_char     => $opt_c,
3164             always_quote => 1,
3165         }
3166     );
3167
3168     # -sct
3169     $opt_c = Text::CSV_XS->new(
3170         {
3171             binary       => 1,
3172             sep_char     => $opt_c,
3173             always_quote => 1,
3174         } );
3175
3176 The B<-sct> flag is somewhat similar to the B<-vtc> flags, and in some
3177 cases it can give a similar result.  The difference is that the B<-vtc>
3178 flags try to avoid lines with leading opening tokens by "hiding" them at
3179 the end of a previous line, whereas the B<-sct> flag merely tries to
3180 reduce the number of lines with isolated closing tokens by stacking them
3181 but does not try to hide them.  For example:
3182
3183     # -vtc=2
3184     $opt_c = Text::CSV_XS->new(
3185         {
3186             binary       => 1,
3187             sep_char     => $opt_c,
3188             always_quote => 1, } );
3189
3190 For detailed control of the stacking of individual closing tokens the
3191 following controls can be used:
3192
3193   -scp  or --stack-closing-paren
3194   -schb or --stack-closing-hash-brace
3195   -scsb or --stack-closing-square-bracket
3196   -scbb or --stack-closing-block-brace
3197
3198 The flag B<-sct> is an abbreviation for stacking the non-block closing
3199 tokens, B<-scp -schb -scsb>.
3200
3201 Stacking of closing block braces, B<-scbb>, causes a cascade of isolated
3202 closing block braces to be combined into a single line as in the following
3203 example:
3204
3205     # -scbb:
3206     for $w1 (@w1) {
3207         for $w2 (@w2) {
3208             for $w3 (@w3) {
3209                 for $w4 (@w4) {
3210                     push( @lines, "$w1 $w2 $w3 $w4\n" );
3211                 } } } }
3212
3213 To simplify input even further for the case in which both opening and closing
3214 non-block containers are stacked, the flag B<-sac> or B<--stack-all-containers>
3215 is an abbreviation for B<-sot -sct>.
3216
3217 Please note that if both opening and closing tokens are to be stacked, then the
3218 newer flag B<-weld-nested-containers> may be preferable because it insures that
3219 stacking is always done symmetrically.  It also removes an extra level of
3220 unnecessary indentation within welded containers.  It is able to do this
3221 because it works on formatting globally rather than locally, as the B<-sot> and
3222 B<-sct> flags do.
3223
3224 =back
3225
3226 =head2 Breaking Before or After Operators
3227
3228 Four command line parameters provide some control over whether
3229 a line break should be before or after specific token types.
3230 Two parameters give detailed control:
3231
3232 B<-wba=s> or B<--want-break-after=s>, and
3233
3234 B<-wbb=s> or B<--want-break-before=s>.
3235
3236 These parameters are each followed by a quoted string, B<s>, containing
3237 a list of token types (separated only by spaces).  No more than one of each
3238 of these parameters should be specified, because repeating a
3239 command-line parameter always overwrites the previous one before
3240 perltidy ever sees it.
3241
3242 By default, perltidy breaks B<after> these token types:
3243   % + - * / x != == >= <= =~ !~ < >  | &
3244   = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x=
3245
3246 And perltidy breaks B<before> these token types by default:
3247   . << >> -> && || //
3248
3249 To illustrate, to cause a break after a concatenation operator, C<'.'>,
3250 rather than before it, the command line would be
3251
3252   -wba="."
3253
3254 As another example, the following command would cause a break before
3255 math operators C<'+'>, C<'-'>, C<'/'>, and C<'*'>:
3256
3257   -wbb="+ - / *"
3258
3259 These commands should work well for most of the token types that perltidy uses
3260 (use B<--dump-token-types> for a list).  Also try the B<-D> flag on a short
3261 snippet of code and look at the .DEBUG file to see the tokenization.  However,
3262 for a few token types there may be conflicts with hardwired logic which cause
3263 unexpected results.  One example is curly braces, which should be controlled
3264 with the parameter B<bl> provided for that purpose.
3265
3266 B<WARNING> Be sure to put these tokens in quotes to avoid having them
3267 misinterpreted by your command shell.
3268
3269 Two additional parameters are available which, though they provide no further
3270 capability, can simplify input are:
3271
3272 B<-baao> or B<--break-after-all-operators>,
3273
3274 B<-bbao> or B<--break-before-all-operators>.
3275
3276 The -baao sets the default to be to break after all of the following operators:
3277
3278     % + - * / x != == >= <= =~ !~ < > | &
3279     = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x=
3280     . : ? && || and or err xor
3281
3282 and the B<-bbao> flag sets the default to break before all of these operators.
3283 These can be used to define an initial break preference which can be fine-tuned
3284 with the B<-wba> and B<-wbb> flags.  For example, to break before all operators
3285 except an B<=> one could use --bbao -wba='=' rather than listing every
3286 single perl operator except B<=> on a -wbb flag.
3287
3288 =over 4
3289
3290 =item B<-bal=n, --break-after-labels=n>
3291
3292 This flag controls whether or not a line break occurs after a label. There
3293 are three possible values for B<n>:
3294
3295   -bal=0  break if there is a break in the input [DEFAULT]
3296   -bal=1  always break after a label
3297   -bal=2  never break after a label
3298
3299 For example,
3300
3301       # perltidy -bal=1
3302       RETURN:
3303         return;
3304
3305       # perltidy -bal=2
3306       RETURN: return;
3307
3308 =back
3309
3310 =head2 Controlling List Formatting
3311
3312 Perltidy attempts to format lists of comma-separated values in tables which
3313 look good.  Its default algorithms usually work well, but sometimes they don't.
3314 In this case, there are several methods available to control list formatting.
3315
3316 A very simple way to prevent perltidy from changing the line breaks
3317 within a comma-separated list of values is to insert a blank line,
3318 comment, or side-comment anywhere between the opening and closing
3319 parens (or braces or brackets).   This causes perltidy to skip
3320 over its list formatting logic.  (The reason is that any of
3321 these items put a constraint on line breaks, and perltidy
3322 needs complete control over line breaks within a container to
3323 adjust a list layout).  For example, let us consider
3324
3325     my @list = (1,
3326                 1, 1,
3327                 1, 2, 1,
3328                 1, 3, 3, 1,
3329                 1, 4, 6, 4, 1,);
3330
3331 The default formatting, which allows a maximum line length of 80,
3332 will flatten this down to one line:
3333
3334     # perltidy (default)
3335     my @list = ( 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, );
3336
3337 This formatting loses the nice structure.  If we place a side comment anywhere
3338 between the opening and closing parens, the original line break points are
3339 retained.  For example,
3340
3341     my @list = (
3342         1,    # a side comment forces the original line breakpoints to be kept
3343         1, 1,
3344         1, 2, 1,
3345         1, 3, 3, 1,
3346         1, 4, 6, 4, 1,
3347     );
3348
3349 The side comment can be a single hash symbol without any text.
3350 We could achieve the same result with a blank line or full comment
3351 anywhere between the opening and closing parens.  Vertical alignment
3352 of the list items will still occur if possible.
3353
3354 For another possibility see
3355 the -fs flag in L<"Skipping Selected Sections of Code">.
3356
3357 =over 4
3358
3359 =item B<-boc>,  B<--break-at-old-comma-breakpoints>
3360
3361 The B<-boc> flag is another way to prevent comma-separated lists from being
3362 reformatted.  Using B<-boc> on the above example, plus additional flags to retain
3363 the original style, yields
3364
3365     # perltidy -boc -lp -pt=2 -vt=1 -vtc=1
3366     my @list = (1,
3367                 1, 1,
3368                 1, 2, 1,
3369                 1, 3, 3, 1,
3370                 1, 4, 6, 4, 1,);
3371
3372 A disadvantage of this flag compared to the methods discussed above is that all
3373 tables in the file must already be nicely formatted.
3374
3375 =item B<-mft=n>,  B<--maximum-fields-per-table=n>
3376
3377 If B<n> is a positive number, and the computed number of fields for any table
3378 exceeds B<n>, then it will be reduced to B<n>.  This parameter might be used on
3379 a small section of code to force a list to have a particular number of fields
3380 per line, and then either the B<-boc> flag could be used to retain this
3381 formatting, or a single comment could be introduced somewhere to freeze the
3382 formatting in future applications of perltidy. For example
3383
3384     # perltidy -mft=2
3385     @month_of_year = (
3386         'Jan', 'Feb',
3387         'Mar', 'Apr',
3388         'May', 'Jun',
3389         'Jul', 'Aug',
3390         'Sep', 'Oct',
3391         'Nov', 'Dec'
3392     );
3393
3394 The default value is B<n=0>, which does not place a limit on the
3395 number of fields in a table.
3396
3397 =item B<-cab=n>,  B<--comma-arrow-breakpoints=n>
3398
3399 A comma which follows a comma arrow, '=>', is given special
3400 consideration.  In a long list, it is common to break at all such
3401 commas.  This parameter can be used to control how perltidy breaks at
3402 these commas.  (However, it will have no effect if old comma breaks are
3403 being forced because B<-boc> is used).  The possible values of B<n> are:
3404
3405  n=0 break at all commas after =>
3406  n=1 stable: break at all commas after => if container is open,
3407      EXCEPT FOR one-line containers
3408  n=2 break at all commas after =>, BUT try to form the maximum
3409      one-line container lengths
3410  n=3 do not treat commas after => specially at all
3411  n=4 break everything: like n=0 but ALSO break a short container with
3412      a => not followed by a comma when -vt=0 is used
3413  n=5 stable: like n=1 but ALSO break at open one-line containers when
3414      -vt=0 is used (default)
3415
3416 For example, given the following single line, perltidy by default will
3417 not add any line breaks because it would break the existing one-line
3418 container:
3419
3420     bless { B => $B, Root => $Root } => $package;
3421
3422 Using B<-cab=0> will force a break after each comma-arrow item:
3423
3424     # perltidy -cab=0:
3425     bless {
3426         B    => $B,
3427         Root => $Root
3428     } => $package;
3429
3430 If perltidy is subsequently run with this container broken, then by
3431 default it will break after each '=>' because the container is now
3432 broken.  To reform a one-line container, the parameter B<-cab=2> could
3433 be used.
3434
3435 The flag B<-cab=3> can be used to prevent these commas from being
3436 treated specially.  In this case, an item such as "01" => 31 is
3437 treated as a single item in a table.  The number of fields in this table
3438 will be determined by the same rules that are used for any other table.
3439 Here is an example.
3440
3441     # perltidy -cab=3
3442     my %last_day = (
3443         "01" => 31, "02" => 29, "03" => 31, "04" => 30,
3444         "05" => 31, "06" => 30, "07" => 31, "08" => 31,
3445         "09" => 30, "10" => 31, "11" => 30, "12" => 31
3446     );
3447
3448 =back
3449
3450 =head2 Adding and Deleting Commas
3451
3452 =over 4
3453
3454 =item B<-drc>,  B<--delete-repeated-commas>
3455
3456 Repeated commas in a list are undesirable and can be removed with this flag.
3457 For example, given this list with a repeated comma
3458
3459       ignoreSpec( $file, "file",, \%spec, \%Rspec );
3460
3461 we can remove it with -drc
3462
3463       # perltidy -drc:
3464       ignoreSpec( $file, "file", \%spec, \%Rspec );
3465
3466 Since the default is not to add or delete commas, this feature is off by default and must be requested.
3467
3468
3469 =item B<--want-trailing-commas=s> or B<-wtc=s>, B<--add-trailing-commas> or B<-atc>, and B<--delete-trailing-commas> or B<-dtc>
3470
3471 A trailing comma is a comma following the last item of a list. Perl allows
3472 trailing commas but they are not required.  By default, perltidy does not add
3473 or delete trailing commas, but it is possible to manipulate them with the
3474 following set of three related parameters:
3475
3476   --want-trailing-commas=s, -wtc=s - defines where trailing commas are wanted
3477   --add-trailing-commas,    -atc   - gives permission to add trailing commas to match the style wanted
3478   --delete-trailing-commas, -dtc   - gives permission to delete trailing commas which do not match the style wanted
3479
3480 The parameter B<--want-trailing-commas=s>, or B<-wtc=s>, defines a preferred style.  The string B<s> indicates which lists should get trailing commas, as follows:
3481
3482   s=0 : no list should have a trailing comma
3483   s=1 or * : every list should have a trailing comma
3484   s=m a multi-line list should have a trailing commas
3485   s=b trailing commas should be 'bare' (comma followed by newline)
3486   s=h lists of key=>value pairs, with about one one '=>' and one ',' per line,
3487       with a bare trailing comma
3488   s=i lists with about one comma per line, with a bare trailing comma
3489   s=' ' or -wtc not defined : leave trailing commas unchanged [DEFAULT].
3490
3491 This parameter by itself only indicates the where trailing commas are
3492 wanted.  Perltidy only adds these trailing commas if the flag B<--add-trailing-commas>, or B<-atc> is set.  And perltidy only removes unwanted trailing commas
3493 if the flag B<--delete-trailing-commas>, or B<-dtc> is set.
3494
3495 Here are some example parameter combinations and their meanings
3496
3497   -wtc=0 -dtc   : delete all trailing commas
3498   -wtc=1 -atc   : all lists get trailing commas
3499   -wtc=m -atc   : all multi-line lists get trailing commas, but
3500                   single line lists remain unchanged.
3501   -wtc=m -dtc   : multi-line lists remain unchanged, but
3502                   any trailing commas on single line lists are removed.
3503   -wtc=m -atc -dtc  : all multi-line lists get trailing commas, and
3504                       any trailing commas on single line lists are removed.
3505
3506 For example, given the following input without a trailing comma
3507
3508     bless {
3509         B    => $B,
3510         Root => $Root
3511     } => $package;
3512
3513 we can add a trailing comma after the variable C<$Root> using
3514
3515     # perltidy -wtc=m -atc
3516     bless {
3517         B    => $B,
3518         Root => $Root,
3519     } => $package;
3520
3521 This could also be achieved in this case with B<-wtc=b> instead of B<-wtc=m>
3522 because the trailing comma here is bare (separated from its closing brace by a
3523 newline).  And it could also be achieved with B<-wtc=h> because this particular
3524 list is a list of key=>value pairs.
3525
3526 The above styles should cover the main of situations of interest, but it is
3527 possible to apply a different style to each type of container token by
3528 including an opening token ahead of the style character in the above table.
3529 For example
3530
3531     -wtc='(m [b'
3532
3533 means that lists within parens should have multi-line trailing commas, and that
3534 lists within square brackets have bare trailing commas. Since there is no
3535 specification for curly braces in this example, their trailing commas would
3536 remain unchanged.
3537
3538 For parentheses, an additional item of information which can be given is an
3539 alphanumeric letter which is used to limit the selection further depending on
3540 the type of token immediately before the opening paren.  The possible letters
3541 are currently 'k', 'K', 'f', 'F', 'w', and 'W', with these meanings for
3542 matching whatever precedes an opening paren:
3543
3544  'k' matches if the previous nonblank token is a perl built-in keyword (such as 'if', 'while'),
3545  'K' matches if 'k' does not, meaning that the previous token is not a keyword.
3546  'f' matches if the previous token is a function other than a keyword.
3547  'F' matches if 'f' does not.
3548  'w' matches if either 'k' or 'f' match.
3549  'W' matches if 'w' does not.
3550
3551 These are the same codes used for B<--line-up-parentheses-inclusion-list>.
3552 For example,
3553
3554   -wtc = 'w(m'
3555
3556 means that trailing commas are wanted for multi-line parenthesized lists following a function call or keyword.
3557
3558 Here are some points to note regarding adding and deleting trailing commas:
3559
3560 =over 4
3561
3562 =item *
3563
3564 For the implementation of these parameters, a B<list> is basically taken to be
3565 a container of items (parens, square brackets, or braces), which is not a code
3566 block, with one or more commas.  These parameters only apply to something that
3567 fits this definition of a list.
3568
3569 Note that a paren-less list of parameters is not a list by this definition, so
3570 these parameters have no effect on a peren-less list.
3571
3572 Another consequence is that if the only comma in a list is deleted, then it
3573 cannot later be added back with these parameters because the container no
3574 longer fits this definition of a list.  For example, given
3575
3576     my ( $self, ) = @_;
3577
3578 and if we remove the comma with
3579
3580     # perltidy -wtc=m -dtc
3581     my ( $self ) = @_;
3582
3583 then we cannot use these trailing comma controls to add this comma back.
3584
3585 =item *
3586
3587 By B<multiline> list is meant a list for which the first comma and trailing comma
3588 are on different lines.
3589
3590 =item *
3591
3592 A B<bare> trailing comma is a comma which is at the end of a line. That is,
3593 the closing container token follows on a different line.  So a list with a
3594 bare trailing comma is a special case of a multi-line list.
3595
3596 =item *
3597
3598 The decision regarding whether or not a list is multi-line or bare is
3599 made based on the B<input> stream.  In some cases it may take an iteration
3600 or two to reach a final state.
3601
3602 =item *
3603
3604 When using these parameters for the first time it is a good idea to practice
3605 on some test scripts and verify that the results are as expected.
3606
3607 =item *
3608
3609 Since the default behavior is not to add or delete commas, these parameters
3610 can be useful on a temporary basis for reformatting a script.
3611
3612 =back
3613
3614 =item B<-dwic>,  B<--delete-weld-interfering-commas>
3615
3616 If the closing tokens of two nested containers are separated by a comma, then
3617 welding requested with B<--weld-nested-containers> cannot occur.  Any commas in
3618 this situation are optional trailing commas and can be removed with B<-dwic>.
3619 For example, a comma in this script prevents welding:
3620
3621     # perltidy -wn
3622     skip_symbols(
3623         [ qw(
3624             Perl_dump_fds
3625             Perl_ErrorNo
3626             Perl_GetVars
3627             PL_sys_intern
3628         ) ],
3629     );
3630
3631 Using B<-dwic> removes the comma and allows welding:
3632
3633     # perltidy -wn -dwic
3634     skip_symbols( [ qw(
3635         Perl_dump_fds
3636         Perl_ErrorNo
3637         Perl_GetVars
3638         PL_sys_intern
3639     ) ] );
3640
3641 Since the default is not to add or delete commas, this feature is off by default.
3642 Here are some points to note about the B<-dwic> parameter
3643
3644 =over 4
3645
3646 =item *
3647
3648 This operation is not reversible, so please check results of using this parameter carefully.
3649
3650 =item *
3651
3652 Removing this type of isolated trailing comma is necessary for welding to be
3653 possible, but not sufficient.  So welding will not always occur where these
3654 commas are removed.
3655
3656 =back
3657
3658 =back
3659
3660 =head2 Retaining or Ignoring Existing Line Breaks
3661
3662 Several additional parameters are available for controlling the extent
3663 to which line breaks in the input script influence the output script.
3664 In most cases, the default parameter values are set so that, if a choice
3665 is possible, the output style follows the input style.  For example, if
3666 a short logical container is broken in the input script, then the
3667 default behavior is for it to remain broken in the output script.
3668
3669 Most of the parameters in this section would only be required for a
3670 one-time conversion of a script from short container lengths to longer
3671 container lengths.  The opposite effect, of converting long container
3672 lengths to shorter lengths, can be obtained by temporarily using a short
3673 maximum line length.
3674
3675 =over 4
3676
3677 =item B<-bol>,  B<--break-at-old-logical-breakpoints>
3678
3679 By default, if a logical expression is broken at a C<&&>, C<||>, C<and>,
3680 or C<or>, then the container will remain broken.  Also, breaks
3681 at internal keywords C<if> and C<unless> will normally be retained.
3682 To prevent this, and thus form longer lines, use B<-nbol>.
3683
3684 Please note that this flag does not duplicate old logical breakpoints.  They
3685 are merely used as a hint with this flag that a statement should remain
3686 broken.  Without this flag, perltidy will normally try to combine relatively
3687 short expressions into a single line.
3688
3689 For example, given this snippet:
3690
3691     return unless $cmd = $cmd || ($dot
3692         && $Last_Shell) || &prompt('|');
3693
3694     # perltidy -bol [default]
3695     return
3696       unless $cmd = $cmd
3697       || ( $dot
3698         && $Last_Shell )
3699       || &prompt('|');
3700
3701     # perltidy -nbol
3702     return unless $cmd = $cmd || ( $dot && $Last_Shell ) || &prompt('|');
3703
3704 =item B<-bom>,  B<--break-at-old-method-breakpoints>
3705
3706 By default, a method call arrow C<-E<gt>> is considered a candidate for
3707 a breakpoint, but method chains will fill to the line width before a break is
3708 considered.  With B<-bom>, breaks before the arrow are preserved, so if you
3709 have pre-formatted a method chain:
3710
3711   my $q = $rs
3712     ->related_resultset('CDs')
3713     ->related_resultset('Tracks')
3714     ->search({
3715       'track.id' => {-ident => 'none_search.id'},
3716     })->as_query;
3717
3718 It will B<keep> these breaks, rather than become this:
3719
3720   my $q = $rs->related_resultset('CDs')->related_resultset('Tracks')->search({
3721       'track.id' => {-ident => 'none_search.id'},
3722     })->as_query;
3723
3724 This flag will also look for and keep a 'cuddled' style of calls,
3725 in which lines begin with a closing paren followed by a call arrow,
3726 as in this example:
3727
3728   # perltidy -bom -wn
3729   my $q = $rs->related_resultset(
3730       'CDs'
3731   )->related_resultset(
3732       'Tracks'
3733   )->search( {
3734       'track.id' => { -ident => 'none_search.id' },
3735   } )->as_query;
3736
3737 You may want to include the B<-weld-nested-containers> flag in this case to keep
3738 nested braces and parens together, as in the last line.
3739
3740 =item B<-bos>,  B<--break-at-old-semicolon-breakpoints>
3741
3742 Semicolons are normally placed at the end of a statement.  This means that formatted lines do not normally begin with semicolons.  If the input stream has some lines which begin with semicolons, these can be retained by setting this flag.  For example, consider
3743 the following two-line input snippet:
3744
3745   $z = sqrt($x**2 + $y**2)
3746   ;
3747
3748 The default formatting will be:
3749
3750   $z = sqrt( $x**2 + $y**2 );
3751
3752 The result using B<perltidy -bos> keeps the isolated semicolon:
3753
3754   $z = sqrt( $x**2 + $y**2 )
3755     ;
3756
3757 The default is not to do this, B<-nbos>.
3758
3759
3760 =item B<-bok>,  B<--break-at-old-keyword-breakpoints>
3761
3762 By default, perltidy will retain a breakpoint before keywords which may
3763 return lists, such as C<sort> and <map>.  This allows chains of these
3764 operators to be displayed one per line.  Use B<-nbok> to prevent
3765 retaining these breakpoints.
3766
3767 =item B<-bot>,  B<--break-at-old-ternary-breakpoints>
3768
3769 By default, if a conditional (ternary) operator is broken at a C<:>,
3770 then it will remain broken.  To prevent this, and thereby
3771 form longer lines, use B<-nbot>.
3772
3773 =item B<-boa>,  B<--break-at-old-attribute-breakpoints>
3774
3775 By default, if an attribute list is broken at a C<:> in the source file, then
3776 it will remain broken.  For example, given the following code, the line breaks
3777 at the ':'s will be retained:
3778
3779                     my @field
3780                       : field
3781                       : Default(1)
3782                       : Get('Name' => 'foo') : Set('Name');
3783
3784 If the attributes are on a single line in the source code then they will remain
3785 on a single line if possible.
3786
3787 To prevent this, and thereby always form longer lines, use B<-nboa>.
3788
3789 =item B<Keeping old breakpoints at specific token types>
3790
3791 It is possible to override the choice of line breaks made by perltidy, and
3792 force it to follow certain line breaks in the input stream, with these two
3793 parameters:
3794
3795 B<-kbb=s> or B<--keep-old-breakpoints-before=s>, and
3796
3797 B<-kba=s> or B<--keep-old-breakpoints-after=s>
3798
3799 These parameters are each followed by a quoted string, B<s>, containing
3800 a list of token types (separated only by spaces).  No more than one of each
3801 of these parameters should be specified, because repeating a
3802 command-line parameter always overwrites the previous one before
3803 perltidy ever sees it.
3804
3805 For example, -kbb='=>' means that if an input line begins with a '=>' then the
3806 output script should also have a line break before that token.
3807
3808 For example, given the script:
3809
3810     method 'foo'
3811       => [ Int, Int ]
3812       => sub {
3813         my ( $self, $x, $y ) = ( shift, @_ );
3814         ...;
3815       };
3816
3817     # perltidy [default]
3818     method 'foo' => [ Int, Int ] => sub {
3819         my ( $self, $x, $y ) = ( shift, @_ );
3820         ...;
3821     };
3822
3823     # perltidy -kbb='=>'
3824     method 'foo'
3825       => [ Int, Int ]
3826       => sub {
3827         my ( $self, $x, $y ) = ( shift, @_ );
3828         ...;
3829       };
3830
3831 For the container tokens '{', '[' and '(' and, their closing counterparts, use the token symbol. Thus,
3832 the command to keep a break after all opening parens is:
3833
3834    perltidy -kba='('
3835
3836 It is possible to be more specific in matching parentheses by preceding them
3837 with a letter.  The possible letters are 'k', 'K', 'f', 'F', 'w', and 'W', with
3838 these meanings (these are the same as used in the
3839 B<--weld-nested-exclusion-list> and B<--line-up-parentheses-exclusion-list>
3840 parameters):
3841
3842  'k' matches if the previous nonblank token is a perl built-in keyword (such as 'if', 'while'),
3843  'K' matches if 'k' does not, meaning that the previous token is not a keyword.
3844  'f' matches if the previous token is a function other than a keyword.
3845  'F' matches if 'f' does not.
3846  'w' matches if either 'k' or 'f' match.
3847  'W' matches if 'w' does not.
3848
3849 So for example the the following parameter will keep breaks after opening function call
3850 parens:
3851
3852    perltidy -kba='f('
3853
3854 B<NOTE>: A request to break before an opening container, such as B<-kbb='('>,
3855 will be silently ignored because it can lead to formatting instability.
3856 Likewise, a request to break after a closing container, such as B<-kba>=')',
3857 will also be silently ignored.
3858
3859 =item B<-iob>,  B<--ignore-old-breakpoints>
3860
3861 Use this flag to tell perltidy to ignore existing line breaks to the
3862 maximum extent possible.  This will tend to produce the longest possible
3863 containers, regardless of type, which do not exceed the line length
3864 limit.  But please note that this parameter has priority over all
3865 other parameters requesting that certain old breakpoints be kept.
3866
3867 To illustrate, consider the following input text:
3868
3869     has subcmds => (
3870         is => 'ro',
3871         default => sub { [] },
3872     );
3873
3874 The default formatting will keep the container broken, giving
3875
3876     # perltidy [default]
3877     has subcmds => (
3878         is      => 'ro',
3879         default => sub { [] },
3880     );
3881
3882 If old breakpoints are ignored, the list will be flattened:
3883
3884     # perltidy -iob
3885     has subcmds => ( is => 'ro', default => sub { [] }, );
3886
3887 Besides flattening lists, this parameter also applies to lines broken
3888 at certain logical breakpoints such as 'if' and 'or'.
3889
3890 Even if this is parameter is not used globally, it provides a convenient way to
3891 flatten selected lists from within an editor.
3892
3893 =item B<-kis>,  B<--keep-interior-semicolons>
3894
3895 Use the B<-kis> flag to prevent breaking at a semicolon if
3896 there was no break there in the input file.  Normally
3897 perltidy places a newline after each semicolon which
3898 terminates a statement unless several statements are
3899 contained within a one-line brace block.  To illustrate,
3900 consider the following input lines:
3901
3902     dbmclose(%verb_delim); undef %verb_delim;
3903     dbmclose(%expanded); undef %expanded;
3904
3905 The default is to break after each statement, giving
3906
3907     dbmclose(%verb_delim);
3908     undef %verb_delim;
3909     dbmclose(%expanded);
3910     undef %expanded;
3911
3912 With B<perltidy -kis> the multiple statements are retained:
3913
3914     dbmclose(%verb_delim); undef %verb_delim;
3915     dbmclose(%expanded);   undef %expanded;
3916
3917 The statements are still subject to the specified value
3918 of B<maximum-line-length> and will be broken if this
3919 maximum is exceeded.
3920
3921 =back
3922
3923 =head2 Blank Line Control
3924
3925 Blank lines can improve the readability of a script if they are carefully
3926 placed.  Perltidy has several commands for controlling the insertion,
3927 retention, and removal of blank lines.
3928
3929 =over 4
3930
3931 =item B<-fbl>,  B<--freeze-blank-lines>
3932
3933 Set B<-fbl> if you want to the blank lines in your script to
3934 remain exactly as they are.  The rest of the parameters in
3935 this section may then be ignored.  (Note: setting the B<-fbl> flag
3936 is equivalent to setting B<-mbl=0> and B<-kbl=2>).
3937
3938 =item B<-bbc>,  B<--blanks-before-comments>
3939
3940 A blank line will be introduced before a full-line comment.  This is the
3941 default.  Use B<-nbbc> or  B<--noblanks-before-comments> to prevent
3942 such blank lines from being introduced.
3943
3944 =item B<-blbs=n>,  B<--blank-lines-before-subs=n>
3945
3946 The parameter B<-blbs=n> requests that least B<n> blank lines precede a sub
3947 definition which does not follow a comment and which is more than one-line
3948 long.  The default is <-blbs=1>.  B<BEGIN> and B<END> blocks are included.
3949
3950 The requested number of blanks statement will be inserted regardless of the
3951 value of B<--maximum-consecutive-blank-lines=n> (B<-mbl=n>) with the exception
3952 that if B<-mbl=0> then no blanks will be output.
3953
3954 This parameter interacts with the value B<k> of the parameter B<--maximum-consecutive-blank-lines=k> (B<-mbl=k>) as follows:
3955
3956 1. If B<-mbl=0> then no blanks will be output.  This allows all blanks to be suppressed with a single parameter.  Otherwise,
3957
3958 2. If the number of old blank lines in the script is less than B<n> then
3959 additional blanks will be inserted to make the total B<n> regardless of the
3960 value of B<-mbl=k>.
3961
3962 3. If the number of old blank lines in the script equals or exceeds B<n> then
3963 this parameter has no effect, however the total will not exceed
3964 value specified on the B<-mbl=k> flag.
3965
3966
3967 =item B<-blbp=n>,  B<--blank-lines-before-packages=n>
3968
3969 The parameter B<-blbp=n> requests that least B<n> blank lines precede a package
3970 which does not follow a comment.  The default is B<-blbp=1>.
3971
3972 This parameter interacts with the value B<k> of the parameter
3973 B<--maximum-consecutive-blank-lines=k> (B<-mbl=k>) in the same way as described
3974 for the previous item B<-blbs=n>.
3975
3976
3977 =item B<-bbs>,  B<--blanks-before-subs>
3978
3979 For compatibility with previous versions, B<-bbs> or B<--blanks-before-subs>
3980 is equivalent to F<-blbp=1> and F<-blbs=1>.
3981
3982 Likewise, B<-nbbs> or B<--noblanks-before-subs>
3983 is equivalent to F<-blbp=0> and F<-blbs=0>.
3984
3985 =item B<-bbb>,  B<--blanks-before-blocks>
3986
3987 A blank line will be introduced before blocks of coding delimited by
3988 B<for>, B<foreach>, B<while>, B<until>, and B<if>, B<unless>, in the following
3989 circumstances:
3990
3991 =over 4
3992
3993 =item *
3994
3995 The block is not preceded by a comment.
3996
3997 =item *
3998
3999 The block is not a one-line block.
4000
4001 =item *
4002
4003 The number of consecutive non-blank lines at the current indentation depth is at least B<-lbl>
4004 (see next section).
4005
4006 =back
4007
4008 This is the default.  The intention of this option is to introduce
4009 some space within dense coding.
4010 This is negated with B<-nbbb> or  B<--noblanks-before-blocks>.
4011
4012 =item B<-lbl=n> B<--long-block-line-count=n>
4013
4014 This controls how often perltidy is allowed to add blank lines before
4015 certain block types (see previous section).  The default is 8.  Entering
4016 a value of B<0> is equivalent to entering a very large number.
4017
4018 =item B<-blao=i> or B<--blank-lines-after-opening-block=i>
4019
4020 This control places a minimum of B<i> blank lines B<after> a line which B<ends>
4021 with an opening block brace of a specified type.  By default, this only applies
4022 to the block of a named B<sub>, but this can be changed (see B<-blaol> below).
4023 The default is not to do this (B<i=0>).
4024
4025 Please see the note below on using the B<-blao> and B<-blbc> options.
4026
4027 =item B<-blbc=i> or B<--blank-lines-before-closing-block=i>
4028
4029 This control places a minimum of B<i> blank lines B<before> a line which
4030 B<begins> with a closing block brace of a specified type.  By default, this
4031 only applies to the block of a named B<sub>, but this can be changed (see
4032 B<-blbcl> below).  The default is not to do this (B<i=0>).
4033
4034 =item B<-blaol=s> or B<--blank-lines-after-opening-block-list=s>
4035
4036 The parameter B<s> is a list of block type keywords to which the flag B<-blao>
4037 should apply.  The section L<"Specifying Block Types"> explains how to list
4038 block types.
4039
4040 =item B<-blbcl=s> or B<--blank-lines-before-closing-block-list=s>
4041
4042 This parameter is a list of block type keywords to which the flag B<-blbc>
4043 should apply.  The section L<"Specifying Block Types"> explains how to list
4044 block types.
4045
4046 =item B<Note on using the> B<-blao> and B<-blbc> options.
4047
4048 These blank line controls introduce a certain minimum number of blank lines in
4049 the text, but the final number of blank lines may be greater, depending on
4050 values of the other blank line controls and the number of old blank lines.  A
4051 consequence is that introducing blank lines with these and other controls
4052 cannot be exactly undone, so some experimentation with these controls is
4053 recommended before using them.
4054
4055 For example, suppose that for some reason we decide to introduce one blank
4056 space at the beginning and ending of all blocks.  We could do
4057 this using
4058
4059   perltidy -blao=2 -blbc=2 -blaol='*' -blbcl='*' filename
4060
4061 Now suppose the script continues to be developed, but at some later date we
4062 decide we don't want these spaces after all. We might expect that running with
4063 the flags B<-blao=0> and B<-blbc=0> will undo them.  However, by default
4064 perltidy retains single blank lines, so the blank lines remain.
4065
4066 We can easily fix this by telling perltidy to ignore old blank lines by
4067 including the added parameter B<-kbl=0> and rerunning. Then the unwanted blank
4068 lines will be gone.  However, this will cause all old blank lines to be
4069 ignored, perhaps even some that were added by hand to improve formatting. So
4070 please be cautious when using these parameters.
4071
4072 =item B<-mbl=n> B<--maximum-consecutive-blank-lines=n>
4073
4074 This parameter specifies the maximum number of consecutive blank lines which
4075 will be output within code sections of a script.  The default is n=1.  If the
4076 input file has more than n consecutive blank lines, the number will be reduced
4077 to n except as noted above for the B<-blbp> and B<-blbs> parameters.  If B<n=0>
4078 then no blank lines will be output (unless all old blank lines are retained
4079 with the B<-kbl=2> flag of the next section).
4080
4081 This flag obviously does not apply to pod sections,
4082 here-documents, and quotes.
4083
4084 =item B<-kbl=n>,  B<--keep-old-blank-lines=n>
4085
4086 The B<-kbl=n> flag gives you control over how your existing blank lines are
4087 treated.
4088
4089 The possible values of B<n> are:
4090
4091  n=0 ignore all old blank lines
4092  n=1 stable: keep old blanks, but limited by the value of the B<-mbl=n> flag
4093  n=2 keep all old blank lines, regardless of the value of the B<-mbl=n> flag
4094
4095 The default is B<n=1>.
4096
4097 =item B<-sob>,  B<--swallow-optional-blank-lines>
4098
4099 This is equivalent to B<kbl=0> and is included for compatibility with
4100 previous versions.
4101
4102 =item B<-nsob>,  B<--noswallow-optional-blank-lines>
4103
4104 This is equivalent to B<kbl=1> and is included for compatibility with
4105 previous versions.
4106
4107 =back
4108
4109 B<Controls for blank lines around lines of consecutive keywords>
4110
4111 The parameters in this section provide some control over the placement of blank
4112 lines within and around groups of statements beginning with selected keywords.
4113 These blank lines are called here B<keyword group blanks>, and all of the
4114 parameters begin with B<--keyword-group-blanks*>, or B<-kgb*> for short.  The
4115 default settings do not employ these controls but they can be enabled with the
4116 following parameters:
4117
4118 B<-kgbl=s> or B<--keyword-group-blanks-list=s>; B<s> is a quoted string of keywords
4119
4120 B<-kgbs=s> or B<--keyword-group-blanks-size=s>; B<s> gives the number of keywords required to form a group.
4121
4122 B<-kgbb=n> or B<--keyword-group-blanks-before=n>; B<n> = (0, 1, or 2) controls a leading blank
4123
4124 B<-kgba=n> or B<--keyword-group-blanks-after=n>; B<n> = (0, 1, or 2) controls a trailing blank
4125
4126 B<-kgbi> or B<--keyword-group-blanks-inside> is a switch for adding blanks between subgroups
4127
4128 B<-kgbd> or B<--keyword-group-blanks-delete> is a switch for removing initial blank lines between keywords
4129
4130 B<-kgbr=n> or B<--keyword-group-blanks-repeat-count=n> can limit the number of times this logic is applied
4131
4132 In addition, the following abbreviations are available to for simplified usage:
4133
4134 B<-kgb> or B<--keyword-group-blanks> is short for B<-kgbb=2 -kgba=2 kgbi>
4135
4136 B<-nkgb> or B<--nokeyword-group-blanks>, is short for B<-kgbb=1 -kgba=1 nkgbi>
4137
4138 Before describing the meaning of the parameters in detail let us look at an
4139 example which is formatted with default parameter settings.
4140
4141         print "Entering test 2\n";
4142         use Test;
4143         use Encode qw(from_to encode decode
4144           encode_utf8 decode_utf8
4145           find_encoding is_utf8);
4146         use charnames qw(greek);
4147         my @encodings     = grep( /iso-?8859/, Encode::encodings() );
4148         my @character_set = ( '0' .. '9', 'A' .. 'Z', 'a' .. 'z' );
4149         my @source        = qw(ascii iso8859-1 cp1250);
4150         my @destiny       = qw(cp1047 cp37 posix-bc);
4151         my @ebcdic_sets   = qw(cp1047 cp37 posix-bc);
4152         my $str           = join( '', map( chr($_), 0x20 .. 0x7E ) );
4153         return unless ($str);
4154
4155 using B<perltidy -kgb> gives:
4156
4157         print "Entering test 2\n";
4158                                       <----------this blank controlled by -kgbb
4159         use Test;
4160         use Encode qw(from_to encode decode
4161           encode_utf8 decode_utf8
4162           find_encoding is_utf8);
4163         use charnames qw(greek);
4164                                       <---------this blank controlled by -kgbi
4165         my @encodings     = grep( /iso-?8859/, Encode::encodings() );
4166         my @character_set = ( '0' .. '9', 'A' .. 'Z', 'a' .. 'z' );
4167         my @source        = qw(ascii iso8859-1 cp1250);
4168         my @destiny       = qw(cp1047 cp37 posix-bc);
4169         my @ebcdic_sets   = qw(cp1047 cp37 posix-bc);
4170         my $str           = join( '', map( chr($_), 0x20 .. 0x7E ) );
4171                                       <----------this blank controlled by -kgba
4172         return unless ($str);
4173
4174 Blank lines have been introduced around the B<my> and B<use> sequences.  What
4175 happened is that the default keyword list includes B<my> and B<use> but not
4176 B<print> and B<return>.  So a continuous sequence of nine B<my> and B<use>
4177 statements was located.  This number exceeds the default threshold of five, so
4178 blanks were placed before and after the entire group.  Then, since there was
4179 also a subsequence of six B<my> lines, a blank line was introduced to separate
4180 them.
4181
4182 Finer control over blank placement can be achieved by using the individual
4183 parameters rather than the B<-kgb> flag.  The individual controls are as follows.
4184
4185 B<-kgbl=s> or B<--keyword-group-blanks-list=s>, where B<s> is a quoted string,
4186 defines the set of keywords which will be formed into groups.  The string is a
4187 space separated list of keywords.  The default set is B<s="use require local
4188 our my">, but any list of keywords may be used. Comment lines may also be included in a keyword group, even though they are not keywords.  To include ordinary block comments, include the symbol B<BC>. To include static block comments (which normally begin with '##'), include the symbol B<SBC>.
4189
4190 B<-kgbs=s> or B<--keyword-group-blanks-size=s>, where B<s> is a string
4191 describing the number of consecutive keyword statements forming a group (Note:
4192 statements separated by blank lines in the input file are considered
4193 consecutive for purposes of this count).  If B<s> is an integer then it is the
4194 minimum number required for a group.  A maximum value may also be given with
4195 the format B<s=min.max>, where B<min> is the minimum number and B<max> is the
4196 maximum number, and the min and max values are separated by one or more dots.
4197 No groups will be found if the maximum is less than the minimum.  The maximum
4198 is unlimited if not given.  The default is B<s=5>.  Some examples:
4199
4200     s      min   max         number for group
4201     3      3     unlimited   3 or more
4202     1.1    1     1           1
4203     1..3   1     3           1 to 3
4204     1.0    1     0           (no match)
4205
4206 There is no really good default value for this parameter.  If it is set too
4207 small, then an excessive number of blank lines may be generated.  However, some
4208 users may prefer reducing the value somewhat below the default, perhaps to
4209 B<s=3>.
4210
4211 B<-kgbb=n> or B<--keyword-group-blanks-before=n> specifies whether
4212 a blank should appear before the first line of the group, as follows:
4213
4214    n=0 => (delete) an existing blank line will be removed
4215    n=1 => (stable) no change to the input file is made  [DEFAULT]
4216    n=2 => (insert) a blank line is introduced if possible
4217
4218 B<-kgba=n> or B<--keyword-group-blanks-after=n> likewise specifies
4219 whether a blank should appear after the last line of the group, using the same
4220 scheme (0=delete, 1=stable, 2=insert).
4221
4222 B<-kgbi> or B<--keyword-group-blanks-inside> controls
4223 the insertion of blank lines between the first and last statement of the entire
4224 group.  If there is a continuous run of a single statement type with more than
4225 the minimum threshold number (as specified with B<-kgbs=s>) then this
4226 switch causes a blank line be inserted between this
4227 subgroup and the others. In the example above this happened between the
4228 B<use> and B<my> statements.
4229
4230 B<-kgbd> or B<--keyword-group-blanks-delete> controls the deletion of any
4231 blank lines that exist in the the group when it is first scanned.  When
4232 statements are initially scanned, any existing blank lines are included in the
4233 collection.  Any such original blank lines will be deleted before any other
4234 insertions are made when the parameter B<-kgbd> is set.  The default is not to
4235 do this, B<-nkgbd>.
4236
4237 B<-kgbr=n> or B<--keyword-group-blanks-repeat-count=n> specifies B<n>, the
4238 maximum number of times this logic will be applied to any file.  The special
4239 value B<n=0> is the same as n=infinity which means it will be applied to an
4240 entire script [Default].  A value B<n=1> could be used to make it apply just
4241 one time for example.  This might be useful for adjusting just the B<use>
4242 statements in the top part of a module for example.
4243
4244 B<-kgb> or B<--keyword-group-blanks> is an abbreviation equivalent to setting
4245 B<-kgbb=1 -kgba=1 -kgbi>.  This turns on keyword group formatting with a set of
4246 default values.
4247
4248 B<-nkgb> or B<--nokeyword-group-blanks> is equivalent to B<-kgbb=0 -kgba
4249 nkgbi>.  This flag turns off keyword group blank lines and is the default
4250 setting.
4251
4252 Here are a few notes about the functioning of this technique.
4253
4254 =over 4
4255
4256 =item *
4257
4258 These parameters are probably more useful as part of a major code reformatting
4259 operation rather than as a routine formatting operation.
4260
4261 In particular, note that deleting old blank lines with B<-kgbd> is an
4262 irreversible operation so it should be applied with care.  Existing blank lines
4263 may be serving an important role in controlling vertical alignment.
4264
4265 =item *
4266
4267 Conflicts which arise among these B<kgb*> parameters and other blank line
4268 controls are generally resolved by producing the maximum number of blank lines
4269 implied by any parameter.
4270
4271 For example, if the flags B<--freeze-blank-lines>, or
4272 B<--keep-old-blank-lines=2>, are set, then they have priority over any blank
4273 line deletion implied by the B<-kgb> flags of this section, so no blank lines
4274 will be deleted.
4275
4276 For another example, if a keyword group ends at a B<sub> and the flag B<kgba=0> requests no blank line there, but we also have B<--blank-lines-before-subs=2>, then two blank lines will still be introduced before the sub.
4277
4278 =item *
4279
4280 The introduction of blank lines does not occur if it would conflict with other
4281 input controls or code validity. For example, a blank line will not be placed
4282 within a here-doc or within a section of code marked with format skipping
4283 comments.  And in general, a blank line will only be introduced at the end of a
4284 group if the next statement is a line of code.
4285
4286 =item *
4287
4288 The count which is used to determine the group size is not the number of lines
4289 but rather the total number of keywords which are found.  Individual statements
4290 with a certain leading keyword may continue on multiple lines, but if any of
4291 these lines is nested more than one level deep then that group will be ended.
4292
4293 =item *
4294
4295 The search for groups of lines with similar leading keywords is based on the
4296 input source, not the final formatted source.  Consequently, if the source code
4297 is badly formatted, it would be best to make a first formatting pass without
4298 these options.
4299
4300 =back
4301
4302 =head2 Styles
4303
4304 A style refers to a convenient collection of existing parameters.
4305
4306 =over 4
4307
4308 =item B<-gnu>, B<--gnu-style>
4309
4310 B<-gnu> gives an approximation to the GNU Coding Standards (which do
4311 not apply to perl) as they are sometimes implemented.  At present, this
4312 style overrides the default style with the following parameters:
4313
4314     -lp -bl -noll -pt=2 -bt=2 -sbt=2 -icp
4315
4316 To use this style with B<-xlp> instead of B<-lp> use B<-gnu -xlp>.
4317
4318 =item B<-pbp>, B<--perl-best-practices>
4319
4320 B<-pbp> is an abbreviation for the parameters in the book B<Perl Best Practices>
4321 by Damian Conway:
4322
4323     -l=78 -i=4 -ci=4 -st -se -vt=2 -cti=0 -pt=1 -bt=1 -sbt=1 -bbt=1 -nsfs -nolq
4324     -wbb="% + - * / x != == >= <= =~ !~ < > | & =
4325           **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x="
4326
4327 Please note that this parameter set includes -st and -se flags, which make
4328 perltidy act as a filter on one file only.  These can be overridden by placing
4329 B<-nst> and/or B<-nse> after the -pbp parameter.
4330
4331 Also note that the value of continuation indentation, -ci=4, is equal to the
4332 value of the full indentation, -i=4.  It is recommended that the either (1) the
4333 parameter B<-ci=2> be used instead, or (2) the flag B<-xci> be set.  This will
4334 help show structure, particularly when there are ternary statements. The
4335 following snippet illustrates these options.
4336
4337     # perltidy -pbp
4338     $self->{_text} = (
4339          !$section        ? ''
4340         : $type eq 'item' ? "the $section entry"
4341         :                   "the section on $section"
4342         )
4343         . (
4344         $page
4345         ? ( $section ? ' in ' : '' ) . "the $page$page_ext manpage"
4346         : ' elsewhere in this document'
4347         );
4348
4349     # perltidy -pbp -ci=2
4350     $self->{_text} = (
4351          !$section        ? ''
4352         : $type eq 'item' ? "the $section entry"
4353         :                   "the section on $section"
4354       )
4355       . (
4356         $page
4357         ? ( $section ? ' in ' : '' ) . "the $page$page_ext manpage"
4358         : ' elsewhere in this document'
4359       );
4360
4361     # perltidy -pbp -xci
4362     $self->{_text} = (
4363          !$section        ? ''
4364         : $type eq 'item' ? "the $section entry"
4365         :                   "the section on $section"
4366         )
4367         . ( $page
4368             ? ( $section ? ' in ' : '' ) . "the $page$page_ext manpage"
4369             : ' elsewhere in this document'
4370         );
4371
4372 The B<-xci> flag was developed after the B<-pbp> parameters were published so you need
4373 to include it separately.
4374
4375 =back
4376
4377 =head2 One-Line Blocks
4378
4379 A one-line block is a block of code where the contents within the curly braces
4380 is short enough to fit on a single line. For example,
4381
4382     if ( -e $file ) { print "'$file' exists\n" }
4383
4384 The alternative, a block which spans multiple lines, is said to be a broken
4385 block.  With few exceptions, perltidy retains existing one-line blocks, if it
4386 is possible within the line-length constraint, but it does not attempt to form
4387 new ones.  In other words, perltidy will try to follow the input file regarding
4388 broken and unbroken blocks.
4389
4390 The main exception to this rule is that perltidy will attempt to form new
4391 one-line blocks following the keywords C<map>, C<eval>, and C<sort>, C<eval>,
4392 because these code blocks are often small and most clearly displayed in a
4393 single line. This behavior can be controlled with the flag
4394 B<--one-line-block-exclusion-list> described below.
4395
4396 When the B<cuddled-else> style is used, the default treatment of one-line blocks
4397 may interfere with the cuddled style.  In this case, the default behavior may 
4398 be changed with the flag B<--cuddled-break-option=n> described elsehwere.
4399
4400 When an existing one-line block is longer than the maximum line length, and
4401 must therefore be broken into multiple lines, perltidy checks for and adds any
4402 optional terminating semicolon (unless the B<-nasc> option is used) if the
4403 block is a code block.
4404
4405 =over 4
4406
4407 =item B<-olbxl=s>, B<--one-line-block-exclusion-list=s>
4408
4409 As noted above, perltidy will, by default, attempt to create new one-line
4410 blocks for certain block types.  This flag allows the user to prevent this behavior for the block types listed in the string B<s>.  The list B<s> may
4411 include any of the words C<sort>, C<map>, C<grep>, C<eval>,  or it may be C<*>
4412 to indicate all of these.
4413
4414 So for example to prevent multi-line B<eval> blocks from becoming one-line
4415 blocks, the command would be B<-olbxl='eval'>.  In this case, existing one-line B<eval> blocks will remain on one-line if possible, and existing multi-line
4416 B<eval> blocks will remain multi-line blocks.
4417
4418 =item B<-olbn=n>, B<--one-line-block-nesting=n>
4419
4420 Nested one-line blocks are lines with code blocks which themselves contain code
4421 blocks.  For example, the following line is a nested one-line block.
4422
4423          foreach (@list) { if ($_ eq $asked_for) { last } ++$found }
4424
4425 The default behavior is to break such lines into multiple lines, but this
4426 behavior can be controlled with this flag.  The values of n are:
4427
4428   n=0 break nested one-line blocks into multiple lines [DEFAULT]
4429   n=1 stable: keep existing nested-one line blocks intact
4430
4431 For the above example, the default formatting (B<-olbn=0>) is
4432
4433     foreach (@list) {
4434         if ( $_ eq $asked_for ) { last }
4435         ++$found;
4436     }
4437
4438 If the parameter B<-olbn=1> is given, then the line will be left intact if it
4439 is a single line in the source, or it will be broken into multiple lines if it
4440 is broken in multiple lines in the source.
4441
4442 =item B<-olbs=n>, B<--one-line-block-semicolons=n>
4443
4444 This flag controls the placement of semicolons at the end of one-line blocks.
4445 Semicolons are optional before a closing block brace, and frequently they are
4446 omitted at the end of a one-line block containing just a single statement.
4447 By default, perltidy follows the input file regarding these semicolons,
4448 but this behavior can be controlled by this flag.  The values of n are:
4449
4450   n=0 remove terminal semicolons in one-line blocks having a single statement
4451   n=1 stable; keep input file placement of terminal semicolons [DEFAULT ]
4452   n=2 add terminal semicolons in all one-line blocks
4453
4454 Note that the B<n=2> option has no effect if adding semicolons is prohibited
4455 with the B<-nasc> flag.  Also not that while B<n=2> adds missing semicolons to
4456 all one-line blocks, regardless of complexity, the B<n=0> option only removes
4457 ending semicolons which terminate one-line blocks containing just one
4458 semicolon.  So these two options are not exact inverses.
4459
4460 =item B<Forming new one-line blocks>
4461
4462 Sometimes it might be desirable to convert a script to have one-line blocks
4463 whenever possible.  Although there is currently no flag for this, a simple
4464 workaround is to execute perltidy twice, once with the flag B<-noadd-newlines>
4465 and then once again with normal parameters, like this:
4466
4467      cat infile | perltidy -nanl | perltidy >outfile
4468
4469 When executed on this snippet
4470
4471     if ( $? == -1 ) {
4472         die "failed to execute: $!\n";
4473     }
4474     if ( $? == -1 ) {
4475         print "Had enough.\n";
4476         die "failed to execute: $!\n";
4477     }
4478
4479 the result is
4480
4481     if ( $? == -1 ) { die "failed to execute: $!\n"; }
4482     if ( $? == -1 ) {
4483         print "Had enough.\n";
4484         die "failed to execute: $!\n";
4485     }
4486
4487 This shows that blocks with a single statement become one-line blocks.
4488
4489 =item B<Breaking existing one-line blocks>
4490
4491 There is no automatic way to break existing long one-line blocks into multiple
4492 lines, but this can be accomplished by processing a script, or section of a
4493 script, with a short value of the parameter B<maximum-line-length=n>.  Then,
4494 when the script is reformatted again with the normal parameters, the blocks
4495 which were broken will remain broken (with the exceptions noted above).
4496
4497 Another trick for doing this for certain block types is to format one time with
4498 the B<-cuddled-else> flag and B<--cuddled-break-option=2>. Then format again
4499 with the normal parameters.  This will break any one-line blocks which are
4500 involved in a cuddled-else style.
4501
4502 =back
4503
4504 =head2 Controlling Vertical Alignment
4505
4506 Vertical alignment refers to lining up certain symbols in a list of consecutive
4507 similar lines to improve readability.  For example, the "fat commas" are
4508 aligned in the following statement:
4509
4510         $data = $pkg->new(
4511             PeerAddr => join( ".", @port[ 0 .. 3 ] ),
4512             PeerPort => $port[4] * 256 + $port[5],
4513             Proto    => 'tcp'
4514         );
4515
4516 Vertical alignment can be completely turned off using the B<-novalign> flag
4517 mentioned below.  However, vertical alignment can be forced to
4518 stop and restart by selectively introducing blank lines.  For example, a blank
4519 has been inserted in the following code to keep somewhat similar things
4520 aligned.
4521
4522     %option_range = (
4523         'format'             => [ 'tidy', 'html', 'user' ],
4524         'output-line-ending' => [ 'dos',  'win',  'mac', 'unix' ],
4525         'character-encoding' => [ 'none', 'utf8' ],
4526
4527         'block-brace-tightness'    => [ 0, 2 ],
4528         'brace-tightness'          => [ 0, 2 ],
4529         'paren-tightness'          => [ 0, 2 ],
4530         'square-bracket-tightness' => [ 0, 2 ],
4531     );
4532
4533 Vertical alignment is implemented by locally increasing an existing blank space
4534 to produce alignment with an adjacent line.  It cannot occur if there is no
4535 blank space to increase.  So if a particular space is removed by one of the
4536 existing controls then vertical alignment cannot occur. Likewise, if a space is
4537 added with one of the controls, then vertical alignment might occur.
4538
4539 For example,
4540
4541         # perltidy -nwls='=>'
4542         $data = $pkg->new(
4543             PeerAddr=> join( ".", @port[ 0 .. 3 ] ),
4544             PeerPort=> $port[4] * 256 + $port[5],
4545             Proto=> 'tcp'
4546         );
4547
4548 =over 4
4549
4550 =item B<Completely turning off vertical alignment with -novalign>
4551
4552 The default is to use vertical alignment, but vertical alignment can be
4553 completely turned of with the B<-novalign> flag.
4554
4555 A lower level of control of vertical alignment is possible with three parameters
4556 B<-vc>, B<-vsc>, and B<-vbc>. These independently control alignment
4557 of code, side comments and block comments.  They are described in the
4558 next section.
4559
4560 The parameter B<-valign> is in fact an alias for B<-vc -vsc -vbc>, and its
4561 negative B<-novalign> is an alias for B<-nvc -nvsc -nvbc>.
4562
4563 =item B<Controlling code alignment with --valign-code or -vc>
4564
4565 The B<-vc> flag enables alignment of code symbols such as B<=>.  The default is B<-vc>.
4566 For detailed control of which symbols to align, see the B<-valign-exclude-list> parameter
4567 below.
4568
4569 =item B<Controlling side comment alignment with --valign-side-comments or -vsc>
4570
4571 The B<-vsc> flag enables alignment of side comments and is enabled by default.  If side
4572 comment alignment is disabled with B<-nvsc> they will appear at a fixed space from the
4573 preceding code token.  The default is B<-vsc>
4574
4575 =item B<Controlling block comment alignment with --valign-block-comments or -vbc>
4576
4577 When B<-vbc> is enabled, block comments can become aligned for example if one
4578 comment of a consecutive sequence of comments becomes outdented due a length in
4579 excess of the maximum line length.  If this occurs, the entire group of
4580 comments will remain aligned and be outdented by the same amount.  This coordinated
4581 alignment will not occur if B<-nvbc> is set.  The default is B<-vbc>.
4582
4583 =item B<Finer alignment control with --valign-exclusion-list=s or -vxl=s and --valign-inclusion-list=s or -vil=s>
4584
4585 More detailed control of alignment types is available with these two
4586 parameters.  Most of the vertical alignments in typical programs occur at one
4587 of the tokens ',', '=', and '=>', but many other alignments are possible and are given in the following list:
4588
4589   = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x=
4590   { ( ? : , ; => && || ~~ !~~ =~ !~ // <=> -> q
4591   if unless and or err for foreach while until
4592
4593 These alignment types correspond to perl symbols, operators and keywords except
4594 for 'q', which refers to the special case of alignment in a 'use' statement of
4595 qw quotes and empty parens. 
4596
4597 They are all enabled by default, but they can be selectively disabled by including one or more of these tokens in the space-separated list B<valign-exclusion-list=s>.
4598 For example, the following would prevent alignment at B<=> and B<if>:
4599
4600   --valign-exclusion-list='= if'
4601
4602 If it is simpler to specify only the token types which are to be aligned, then
4603 include the types which are to be aligned in the list of B<--valign-inclusion-list>.
4604 In that case you may leave the B<valign-exclusion-list> undefined, or use the special symbol B<*> for the exclusion list.
4605 For example, the following parameters enable alignment only at commas and 'fat commas':
4606
4607   --valign-inclusion-list=', =>'
4608   --valign-exclusion-list='*'     ( this is optional and may be omitted )
4609
4610 These parameter lists should consist of space-separated tokens from the above
4611 list of possible alignment tokens, or a '*'.  If an unrecognized token
4612 appears, it is simply ignored. And if a specific token is entered in both lists by
4613 mistake then the exclusion list has priority.
4614
4615 The default values of these parameters enable all alignments and are equivalent to
4616
4617   --valign-exclusion-list=' '
4618   --valign-inclusion-list='*'
4619
4620 To illustrate, consider the following snippet with default formatting
4621
4622     # perltidy
4623     $co_description = ($color) ? 'bold cyan'  : '';           # description
4624     $co_prompt      = ($color) ? 'bold green' : '';           # prompt
4625     $co_unused      = ($color) ? 'on_green'   : 'reverse';    # unused
4626
4627 To exclude all alignments except the equals (i.e., include only equals) we could use:
4628
4629     # perltidy -vil='='
4630     $co_description = ($color) ? 'bold cyan' : '';          # description
4631     $co_prompt      = ($color) ? 'bold green' : '';         # prompt
4632     $co_unused      = ($color) ? 'on_green' : 'reverse';    # unused
4633
4634 To exclude only the equals we could use:
4635
4636     # perltidy -vxl='='
4637     $co_description = ($color) ? 'bold cyan' : '';     # description
4638     $co_prompt = ($color) ? 'bold green' : '';         # prompt
4639     $co_unused = ($color) ? 'on_green' : 'reverse';    # unused
4640
4641 Notice in this last example that although only the equals alignment was
4642 excluded, the ternary alignments were also lost.  This happens because the
4643 vertical aligner sweeps from left-to-right and usually stops if an important
4644 alignment cannot be made for some reason.
4645
4646 But also notice that side comments remain aligned because their alignment is
4647 controlled separately with the parameter B<--valign-side_comments> described above.
4648
4649 =back
4650
4651 =head2 Extended Syntax
4652
4653 This section describes some parameters for dealing with extended syntax.
4654
4655 For another method of handling extended syntax see the section L<"Skipping Selected Sections of Code">.
4656
4657 Also note that the module F<Perl::Tidy> supplies a pre-filter and post-filter capability. This requires calling the module from a separate program rather than through the binary F<perltidy>. 
4658
4659 =over 4
4660
4661 =item B<-xs>,   B<--extended-syntax>
4662
4663 This flag allows perltidy to handle certain common extensions
4664 to the standard syntax without complaint.
4665
4666 For example, without this flag a structure such as the following would generate
4667 a syntax error:
4668
4669     Method deposit( Num $amount) {
4670         $self->balance( $self->balance + $amount );
4671     }
4672
4673 This flag is enabled by default but it can be deactivated with B<-nxs>.
4674 Probably the only reason to deactivate this flag is to generate more diagnostic
4675 messages when debugging a script.
4676
4677 =item B<-sal=s>,   B<--sub-alias-list=s>
4678
4679 This flag causes one or more words to be treated the same as if they were the keyword B<sub>.  The string B<s> contains one or more alias words, separated by spaces or commas.
4680
4681 For example,
4682
4683         perltidy -sal='method fun _sub M4'
4684
4685 will cause the perltidy to treat the words 'method', 'fun', '_sub' and 'M4' the same as if they were 'sub'.  Note that if the alias words are separated by spaces then the string of words should be placed in quotes.
4686
4687 Note that several other parameters accept a list of keywords, including 'sub' (see L<"Specifying Block Types">).
4688 You do not need to include any sub aliases in these lists. Just include keyword 'sub' if you wish, and all aliases are automatically included.
4689
4690 =item B<-gal=s>,   B<--grep-alias-list=s>
4691
4692 This flag allows a code block following an external 'list operator' function to be formatted as if it followed one of the built-in keywords B<grep>,  B<map> or B<sort>.  The string B<s> contains the names of one or more such list operators, separated by spaces or commas.
4693
4694 By 'list operator' is meant a function which is invoked in the form
4695
4696       word {BLOCK} @list
4697
4698 Perltidy tries to keep code blocks for these functions intact, since they are usually short, and does not automatically break after the closing brace since a list may follow. It also does some special handling of continuation indentation.
4699
4700 For example, the code block arguments to functions 'My_grep' and 'My_map' can be given formatting like 'grep' with
4701
4702         perltidy -gal='My_grep My_map'
4703
4704 By default, the following list operators in List::Util are automatically included:
4705
4706       all any first none notall reduce reductions
4707
4708 Any operators specified with B<--grep-alias-list> are added to this list.
4709 The next parameter can be used to remove words from this default list.
4710
4711 =item B<-gaxl=s>,   B<--grep-alias-exclusion-list=s>
4712
4713 The B<-gaxl=s> flag provides a method for removing any of the default list operators given above
4714 by listing them in the string B<s>.  To remove all of the default operators use B<-gaxl='*'>.
4715
4716 =item B<-uf=s>,   B<--use-feature=s>
4717
4718 This flag tells perltidy to allow the syntax associated a pragma in string
4719 B<s>. Currently only the recognized values for the string are B<s='class'> or
4720 string B<s=' '>.  The default is B<--use-feature='class'>.  This enables
4721 perltidy to recognized the special words B<class>, B<method>, B<field>, and
4722 B<ADJUST>.  If this causes a conflict with other uses of these words, the
4723 default can be turned off with B<--use-feature=' '>.
4724
4725 =back
4726
4727 =head2 Other Controls
4728
4729 =over 4
4730
4731 =item B<Deleting selected text>
4732
4733 Perltidy can selectively delete comments and/or pod documentation.  The
4734 command B<-dac> or  B<--delete-all-comments> will delete all comments
4735 B<and> all pod documentation, leaving just code and any leading system
4736 control lines.
4737
4738 The command B<-dp> or B<--delete-pod> will remove all pod documentation
4739 (but not comments).
4740
4741 Two commands which remove comments (but not pod) are: B<-dbc> or
4742 B<--delete-block-comments> and B<-dsc> or  B<--delete-side-comments>.
4743 (Hanging side comments will be deleted with side comments here.)
4744
4745 When side comments are deleted, any special control side comments for
4746 non-indenting braces will be retained unless they are deactivated with
4747 a B<-nnib> flag.
4748
4749 The negatives of these commands also work, and are the defaults.  When
4750 block comments are deleted, any leading 'hash-bang' will be retained.
4751 Also, if the B<-x> flag is used, any system commands before a leading
4752 hash-bang will be retained (even if they are in the form of comments).
4753
4754 =item B<Writing selected text to a file>
4755
4756 When perltidy writes a formatted text file, it has the ability to also
4757 send selected text to a file with a F<.TEE> extension.  This text can
4758 include comments and pod documentation.
4759
4760 The command B<-tac> or  B<--tee-all-comments> will write all comments
4761 B<and> all pod documentation.
4762
4763 The command B<-tp> or B<--tee-pod> will write all pod documentation (but
4764 not comments).
4765
4766 The commands which write comments (but not pod) are: B<-tbc> or
4767 B<--tee-block-comments> and B<-tsc> or  B<--tee-side-comments>.
4768 (Hanging side comments will be written with side comments here.)
4769
4770 The negatives of these commands also work, and are the defaults.
4771
4772 =item B<Using a F<.perltidyrc> command file>
4773
4774 If you use perltidy frequently, you probably won't be happy until you
4775 create a F<.perltidyrc> file to avoid typing commonly-used parameters.
4776 Perltidy will first look in your current directory for a command file
4777 named F<.perltidyrc>.  If it does not find one, it will continue looking
4778 for one in other standard locations.
4779
4780 These other locations are system-dependent, and may be displayed with
4781 the command C<perltidy -dpro>.  Under Unix systems, it will first look
4782 for an environment variable B<PERLTIDY>.  Then it will look for a
4783 F<.perltidyrc> file in the home directory, and then for a system-wide
4784 file F</usr/local/etc/perltidyrc>, and then it will look for
4785 F</etc/perltidyrc>.  Note that these last two system-wide files do not
4786 have a leading dot.  Further system-dependent information will be found
4787 in the INSTALL file distributed with perltidy.
4788
4789 Under Windows, perltidy will also search for a configuration file named F<perltidy.ini> since Windows does not allow files with a leading period (.).
4790 Use C<perltidy -dpro> to see the possible locations for your system.
4791 An example might be F<C:\Documents and Settings\All Users\perltidy.ini>.
4792
4793 Another option is the use of the PERLTIDY environment variable.
4794 The method for setting environment variables depends upon the version of
4795 Windows that you are using.  Instructions for Windows 95 and later versions can
4796 be found here:
4797
4798 http://www.netmanage.com/000/20021101_005_tcm21-6336.pdf
4799
4800 Under Windows NT / 2000 / XP the PERLTIDY environment variable can be placed in
4801 either the user section or the system section.  The later makes the
4802 configuration file common to all users on the machine.  Be sure to enter the
4803 full path of the configuration file in the value of the environment variable.
4804 Ex.  PERLTIDY=C:\Documents and Settings\perltidy.ini
4805
4806 The configuration file is free format, and simply a list of parameters, just as
4807 they would be entered on a command line.  Any number of lines may be used, with
4808 any number of parameters per line, although it may be easiest to read with one
4809 parameter per line.  Comment text begins with a #, and there must
4810 also be a space before the # for side comments.  It is a good idea to
4811 put complex parameters in either single or double quotes.
4812
4813 Here is an example of a F<.perltidyrc> file:
4814
4815   # This is a simple of a .perltidyrc configuration file
4816   # This implements a highly spaced style
4817   -se    # errors to standard error output
4818   -w     # show all warnings
4819   -bl    # braces on new lines
4820   -pt=0  # parens not tight at all
4821   -bt=0  # braces not tight
4822   -sbt=0 # square brackets not tight
4823
4824 The parameters in the F<.perltidyrc> file are installed first, so any
4825 parameters given on the command line will have priority over them.
4826
4827 To avoid confusion, perltidy ignores any command in the .perltidyrc
4828 file which would cause some kind of dump and an exit.  These are:
4829
4830  -h -v -ddf -dln -dop -dsn -dtt -dwls -dwrs -ss
4831
4832 There are several options may be helpful in debugging a F<.perltidyrc>
4833 file:
4834
4835 =over 4
4836
4837 =item *
4838
4839 A very helpful command is B<--dump-profile> or B<-dpro>.  It writes a
4840 list of all configuration filenames tested to standard output, and
4841 if a file is found, it dumps the content to standard output before
4842 exiting.  So, to find out where perltidy looks for its configuration
4843 files, and which one if any it selects, just enter
4844
4845   perltidy -dpro
4846
4847 =item *
4848
4849 It may be simplest to develop and test configuration files with
4850 alternative names, and invoke them with B<-pro=filename> on the command
4851 line.  Then rename the desired file to F<.perltidyrc> when finished.
4852
4853 =item *
4854
4855 The parameters in the F<.perltidyrc> file can be switched off with
4856 the B<-npro> option.
4857
4858 =item *
4859
4860 The commands B<--dump-options>, B<--dump-defaults>, B<--dump-long-names>,
4861 and B<--dump-short-names>, all described below, may all be helpful.
4862
4863 =back
4864
4865 =item B<Creating a new abbreviation>
4866
4867 A special notation is available for use in a F<.perltidyrc> file
4868 for creating an abbreviation for a group
4869 of options.  This can be used to create a
4870 shorthand for one or more styles which are frequently, but not always,
4871 used.  The notation is to group the options within curly braces which
4872 are preceded by the name of the alias (without leading dashes), like this:
4873
4874         newword {
4875         -opt1
4876         -opt2
4877         }
4878
4879 where B<newword> is the abbreviation, and B<opt1>, etc, are existing parameters
4880 I<or other abbreviations>.  The main syntax requirement is that the new
4881 abbreviation along with its opening curly brace must begin on a new line.
4882 Space before and after the curly braces is optional.
4883
4884 For a specific example, the following line
4885
4886         oneliner { --maximum-line-length=0 --noadd-newlines --noadd-terminal-newline}
4887
4888 or equivalently with abbreviations
4889
4890         oneliner { -l=0 -nanl -natnl }
4891
4892 could be placed in a F<.perltidyrc> file to temporarily override the maximum
4893 line length with a large value, to temporarily prevent new line breaks from
4894 being added, and to prevent an extra newline character from being added the
4895 file.  All other settings in the F<.perltidyrc> file still apply.  Thus it
4896 provides a way to format a long 'one liner' when perltidy is invoked with
4897
4898         perltidy --oneliner ...
4899
4900 (Either C<-oneliner> or C<--oneliner> may be used).
4901
4902 =item Skipping leading non-perl commands with B<-x> or B<--look-for-hash-bang>
4903
4904 If your script has leading lines of system commands or other text which
4905 are not valid perl code, and which are separated from the start of the
4906 perl code by a "hash-bang" line, ( a line of the form C<#!...perl> ),
4907 you must use the B<-x> flag to tell perltidy not to parse and format any
4908 lines before the "hash-bang" line.  This option also invokes perl with a
4909 -x flag when checking the syntax.  This option was originally added to
4910 allow perltidy to parse interactive VMS scripts, but it should be used
4911 for any script which is normally invoked with C<perl -x>.
4912
4913 Please note: do not use this flag unless you are sure your script needs it.
4914 Parsing errors can occur if it does not have a hash-bang, or, for example, if
4915 the actual first hash-bang is in a here-doc. In that case a parsing error will
4916 occur because the tokenization will begin in the middle of the here-doc.
4917
4918 =item B<Making a file unreadable>
4919
4920 The goal of perltidy is to improve the readability of files, but there
4921 are two commands which have the opposite effect, B<--mangle> and
4922 B<--extrude>.  They are actually
4923 merely aliases for combinations of other parameters.  Both of these
4924 strip all possible whitespace, but leave comments and pod documents,
4925 so that they are essentially reversible.  The
4926 difference between these is that B<--mangle> puts the fewest possible
4927 line breaks in a script while B<--extrude> puts the maximum possible.
4928 Note that these options do not provided any meaningful obfuscation, because
4929 perltidy can be used to reformat the files.  They were originally
4930 developed to help test the tokenization logic of perltidy, but they
4931 have other uses.
4932 One use for B<--mangle> is the following:
4933
4934   perltidy --mangle myfile.pl -st | perltidy -o myfile.pl.new
4935
4936 This will form the maximum possible number of one-line blocks (see next
4937 section), and can sometimes help clean up a badly formatted script.
4938
4939 A similar technique can be used with B<--extrude> instead of B<--mangle>
4940 to make the minimum number of one-line blocks.
4941
4942 Another use for B<--mangle> is to combine it with B<-dac> to reduce
4943 the file size of a perl script.
4944
4945 =item B<Debugging>
4946
4947 The following flags are available for debugging:
4948
4949 B<--dump-cuddled-block-list> or B<-dcbl> will dump to standard output the
4950 internal hash of cuddled block types created by a B<-cuddled-block-list> input
4951 string.
4952
4953 B<--dump-defaults> or B<-ddf> will write the default option set to standard output and quit
4954
4955 B<--dump-profile> or B<-dpro>  will write the name of the current
4956 configuration file and its contents to standard output and quit.
4957
4958 B<--dump-options> or B<-dop>  will write current option set to standard
4959 output and quit.
4960
4961 B<--dump-long-names> or B<-dln>  will write all command line long names (passed
4962 to Get_options) to standard output and quit.
4963
4964 B<--dump-short-names>  or B<-dsn> will write all command line short names
4965 to standard output and quit.
4966
4967 B<--dump-token-types> or B<-dtt>  will write a list of all token types
4968 to standard output and quit.
4969
4970 B<--dump-want-left-space> or B<-dwls>  will write the hash %want_left_space
4971 to standard output and quit.  See the section on controlling whitespace
4972 around tokens.
4973
4974 B<--dump-want-right-space> or B<-dwrs>  will write the hash %want_right_space
4975 to standard output and quit.  See the section on controlling whitespace
4976 around tokens.
4977
4978 B<--no-memoize> or B<-nmem>  will turn of memoizing.
4979 Memoization can reduce run time when running perltidy repeatedly in a
4980 single process.  It is on by default but can be deactivated for
4981 testing with B<-nmem>.
4982
4983 B<--no-timestamp> or B<-nts> will eliminate any time stamps in output files to prevent
4984 differences in dates from causing test installation scripts to fail. There are just
4985 a couple of places where timestamps normally occur. One is in the headers of
4986 html files, and another is when the B<-cscw> option is selected. The default is
4987 to allow timestamps (B<--timestamp> or B<-ts>).
4988
4989 B<--file-size-order> or B<-fso> will cause files to be processed in order of
4990 increasing size, when multiple files are being processed.  This is useful
4991 during program development, when large numbers of files with varying sizes are
4992 processed, because it can reduce virtual memory usage.
4993
4994 B<--maximum-file-size-mb=n> or B<-maxfs=n> specifies the maximum file size in
4995 megabytes that perltidy will attempt to format. This parameter is provided to
4996 avoid causing system problems by accidentally attempting to format an extremely
4997 large data file. Most perl scripts are less than about 2 MB in size. The
4998 integer B<n> has a default value of 10, so perltidy will skip formatting files
4999 which have a size greater than 10 MB.  The command to increase the limit to 20
5000 MB for example would be
5001
5002   perltidy -maxfs=20
5003
5004 This only applies to files specified by filename on the command line.
5005
5006 B<--maximum-level-errors=n> or B<-maxle=n> specifies the maximum number of
5007 indentation level errors are allowed before perltidy skips formatting and just
5008 outputs a file verbatim.  The default is B<n=1>.  This means that if the final
5009 indentation of a script differs from the starting indentation by more than 1
5010 levels, the file will be output verbatim.  To avoid formatting if there are any
5011 indentation level errors use -maxle=0. To skip this check you can either set n
5012 equal to a large number, such as B<n=100>, or set B<n=-1>.
5013
5014 For example, the following script has level error of 3 and will be output verbatim
5015
5016     Input and default output:
5017     {{{
5018
5019
5020     perltidy -maxle=100
5021     {
5022         {
5023             {
5024
5025 B<--maximum-unexpected-errors=n> or B<-maxue=n> specifies the maximum number of
5026 unexpected tokenization errors are allowed before formatting is skipped and a
5027 script is output verbatim.  The intention is to avoid accidentally formatting
5028 a non-perl script, such as an html file for example.  This check can be turned
5029 off by setting B<n=0>.
5030
5031 A recommended value is B<n=3>.  However, the default is B<n=0> (skip this check)
5032 to avoid causing problems with scripts which have extended syntaxes.
5033
5034 B<-DEBUG>  will write a file with extension F<.DEBUG> for each input file
5035 showing the tokenization of all lines of code.
5036
5037 =item B<Making a table of information on code blocks>
5038
5039 A table listing information about the blocks of code in a file can be made with
5040 B<--dump-block-summary>, or B<-dbs>.  This causes perltidy to read and parse
5041 the file, write a table of comma-separated values for selected code blocks to
5042 the standard output, and then exit.  This parameter must be on the command
5043 line, not in a F<.perlticyrc> file, and it requires a single file name on the
5044 command line.  For example
5045
5046    perltidy -dbs somefile.pl >blocks.csv
5047
5048 produces an output file F<blocks.csv> whose lines hold these
5049 parameters:
5050
5051     filename     - the name of the file
5052     line         - the line number of the opening brace of this block
5053     line_count   - the number of lines between opening and closing braces
5054     code_lines   - the number of lines excluding blanks, comments, and pod
5055     type         - the block type (sub, for, foreach, ...)
5056     name         - the block name if applicable (sub name, label, asub name)
5057     depth        - the nesting depth of the opening block brace
5058     max_change   - the change in depth to the most deeply nested code block
5059     block_count  - the total number of code blocks nested in this block
5060     mccabe_count - the McCabe complexity measure of this code block
5061
5062 This feature was developed to help identify complex sections of code as an aid
5063 in refactoring.  The McCabe complexity measure follows the definition used by
5064 Perl::Critic.  By default the table contains these values for subroutines, but
5065 the user may request them for any or all blocks of code or packages.  For
5066 blocks which are loops nested within loops, a postfix '+' to the C<type> is
5067 added to indicate possible code complexity.  Although the table does not
5068 otherwise indicate which blocks are nested in other blocks, this can be
5069 determined by computing and comparing the block ending line numbers.
5070
5071 By default the table lists subroutines with more than 20 C<code_lines>, but
5072 this can be changed with the following two parameters:
5073
5074 B<--dump-block-minimum-lines=n>, or B<-dbl=n>, where B<n> is the minimum
5075 number of C<code_lines> to be included. The default is B<-n=20>.  Note that
5076 C<code_lines> is the number of lines excluding and comments, blanks and pod.
5077
5078 B<--dump-block-types=s>, or B<-dbt=s>, where string B<s> is a list of block
5079 types to be included.  The type of a block is either the name of the perl
5080 builtin keyword for that block (such as B<sub if elsif else for foreach ..>) or
5081 the word immediately before the opening brace.  In addition, there are
5082 a few symbols for special block types, as follows:
5083
5084    if elsif else for foreach ... any keyword introducing a block
5085    sub  - any sub or anynomous sub
5086    asub - any anonymous sub
5087    *    - any block except nameless blocks
5088    +    - any nested inner block loop
5089    package - any package or class
5090    closure - any nameless block
5091
5092 In addition, specific block loop types which are nested in other loops can be
5093 selected by adding a B<+> after the block name. (Nested loops are sometimes
5094 good candidates for restructuring).
5095
5096 The default is B<-dbt='sub'>.
5097
5098 In the following examples a table C<block.csv> is created for a file
5099 C<somefile.pl>:
5100
5101 =over 4
5102
5103 =item *
5104 This selects both C<subs> and C<packages> which have 20 or more lines of code.
5105 This can be useful in code which contains multiple packages.
5106
5107     perltidy -dbs -dbt='sub package' somefile.pl >blocks.csv
5108
5109 =item *
5110 This selects block types C<sub for foreach while> with 10 or more code lines.
5111
5112     perltidy -dbs -dbl=10 -dbt='sub for foreach while' somefile.pl >blocks.csv
5113
5114 =item *
5115 This selects blocks with 2 or more code lines which are type C<sub> or which
5116 are inner loops.
5117
5118     perltidy -dbs -dbl=2 -dbt='sub +' somefile.pl >blocks.csv
5119
5120 =item *
5121 This selects every block and package.
5122
5123     perltidy -dbs -dbl=1 -dbt='* closure' somefile.pl >blocks.csv
5124
5125 =back
5126
5127
5128 =item B<Working with MakeMaker, AutoLoader and SelfLoader>
5129
5130 The first $VERSION line of a file which might be eval'd by MakeMaker
5131 is passed through unchanged except for indentation.
5132 Use B<--nopass-version-line>, or B<-npvl>, to deactivate this feature.
5133
5134 If the AutoLoader module is used, perltidy will continue formatting
5135 code after seeing an __END__ line.
5136 Use B<--nolook-for-autoloader>, or B<-nlal>, to deactivate this feature.
5137
5138 Likewise, if the SelfLoader module is used, perltidy will continue formatting
5139 code after seeing a __DATA__ line.
5140 Use B<--nolook-for-selfloader>, or B<-nlsl>, to deactivate this feature.
5141
5142 =item B<Working around problems with older version of Perl>
5143
5144 Perltidy contains a number of rules which help avoid known subtleties
5145 and problems with older versions of perl, and these rules always
5146 take priority over whatever formatting flags have been set.  For example,
5147 perltidy will usually avoid starting a new line with a bareword, because
5148 this might cause problems if C<use strict> is active.
5149
5150 There is no way to override these rules.
5151
5152 =back
5153
5154 =head1 HTML OPTIONS
5155
5156 =over 4
5157
5158 =item  The B<-html> master switch
5159
5160 The flag B<-html> causes perltidy to write an html file with extension
5161 F<.html>.  So, for example, the following command
5162
5163         perltidy -html somefile.pl
5164
5165 will produce a syntax-colored html file named F<somefile.pl.html>
5166 which may be viewed with a browser.
5167
5168 B<Please Note>: In this case, perltidy does not do any formatting to the
5169 input file, and it does not write a formatted file with extension
5170 F<.tdy>.  This means that two perltidy runs are required to create a
5171 fully reformatted, html copy of a script.
5172
5173 =item  The B<-pre> flag for code snippets
5174
5175 When the B<-pre> flag is given, only the pre-formatted section, within
5176 the <PRE> and </PRE> tags, will be output.  This simplifies inclusion
5177 of the output in other files.  The default is to output a complete
5178 web page.
5179
5180 =item  The B<-nnn> flag for line numbering
5181
5182 When the B<-nnn> flag is given, the output lines will be numbered.
5183
5184 =item  The B<-toc>, or B<--html-table-of-contents> flag
5185
5186 By default, a table of contents to packages and subroutines will be
5187 written at the start of html output.  Use B<-ntoc> to prevent this.
5188 This might be useful, for example, for a pod document which contains a
5189 number of unrelated code snippets.  This flag only influences the code
5190 table of contents; it has no effect on any table of contents produced by
5191 pod2html (see next item).
5192
5193 =item  The B<-pod>, or B<--pod2html> flag
5194
5195 There are two options for formatting pod documentation.  The default is
5196 to pass the pod through the Pod::Html module (which forms the basis of
5197 the pod2html utility).  Any code sections are formatted by perltidy, and
5198 the results then merged.  Note: perltidy creates a temporary file when
5199 Pod::Html is used; see L<"FILES">.  Also, Pod::Html creates temporary
5200 files for its cache.
5201
5202 NOTE: Perltidy counts the number of C<=cut> lines, and either moves the
5203 pod text to the top of the html file if there is one C<=cut>, or leaves
5204 the pod text in its original order (interleaved with code) otherwise.
5205
5206 Most of the flags accepted by pod2html may be included in the perltidy
5207 command line, and they will be passed to pod2html.  In some cases,
5208 the flags have a prefix C<pod> to emphasize that they are for the
5209 pod2html, and this prefix will be removed before they are passed to
5210 pod2html.  The flags which have the additional C<pod> prefix are:
5211
5212    --[no]podheader --[no]podindex --[no]podrecurse --[no]podquiet
5213    --[no]podverbose --podflush
5214
5215 The flags which are unchanged from their use in pod2html are:
5216
5217    --backlink=s --cachedir=s --htmlroot=s --libpods=s --title=s
5218    --podpath=s --podroot=s
5219
5220 where 's' is an appropriate character string.  Not all of these flags are
5221 available in older versions of Pod::Html.  See your Pod::Html documentation for
5222 more information.
5223
5224 The alternative, indicated with B<-npod>, is not to use Pod::Html, but
5225 rather to format pod text in italics (or whatever the stylesheet
5226 indicates), without special html markup.  This is useful, for example,
5227 if pod is being used as an alternative way to write comments.
5228
5229 =item  The B<-frm>, or B<--frames> flag
5230
5231 By default, a single html output file is produced.  This can be changed
5232 with the B<-frm> option, which creates a frame holding a table of
5233 contents in the left panel and the source code in the right side. This
5234 simplifies code browsing.  Assume, for example, that the input file is
5235 F<MyModule.pm>.  Then, for default file extension choices, these three
5236 files will be created:
5237
5238  MyModule.pm.html      - the frame
5239  MyModule.pm.toc.html  - the table of contents
5240  MyModule.pm.src.html  - the formatted source code
5241
5242 Obviously this file naming scheme requires that output be directed to a real
5243 file (as opposed to, say, standard output).  If this is not the
5244 case, or if the file extension is unknown, the B<-frm> option will be
5245 ignored.
5246
5247 =item  The B<-text=s>, or B<--html-toc-extension> flag
5248
5249 Use this flag to specify the extra file extension of the table of contents file
5250 when html frames are used.  The default is "toc".
5251 See L<"Specifying File Extensions">.
5252
5253 =item  The B<-sext=s>, or B<--html-src-extension> flag
5254
5255 Use this flag to specify the extra file extension of the content file when html
5256 frames are used.  The default is "src".
5257 See L<"Specifying File Extensions">.
5258
5259 =item  The B<-hent>, or B<--html-entities> flag
5260
5261 This flag controls the use of Html::Entities for html formatting.  By
5262 default, the module Html::Entities is used to encode special symbols.
5263 This may not be the right thing for some browser/language
5264 combinations.  Use --nohtml-entities or -nhent to prevent this.
5265
5266 =item  B<Style Sheets>
5267
5268 Style sheets make it very convenient to control and adjust the
5269 appearance of html pages.  The default behavior is to write a page of
5270 html with an embedded style sheet.
5271
5272 An alternative to an embedded style sheet is to create a page with a
5273 link to an external style sheet.  This is indicated with the
5274 B<-css=filename>,  where the external style sheet is F<filename>.  The
5275 external style sheet F<filename> will be created if and only if it does
5276 not exist.  This option is useful for controlling multiple pages from a
5277 single style sheet.
5278
5279 To cause perltidy to write a style sheet to standard output and exit,
5280 use the B<-ss>, or B<--stylesheet>, flag.  This is useful if the style
5281 sheet could not be written for some reason, such as if the B<-pre> flag
5282 was used.  Thus, for example,
5283
5284   perltidy -html -ss >mystyle.css
5285
5286 will write a style sheet with the default properties to file
5287 F<mystyle.css>.
5288
5289 The use of style sheets is encouraged, but a web page without a style
5290 sheets can be created with the flag B<-nss>.  Use this option if you
5291 must to be sure that older browsers (roughly speaking, versions prior to
5292 4.0 of Netscape Navigator and Internet Explorer) can display the
5293 syntax-coloring of the html files.
5294
5295 =item  B<Controlling HTML properties>
5296
5297 Note: It is usually more convenient to accept the default properties
5298 and then edit the stylesheet which is produced.  However, this section
5299 shows how to control the properties with flags to perltidy.
5300
5301 Syntax colors may be changed from their default values by flags of the either
5302 the long form, B<-html-color-xxxxxx=n>, or more conveniently the short form,
5303 B<-hcx=n>, where B<xxxxxx> is one of the following words, and B<x> is the
5304 corresponding abbreviation:
5305
5306       Token Type             xxxxxx           x
5307       ----------             --------         --
5308       comment                comment          c
5309       number                 numeric          n
5310       identifier             identifier       i
5311       bareword, function     bareword         w
5312       keyword                keyword          k
5313       quite, pattern         quote            q
5314       here doc text          here-doc-text    h
5315       here doc target        here-doc-target  hh
5316       punctuation            punctuation      pu
5317       parentheses            paren            p
5318       structural braces      structure        s
5319       semicolon              semicolon        sc
5320       colon                  colon            co
5321       comma                  comma            cm
5322       label                  label            j
5323       sub definition name    subroutine       m
5324       pod text               pod-text         pd
5325
5326 A default set of colors has been defined, but they may be changed by providing
5327 values to any of the following parameters, where B<n> is either a 6 digit
5328 hex RGB color value or an ascii name for a color, such as 'red'.
5329
5330 To illustrate, the following command will produce an html
5331 file F<somefile.pl.html> with "aqua" keywords:
5332
5333         perltidy -html -hck=00ffff somefile.pl
5334
5335 and this should be equivalent for most browsers:
5336
5337         perltidy -html -hck=aqua somefile.pl
5338
5339 Perltidy merely writes any non-hex names that it sees in the html file.
5340 The following 16 color names are defined in the HTML 3.2 standard:
5341
5342         black   => 000000,
5343         silver  => c0c0c0,
5344         gray    => 808080,
5345         white   => ffffff,
5346         maroon  => 800000,
5347         red     => ff0000,
5348         purple  => 800080,
5349         fuchsia => ff00ff,
5350         green   => 008000,
5351         lime    => 00ff00,
5352         olive   => 808000,
5353         yellow  => ffff00
5354         navy    => 000080,
5355         blue    => 0000ff,
5356         teal    => 008080,
5357         aqua    => 00ffff,
5358
5359 Many more names are supported in specific browsers, but it is safest
5360 to use the hex codes for other colors.  Helpful color tables can be
5361 located with an internet search for "HTML color tables".
5362
5363 Besides color, two other character attributes may be set: bold, and italics.
5364 To set a token type to use bold, use the flag
5365 B<--html-bold-xxxxxx> or B<-hbx>, where B<xxxxxx> or B<x> are the long
5366 or short names from the above table.  Conversely, to set a token type to
5367 NOT use bold, use B<--nohtml-bold-xxxxxx> or B<-nhbx>.
5368
5369 Likewise, to set a token type to use an italic font, use the flag
5370 B<--html-italic-xxxxxx> or B<-hix>, where again B<xxxxxx> or B<x> are the
5371 long or short names from the above table.  And to set a token type to
5372 NOT use italics, use B<--nohtml-italic-xxxxxx> or B<-nhix>.
5373
5374 For example, to use bold braces and lime color, non-bold, italics keywords the
5375 following command would be used:
5376
5377         perltidy -html -hbs -hck=00FF00 -nhbk -hik somefile.pl
5378
5379 The background color can be specified with B<--html-color-background=n>,
5380 or B<-hcbg=n> for short, where n is a 6 character hex RGB value.  The
5381 default color of text is the value given to B<punctuation>, which is
5382 black as a default.
5383
5384 Here are some notes and hints:
5385
5386 1. If you find a preferred set of these parameters, you may want
5387 to create a F<.perltidyrc> file containing them.  See the perltidy man
5388 page for an explanation.
5389
5390 2. Rather than specifying values for these parameters, it is probably
5391 easier to accept the defaults and then edit a style sheet.  The style
5392 sheet contains comments which should make this easy.
5393
5394 3. The syntax-colored html files can be very large, so it may be best to
5395 split large files into smaller pieces to improve download times.
5396
5397 =back
5398
5399 =head1 SOME COMMON INPUT CONVENTIONS
5400
5401 =head2 Specifying Block Types
5402
5403 Several parameters which refer to code block types may be customized by also
5404 specifying an associated list of block types.  The type of a block is the name
5405 of the keyword which introduces that block, such as B<if>, B<else>, or B<sub>.
5406 An exception is a labeled block, which has no keyword, and should be specified
5407 with just a colon.  To specify all blocks use B<'*'>.
5408
5409 The keyword B<sub> indicates a named sub.  For anonymous subs, use the special
5410 keyword B<asub>.
5411
5412 For example, the following parameter specifies C<sub>, labels, C<BEGIN>, and
5413 C<END> blocks:
5414
5415    -cscl="sub : BEGIN END"
5416
5417 (the meaning of the -cscl parameter is described above.)  Note that
5418 quotes are required around the list of block types because of the
5419 spaces.  For another example, the following list specifies all block types
5420 for vertical tightness:
5421
5422    -bbvtl='*'
5423
5424 =head2 Specifying File Extensions
5425
5426 Several parameters allow default file extensions to be overridden.  For
5427 example, a backup file extension may be specified with B<-bext=ext>,
5428 where B<ext> is some new extension.  In order to provides the user some
5429 flexibility, the following convention is used in all cases to decide if
5430 a leading '.' should be used.  If the extension C<ext> begins with
5431 C<A-Z>, C<a-z>, or C<0-9>, then it will be appended to the filename with
5432 an intermediate '.' (or perhaps a '_' on VMS systems).  Otherwise, it
5433 will be appended directly.
5434
5435 For example, suppose the file is F<somefile.pl>.  For C<-bext=old>, a '.' is
5436 added to give F<somefile.pl.old>.  For C<-bext=.old>, no additional '.' is
5437 added, so again the backup file is F<somefile.pl.old>.  For C<-bext=~>, then no
5438 dot is added, and the backup file will be F<somefile.pl~>  .
5439
5440 =head1 SWITCHES WHICH MAY BE NEGATED
5441
5442 The following list shows all short parameter names which allow a prefix
5443 'n' to produce the negated form:
5444
5445  D      anl    asbl   asc    ast    asu    atc    atnl   aws    b
5446  baa    baao   bar    bbao   bbb    bbc    bbs    bl     bli    boa
5447  boc    bok    bol    bom    bos    bot    cblx   ce     conv   cpb
5448  cs     csc    cscb   cscw   dac    dbc    dbs    dcbl   dcsc   ddf
5449  dln    dnl    dop    dp     dpro   drc    dsc    dsm    dsn    dtc
5450  dtt    dwic   dwls   dwrs   dws    eos    f      fll    fpva   frm
5451  fs     fso    gcs    hbc    hbcm   hbco   hbh    hbhh   hbi    hbj
5452  hbk    hbm    hbn    hbp    hbpd   hbpu   hbq    hbs    hbsc   hbv
5453  hbw    hent   hic    hicm   hico   hih    hihh   hii    hij    hik
5454  him    hin    hip    hipd   hipu   hiq    his    hisc   hiv    hiw
5455  hsc    html   ibc    icb    icp    iob    isbc   iscl   kgb    kgbd
5456  kgbi   kis    lal    log    lop    lp     lsl    mem    nib    ohbr
5457  okw    ola    olc    oll    olq    opr    opt    osbc   osbr   otr
5458  ple    pod    pvl    q      sac    sbc    sbl    scbb   schb   scp
5459  scsb   sct    se     sfp    sfs    skp    sob    sobb   sohb   sop
5460  sosb   sot    ssc    st     sts    t      tac    tbc    toc    tp
5461  tqw    trp    ts     tsc    tso    vbc    vc     vmll   vsc    w
5462  wfc    wn     x      xci    xlp    xs
5463
5464 Equivalently, the prefix 'no' or 'no-' on the corresponding long names may be
5465 used.
5466
5467 =head1 LIMITATIONS
5468
5469 =over 4
5470
5471 =item  B<Parsing Limitations>
5472
5473 Perltidy should work properly on most perl scripts.  It does a lot of
5474 self-checking, but still, it is possible that an error could be
5475 introduced and go undetected.  Therefore, it is essential to make
5476 careful backups and to test reformatted scripts.
5477
5478 The main current limitation is that perltidy does not scan modules
5479 included with 'use' statements.  This makes it necessary to guess the
5480 context of any bare words introduced by such modules.  Perltidy has good
5481 guessing algorithms, but they are not infallible.  When it must guess,
5482 it leaves a message in the log file.
5483
5484 If you encounter a bug, please report it.
5485
5486 =item  B<What perltidy does not parse and format>
5487
5488 Perltidy indents but does not reformat comments and C<qw> quotes.
5489 Perltidy does not in any way modify the contents of here documents or
5490 quoted text, even if they contain source code.  (You could, however,
5491 reformat them separately).  Perltidy does not format 'format' sections
5492 in any way.  And, of course, it does not modify pod documents.
5493
5494 =back
5495
5496 =head1 FILES
5497
5498 =over 4
5499
5500 =item B<Temporary files>
5501
5502 Under the -html option with the default --pod2html flag, a temporary file is
5503 required to pass text to Pod::Html.  Unix systems will try to use the POSIX
5504 tmpnam() function.  Otherwise the file F<perltidy.TMP> will be temporarily
5505 created in the current working directory.
5506
5507 =item B<Special files when standard input is used>
5508
5509 When standard input is used, the log file, if saved, is F<perltidy.LOG>,
5510 and any errors are written to F<perltidy.ERR> unless the B<-se> flag is
5511 set.  These are saved in the current working directory.
5512
5513 =item B<Files overwritten>
5514
5515 The following file extensions are used by perltidy, and files with these
5516 extensions may be overwritten or deleted: F<.ERR>, F<.LOG>, F<.TEE>,
5517 and/or F<.tdy>, F<.html>, and F<.bak>, depending on the run type and
5518 settings.
5519
5520 =item  B<Files extensions limitations>
5521
5522 Perltidy does not operate on files for which the run could produce a file with
5523 a duplicated file extension.  These extensions include F<.LOG>, F<.ERR>,
5524 F<.TEE>, and perhaps F<.tdy> and F<.bak>, depending on the run type.  The
5525 purpose of this rule is to prevent generating confusing filenames such as
5526 F<somefile.tdy.tdy.tdy>.
5527
5528 =back
5529
5530 =head1 ERROR HANDLING
5531
5532 An exit value of 0, 1, or 2 is returned by perltidy to indicate the status of the result.
5533
5534 A exit value of 0 indicates that perltidy ran to completion with no error messages.
5535
5536 A non-zero exit value indicates some kind of problem was detected.
5537
5538 An exit value of 1 indicates that perltidy terminated prematurely, usually due
5539 to some kind of errors in the input parameters.  This can happen for example if
5540 a parameter is misspelled or given an invalid value.  Error messages in the
5541 standard error output will indicate the cause of any problem.  If perltidy
5542 terminates prematurely then no output files will be produced.
5543
5544 An exit value of 2 indicates that perltidy was able to run to completion but
5545 there there are (1) warning messages in the standard error output related to
5546 parameter errors or problems and/or (2) warning messages in the perltidy error
5547 file(s) relating to possible syntax errors in one or more of the source
5548 script(s) being tidied.  When multiple files are being processed, an error
5549 detected in any single file will produce this type of exit condition.
5550
5551 =head1 SEE ALSO
5552
5553 perlstyle(1), Perl::Tidy(3)
5554
5555 =head1 INSTALLATION
5556
5557 The perltidy binary uses the Perl::Tidy module and is installed when that module is installed.  The module name is case-sensitive.  For example, the basic command for installing with cpanm is 'cpanm Perl::Tidy'.
5558
5559 =head1 VERSION
5560
5561 This man page documents perltidy version 20230309
5562
5563 =head1 BUG REPORTS
5564
5565 The source code repository is at L<https://github.com/perltidy/perltidy>.
5566
5567 To report a new bug or problem, use the "issues" link on this page.
5568
5569 =head1 COPYRIGHT
5570
5571 Copyright (c) 2000-2022 by Steve Hancock
5572
5573 =head1 LICENSE
5574
5575 This package is free software; you can redistribute it and/or modify it
5576 under the terms of the "GNU General Public License".
5577
5578 Please refer to the file "COPYING" for details.
5579
5580 =head1 DISCLAIMER
5581
5582 This package is distributed in the hope that it will be useful,
5583 but WITHOUT ANY WARRANTY; without even the implied warranty of
5584 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5585
5586 See the "GNU General Public License" for more details.