}
# ATTRS: check for a ':' which introduces an attribute list
- # (this might eventually get its own token type)
- elsif ( $statement_type =~ /^sub\b/ ) {
+ # either after a 'sub' keyword or within a paren list
+ elsif ($statement_type =~ /^sub\b/ ) {
$type = 'A';
$in_attribute_list = 1;
}
$type = 'J';
}
+ # Withing a signature. For example,
+ # from 't/filter_example.t':
+ # method foo4 ( $class: $bar ) { $class->bar($bar) }
+ elsif ( !is_balanced_closing_container(QUESTION_COLON)
+ && $paren_type[$paren_depth] =~ /^sub\b/ )
+ {
+ $type = 'A';
+ $in_attribute_list = 1;
+ }
+
# otherwise, it should be part of a ?/: operator
else {
( $type_sequence, $indent_flag ) =
# particular, we stop if we see any nested parens, braces, or commas.
# Also note, a valid prototype cannot contain any alphabetic character
# -- see https://perldoc.perl.org/perlsub
- # But it appears that an underscore may be valid now, so this is
- # using [A-Za-z] instead of \w
+ # old PROTO:
+ # $input_line =~ m/\G(\s*\([^\)\(\}\{\,#]*\))? # PROTO
my $saw_opening_paren = $input_line =~ /\G\s*\(/;
if (
$input_line =~ m/\G(\s*\([^\)\(\}\{\,#A-Za-z]*\))? # PROTO
=item b<sub signatures no longer parsed with prototypes>
-Simple signatures were being parsed with the code for prototypes, which
-prevented them from being formatted with the usual formatting rules. All
-signatures are now formatted separately from prototypes with the normal
-formatting rules. For example:
+Simple signatures (those without commas) were being parsed with code originally
+written for prototypes. This prevented them from being formatted with the
+usual formatting rules. This was changed so that all signatures are now
+formatted with the normal formatting rules. For example:
- # Old, intput and after formatting:
+ # Old, input and after formatting:
sub t123 ($list=wantarray) { $list ? "list" : "scalar" }
# New, after formatting
sub t123 ( $list = wantarray ) { $list ? "list" : "scalar" }
Notice that some spaces have been introduced within the signature. Previously
-the contents of the parens was left unchanged.
+the contents of the parens not changed unless the parens contained a list.
+
+This change introduced a problem parsing extended syntax within
+signatures which has been fixed. In the following snippet, the ':' caused
+a parsing error which was fixed.
+
+ # perltidy -sal='method'
+ method foo4 ( $class : $bar, $bubba ) { $class->bar($bar) }
+
+The ':' here is given a type of 'A'. This may be used to change
+the spacing around it. For example:
+
+ # perltidy -sal='method' -nwls='A'
+ method foo4 ( $class: $bar, $bubba ) { $class->bar($bar) }
+
=item b<fix parsing problem with $#>
# change invocant name
method
-foo4 ($class: $bar) { $class->bar($bar) }
+foo4 ( $class : $bar ) { $class->bar($bar) }
ENDS
my $expect = <<'ENDE';
}
# change invocant name
-method foo4 ($class: $bar) { $class->bar($bar) }
+method foo4 ( $class : $bar ) { $class->bar($bar) }
ENDE
my $output;
-sub classify_digit($digit)
+sub classify_digit ($digit)
{ switch($digit)
{ case 0 { return 'zero' } case [ 2, 4, 6, 8 ]{ return 'even' }
case [ 1, 3, 4, 7, 9 ]{ return 'odd' } case /[A-F]/i { return 'hex' } }
----------
'switch1' => <<'----------',
-sub classify_digit($digit)
+sub classify_digit ($digit)
{ switch($digit)
{ case 0 { return 'zero' } case [ 2, 4, 6, 8 ]{ return 'even' }
case [ 1, 3, 4, 7, 9 ]{ return 'odd' } case /[A-F]/i { return 'hex' } }