# perltidy (default)
my @list = ( 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, );
-This formatting loses important information. If we place a side comment on one
-of the lines, for example, we get the following result with with default formatting
-parameters:
+This formatting loses the nice structure. If we place a side comment anywhere
+between the opening and closing parens, the original line break points are
+retained. For example,
my @list = (
- 1, # a side comment, comment, or blank keeps list intact
+ 1, # a side comment forces the original line breakpoints to be kept
1, 1,
1, 2, 1,
1, 3, 3, 1,
1, 4, 6, 4, 1,
);
+The side comment can be a single hash symbol without any text.
We could achieve the same result with a blank line or full comment
-anywhere between the opening and closing parens.
+anywhere between the opening and closing parens. Vertical alignment
+of the list items will still occur if possible.
For another possibility see
the -fs flag in L<Skipping Selected Sections of Code>.
1, 3, 3, 1,
1, 4, 6, 4, 1,);
-A disadvantage of this flag is that all tables in the file
-must already be nicely formatted.
-
+A disadvantage of this flag compared to the methods discussed above is that all
+tables in the file must already be nicely formatted.
=item B<-mft=n>, B<--maximum-fields-per-table=n>
Proto => 'tcp'
);
-Vertical alignment can be completely turned off using B<-novalign>, a flag
-mainly intended for debugging. However, vertical alignment can be forced to
+Vertical alignment can be completely turned off using the B<-novalign> flag
+mentioned below. However, vertical alignment can be forced to
stop and restart by selectively introducing blank lines. For example, a blank
has been inserted in the following code to keep somewhat similar things
aligned.
Proto=> 'tcp'
);
+=over 4
+
+=item B<Completely turning off vertical alignment with -novalign>
+
+The default is to use vertical alignment, but bertical alignment can be
+completely turned of with the B<-novalign> flag.
+
+=back
+
=head2 Other Controls
=over 4
--- /dev/null
+# Created with: ./make_t.pl
+
+# Contents:
+#1 novalign.def
+#2 novalign.novalign
+
+# To locate test #13 you can search for its name or the string '#13'
+
+use strict;
+use Test::More;
+use Carp;
+use Perl::Tidy;
+my $rparams;
+my $rsources;
+my $rtests;
+
+BEGIN {
+
+ ###########################################
+ # BEGIN SECTION 1: Parameter combinations #
+ ###########################################
+ $rparams = {
+ 'def' => "",
+ 'novalign' => "-novalign",
+ };
+
+ ############################
+ # BEGIN SECTION 2: Sources #
+ ############################
+ $rsources = {
+
+ 'novalign' => <<'----------',
+# simple vertical alignment of '=' and '#'
+my $lines = 0; # checksum: #lines
+my $bytes = 0; # checksum: #bytes
+my $sum = 0; # checksum: system V sum
+my $patchdata = 0; # saw patch data
+my $pos = 0; # start of patch data
+my $endkit = 0; # saw end of kit
+my $fail = 0; # failed
+
+----------
+ };
+
+ ####################################
+ # BEGIN SECTION 3: Expected output #
+ ####################################
+ $rtests = {
+
+ 'novalign.def' => {
+ source => "novalign",
+ params => "def",
+ expect => <<'#1...........',
+# simple vertical alignment of '=' and '#'
+my $lines = 0; # checksum: #lines
+my $bytes = 0; # checksum: #bytes
+my $sum = 0; # checksum: system V sum
+my $patchdata = 0; # saw patch data
+my $pos = 0; # start of patch data
+my $endkit = 0; # saw end of kit
+my $fail = 0; # failed
+
+#1...........
+ },
+
+ 'novalign.novalign' => {
+ source => "novalign",
+ params => "novalign",
+ expect => <<'#2...........',
+# simple vertical alignment of '=' and '#'
+my $lines = 0; # checksum: #lines
+my $bytes = 0; # checksum: #bytes
+my $sum = 0; # checksum: system V sum
+my $patchdata = 0; # saw patch data
+my $pos = 0; # start of patch data
+my $endkit = 0; # saw end of kit
+my $fail = 0; # failed
+
+#2...........
+ },
+ };
+
+ my $ntests = 0 + keys %{$rtests};
+ plan tests => $ntests;
+}
+
+###############
+# EXECUTE TESTS
+###############
+
+foreach my $key ( sort keys %{$rtests} ) {
+ my $output;
+ my $sname = $rtests->{$key}->{source};
+ my $expect = $rtests->{$key}->{expect};
+ my $pname = $rtests->{$key}->{params};
+ my $source = $rsources->{$sname};
+ my $params = defined($pname) ? $rparams->{$pname} : "";
+ my $stderr_string;
+ my $errorfile_string;
+ my $err = Perl::Tidy::perltidy(
+ source => \$source,
+ destination => \$output,
+ perltidyrc => \$params,
+ argv => '', # for safety; hide any ARGV from perltidy
+ stderr => \$stderr_string,
+ errorfile => \$errorfile_string, # not used when -se flag is set
+ );
+ if ( $err || $stderr_string || $errorfile_string ) {
+ print STDERR "Error output received for test '$key'\n";
+ if ($err) {
+ print STDERR "An error flag '$err' was returned\n";
+ ok( !$err );
+ }
+ if ($stderr_string) {
+ print STDERR "---------------------\n";
+ print STDERR "<<STDERR>>\n$stderr_string\n";
+ print STDERR "---------------------\n";
+ ok( !$stderr_string );
+ }
+ if ($errorfile_string) {
+ print STDERR "---------------------\n";
+ print STDERR "<<.ERR file>>\n$errorfile_string\n";
+ print STDERR "---------------------\n";
+ ok( !$errorfile_string );
+ }
+ }
+ else {
+ if ( !is( $output, $expect, $key ) ) {
+ my $leno = length($output);
+ my $lene = length($expect);
+ if ( $leno == $lene ) {
+ print STDERR
+"#> Test '$key' gave unexpected output. Strings differ but both have length $leno\n";
+ }
+ else {
+ print STDERR
+"#> Test '$key' gave unexpected output. String lengths differ: output=$leno, expected=$lene\n";
+ }
+ }
+ }
+}