From: Steve Hancock Date: Tue, 6 Dec 2022 17:40:56 +0000 (-0800) Subject: document --dump-block-summary X-Git-Tag: 20221112.02~21 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=eff48db8c418e627aa7939f7ab095fab4b00f54e;p=perltidy.git document --dump-block-summary --- diff --git a/CHANGES.md b/CHANGES.md index 70ba95e3..2bfc7bc1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,7 +3,8 @@ ## 2022 11 12.01 - Added option -dbs, or --dump-block-summary, to dump summary - information about code blocks in a file to standard output. + information about code blocks in a file to standard output. The + man page file, bin/perltidy, has a description. ## 2022 11 12 diff --git a/bin/perltidy b/bin/perltidy index f5870e2c..1f67f426 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -4994,6 +4994,56 @@ to avoid causing problems with scripts which have extended syntaxes. B<-DEBUG> will write a file with extension F<.DEBUG> for each input file showing the tokenization of all lines of code. +=item B + +A table listing information about the blocks of code in a file can be made with +B<--dump-block-summary>, or B<-dbs>. This causes perltidy to read and parse +the file, write a table of comma-separated values for selected code blocks to +the standard output, and then exit. This parameter must be on the command +line, not in a F<.perlticyrc> file, and it requires a single file name on the +command line. For example + + perltidy -dbs somefile.pl >blocks.csv + +produces an output file F whose lines hold these +parameters: + + filename - the name of the file + line - the line number + line_count - the number of lines between opening and closing braces + type - the block type (sub, for, foreach, ...) + name - the block name if applicable (sub name, label, asub name) + level - the starting block nesting level + max_change - the change in level to the deepest block level + total_change - the total positive change in level in the block + +The level changes are computed by monitoring the change in code block stack +depth through the file. The depth increases by one when a block is entered, +and decreases by one when the block is exited. The last item, total_change, is +analogous to the total positive elevation change that a person walking over a +sequence of hills would experience. + +These quantities can be useful for identifying complex code. Although the +table does not indicate which blocks are nested in other blocks, this can be +determined by computing and comparing the block ending line numbers. By default +the table lists subroutines with more than 20 lines, but this can be changed +with the following two parameters: + +B<--dump-block-minimum-lines=n>, or B<-dbml=n>, where B is the minimum +number of lines to be included. The default is B<-n=20>. + +B<--dump-block-types=s>, or B<-dbt=s>, where string B is a list of block +types to be included. The type of a block is either the name of the perl +builtin keyword for that block (such as B) or +the word immediately before the opening brace. The type B selects both +named subs and anonymous subs. The special type B selects just anonymous +subs, and the special type B selects nameless blocks. Finally, the +type B<*> selects all types except closures. For example: + + perltidy -dbs -dbt='sub for foreach while' somefile.pl >blocks.csv + +The default is B<-dbt='sub'>. + =item B The first $VERSION line of a file which might be eval'd by MakeMaker