## 2023 03 09.01
+ - Issue git #116. A new flag --valign-if-unless, -viu, was added to
+ allow postfix 'unless' terms to align with postfix 'if' terms. The
+ default remains not to do this.
+
- Fixed git #115. In the two most recent CPAN releases, when the
Perl::Tidy module was called with the source pointing to a file,
but no destination specified, the output went to the standard
But also notice that side comments remain aligned because their alignment is
controlled separately with the parameter B<--valign-side_comments> described above.
+=item B<Aligning postfix unless and if with --valign-if-unless or -viu>
+
+By default, postfix B<if> terms align and postfix B<unless> terms align,
+but separately. For example,
+
+ # perltidy [DEFAULT]
+ print "Tried to add: @ResolveRPM\n" if ( @ResolveRPM and !$Quiet );
+ print "Would need: @DepList\n" if ( @DepList and !$Quiet );
+ print "RPM Output:\n" unless $Quiet;
+ print join( "\n", @RPMOutput ) . "\n" unless $Quiet;
+
+The B<-viu> flag causes a postfix B<unless> to be treated as if it were a
+postfix B<if> for purposes of alignment. Thus
+
+ # perltidy -viu
+ print "Tried to add: @ResolveRPM\n" if ( @ResolveRPM and !$Quiet );
+ print "Would need: @DepList\n" if ( @DepList and !$Quiet );
+ print "RPM Output:\n" unless $Quiet;
+ print join( "\n", @RPMOutput ) . "\n" unless $Quiet;
+
=back
=head2 Extended Syntax
$add_option->( 'valign-side-comments', 'vsc', '!' );
$add_option->( 'valign-exclusion-list', 'vxl', '=s' );
$add_option->( 'valign-inclusion-list', 'vil', '=s' );
+ $add_option->( 'valign-if-unless', 'viu', '!' );
########################################
$category = 4; # Comment controls
$rOpts_variable_maximum_line_length,
$rOpts_valign_code,
$rOpts_valign_side_comments,
+ $rOpts_valign_if_unless,
$rOpts_whitespace_cycle,
$rOpts_extended_line_up_parentheses,
$rOpts_tee_side_comments = $rOpts->{'tee-side-comments'};
$rOpts_valign_code = $rOpts->{'valign-code'};
$rOpts_valign_side_comments = $rOpts->{'valign-side-comments'};
+ $rOpts_valign_if_unless = $rOpts->{'valign-if-unless'};
$rOpts_variable_maximum_line_length =
$rOpts->{'variable-maximum-line-length'};
# /^(if|unless|and|or|eq|ne)$/
if ( $is_vertical_alignment_keyword{$token} ) {
$alignment_type = $token;
+
+ # Align postfix 'unless' and 'if' if requested (git #116)
+ # These are the only equivalent keywords. For equivalent
+ # token types see '%operator_map'.
+ if ( $token eq 'unless' && $rOpts_valign_if_unless ) {
+ $alignment_type = 'if';
+ }
}
}
# Note: %block_type_map is now global to enable the -gal=s option
- # map certain keywords to the same 'if' class to align
- # long if/elsif sequences. [elsif.pl]
+ # Map certain keywords to the same 'if' class to align
+ # long if/elsif sequences. [elsif.pl]. But note that this is
+ # only for purposes of making the patterns, not alignment tokens.
+ # The only possible equivalent alignment tokens are 'if' and 'unless',
+ # and this is handled earlier under control of $rOpts_valign_if_unless
+ # to avoid making this a global hash.
%keyword_map = (
'unless' => 'if',
'else' => 'if',
'undef' => 'Q',
);
- # map certain operators to the same class for pattern matching
+ # Map certain operators to the same class for alignment.
+ # Note that this map is for the alignment tokens, not the patterns.
+ # We could have placed 'unless' => 'if' here, but since that is
+ # under control of $rOpts_valign_if_unless, it is handled elsewhere.
%operator_map = (
'!~' => '=~',
'+=' => '+=',
# token types which prevent using leading word as a container name
@q = qw(
- x / : % . | ^ < = > || >= != *= => !~ == && |= .= -= =~ += <= %= ^= x= ~~ ** << /=
- &= // >> ~. &. |. ^.
+ x / : % . | ^ < = > || >= != *= => !~ == && |= .= -= =~ += <=
+ %= ^= x= ~~ ** << /= &= // >> ~. &. |. ^.
**= <<= >>= &&= ||= //= <=> !~~ &.= |.= ^.= <<~
);
push @q, ',';
--- /dev/null
+print "Tried to add: @ResolveRPM\n" if ( @ResolveRPM and !$Quiet );
+print "Would need: @DepList\n" if ( @DepList and !$Quiet );
+print "RPM Output:\n" unless $Quiet;
+print join( "\n", @RPMOutput ) . "\n" unless $Quiet;
--- /dev/null
+print "Tried to add: @ResolveRPM\n" if ( @ResolveRPM and !$Quiet );
+print "Would need: @DepList\n" if ( @DepList and !$Quiet );
+print "RPM Output:\n" unless $Quiet;
+print join( "\n", @RPMOutput ) . "\n" unless $Quiet;
--- /dev/null
+print "Tried to add: @ResolveRPM\n" if ( @ResolveRPM and !$Quiet );
+print "Would need: @DepList\n" if ( @DepList and !$Quiet );
+print "RPM Output:\n" unless $Quiet;
+print join( "\n", @RPMOutput ) . "\n" unless $Quiet;
../snippets9.t rt98902.def
../snippets9.t rt98902.rt98902
../snippets9.t rt99961.def
+../snippets28.t git116.def
+../snippets28.t git116.git116
#3 recombine6.def
#4 recombine7.def
#5 recombine8.def
+#6 git116.def
+#7 git116.git116
# To locate test #13 you can search for its name or the string '#13'
###########################################
$rparams = {
'def' => "",
+ 'git116' => "-viu",
'olbxl2' => <<'----------',
-olbxl='*'
----------
############################
$rsources = {
+ 'git116' => <<'----------',
+print "Tried to add: @ResolveRPM\n" if ( @ResolveRPM and !$Quiet );
+print "Would need: @DepList\n" if ( @DepList and !$Quiet );
+print "RPM Output:\n" unless $Quiet;
+print join( "\n", @RPMOutput ) . "\n" unless $Quiet;
+----------
+
'olbxl' => <<'----------',
eval {
require Ace };
);
#5...........
},
+
+ 'git116.def' => {
+ source => "git116",
+ params => "def",
+ expect => <<'#6...........',
+print "Tried to add: @ResolveRPM\n" if ( @ResolveRPM and !$Quiet );
+print "Would need: @DepList\n" if ( @DepList and !$Quiet );
+print "RPM Output:\n" unless $Quiet;
+print join( "\n", @RPMOutput ) . "\n" unless $Quiet;
+#6...........
+ },
+
+ 'git116.git116' => {
+ source => "git116",
+ params => "git116",
+ expect => <<'#7...........',
+print "Tried to add: @ResolveRPM\n" if ( @ResolveRPM and !$Quiet );
+print "Would need: @DepList\n" if ( @DepList and !$Quiet );
+print "RPM Output:\n" unless $Quiet;
+print join( "\n", @RPMOutput ) . "\n" unless $Quiet;
+#7...........
+ },
};
my $ntests = 0 + keys %{$rtests};