]> git.donarmstrong.com Git - perltidy.git/commitdiff
add sub do_colon_breaks
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 11 Jul 2022 01:11:23 +0000 (18:11 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 11 Jul 2022 01:11:23 +0000 (18:11 -0700)
lib/Perl/Tidy/Formatter.pm

index 2c9e27c4286a6ca814dccb6cd7aa49945e029eb2..63bf45a8cecaac7bcd9b9b8a92b7402498ad6798 100644 (file)
@@ -777,7 +777,7 @@ sub new {
     my $self = [];
 
     # Basic data structures...
-    $self->[_rlines_]     = [];    # = ref to array of lines of the file
+    $self->[_rlines_] = [];    # = ref to array of lines of the file
 
     # 'rLL' = reference to the continuous liner array of all tokens in a file.
     # 'LL' stands for 'Linked List'. Using a linked list was a disaster, but
@@ -18536,33 +18536,39 @@ sub break_long_lines {
     # corresponding '?' unless this is a chain of ?: expressions
     #-------------------------------------------------------
     if (@i_colon_breaks) {
-
-        # using a simple method for deciding if we are in a ?/: chain --
-        # this is a chain if it has multiple ?/: pairs all in order;
-        # otherwise not.
-        # Note that if line starts in a ':' we count that above as a break
         my $is_chain = ( $colons_in_order && @i_colon_breaks > 1 );
+        if ( !$is_chain ) {
+            $self->do_colon_breaks( \@i_colon_breaks, \@i_first, \@i_last );
+        }
+    }
 
-        unless ($is_chain) {
-            my @insert_list = ();
-            foreach (@i_colon_breaks) {
-                my $i_question = $mate_index_to_go[$_];
-                if ( $i_question >= 0 ) {
-                    if ( $want_break_before{'?'} ) {
-                        $i_question = $iprev_to_go[$i_question];
-                    }
+    return ( \@i_first, \@i_last, $rbond_strength_to_go );
+} ## end sub break_long_lines
 
-                    if ( $i_question >= 0 ) {
-                        push @insert_list, $i_question;
-                    }
-                }
-                $self->insert_additional_breaks( \@insert_list, \@i_first,
-                    \@i_last );
+sub do_colon_breaks {
+    my ( $self, $ri_colon_breaks, $ri_first, $ri_last ) = @_;
+
+    # using a simple method for deciding if we are in a ?/: chain --
+    # this is a chain if it has multiple ?/: pairs all in order;
+    # otherwise not.
+    # Note that if line starts in a ':' we count that above as a break
+
+    my @insert_list = ();
+    foreach ( @{$ri_colon_breaks} ) {
+        my $i_question = $mate_index_to_go[$_];
+        if ( $i_question >= 0 ) {
+            if ( $want_break_before{'?'} ) {
+                $i_question = $iprev_to_go[$i_question];
+            }
+
+            if ( $i_question >= 0 ) {
+                push @insert_list, $i_question;
             }
         }
+        $self->insert_additional_breaks( \@insert_list, $ri_first, $ri_last );
     }
-    return ( \@i_first, \@i_last, $rbond_strength_to_go );
-} ## end sub break_long_lines
+    return;
+}
 
 ###########################################
 # CODE SECTION 11: Code to break long lists