This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Extract a subroutine.
[perl5.git] / lib / perl5db.pl
index 070c92e..330f7a9 100644 (file)
@@ -5729,62 +5729,75 @@ sub _cmd_L_calc_wanted_flags {
     return (map { index($arg, $_) >= 0 ? 1 : 0 } qw(a b w));
 }
 
-sub cmd_L {
-    my $cmd = shift;
 
-    my ($action_wanted, $break_wanted, $watch_wanted) =
-        _cmd_L_calc_wanted_flags(shift);
+sub _cmd_L_handle_breakpoints {
+    my ($handle_db_line) = @_;
 
-    # Breaks and actions are found together, so we look in the same place
-    # for both.
-    if ( $break_wanted or $action_wanted ) {
+    BREAKPOINTS_SCAN:
+    # Look in all the files with breakpoints...
+    for my $file ( keys %had_breakpoints ) {
 
-        BREAKPOINTS_SCAN:
-        # Look in all the files with breakpoints...
-        for my $file ( keys %had_breakpoints ) {
+        # Temporary switch to this file.
+        local *dbline = $main::{ '_<' . $file };
 
-            # Temporary switch to this file.
-            local *dbline = $main::{ '_<' . $file };
+        # Set up to look through the whole file.
+        $max = $#dbline;
+        my $was;    # Flag: did we print something
+        # in this file?
 
-            # Set up to look through the whole file.
-            $max = $#dbline;
-            my $was;    # Flag: did we print something
-                        # in this file?
+        # For each line in the file ...
+        for my $i (1 .. $max) {
 
-            # For each line in the file ...
-            for my $i (1 .. $max) {
+            # We've got something on this line.
+            if ( defined $dbline{$i} ) {
 
-                # We've got something on this line.
-                if ( defined $dbline{$i} ) {
+                # Print the header if we haven't.
+                if (not $was++) {
+                    print {$OUT} "$file:\n";
+                }
 
-                    # Print the header if we haven't.
-                    if (not $was++) {
-                        print {$OUT} "$file:\n";
-                    }
+                # Print the line.
+                print {$OUT} " $i:\t", $dbline[$i];
 
-                    # Print the line.
-                    print {$OUT} " $i:\t", $dbline[$i];
+                $handle_db_line->($dbline{$i});
 
-                    # Pull out the condition and the action.
-                    my ( $stop, $action ) = split( /\0/, $dbline{$i} );
+                # Quit if the user hit interrupt.
+                if ($signal) {
+                    last BREAKPOINTS_SCAN;
+                }
+            } ## end if (defined $dbline{$i...
+        } ## end for my $i (1 .. $max)
+    } ## end for my $file (keys %had_breakpoints)
 
-                    # Print the break if there is one and it's wanted.
-                    if ($stop && $break_wanted) {
-                        print {$OUT} "   break if (", $stop, ")\n";
-                    }
+    return;
+}
 
-                    # Print the action if there is one and it's wanted.
-                    if ($action && $action_wanted) {
-                        print {$OUT} "   action:  ", $action, "\n";
-                    }
+sub cmd_L {
+    my $cmd = shift;
 
-                    # Quit if the user hit interrupt.
-                    if ($signal) {
-                        last BREAKPOINTS_SCAN;
-                    }
-                } ## end if (defined $dbline{$i...
-            } ## end for my $i (1 .. $max)
-        } ## end for my $file (keys %had_breakpoints)
+    my ($action_wanted, $break_wanted, $watch_wanted) =
+        _cmd_L_calc_wanted_flags(shift);
+
+    my $handle_db_line = sub {
+        my ($l) = @_;
+
+        my ( $stop, $action ) = split( /\0/, $l );
+
+        if ($stop and $break_wanted) {
+            print {$OUT} "    break if (", $stop, ")\n"
+        }
+
+        if ($action && $action_wanted) {
+            print {$OUT} "    action:  ", $action, "\n"
+        }
+
+        return;
+    };
+
+    # Breaks and actions are found together, so we look in the same place
+    # for both.
+    if ( $break_wanted or $action_wanted ) {
+        _cmd_L_handle_breakpoints($handle_db_line);
     } ## end if ($break_wanted or $action_wanted)
 
     # Look for breaks in not-yet-compiled subs:
@@ -5815,15 +5828,7 @@ sub cmd_L {
             for my $line ( sort { $a <=> $b } keys %$db ) {
                 print {$OUT} "  $line:\n";
 
-                my ( $stop, $action ) = split( /\0/, $$db{$line} );
-
-                if ($stop and $break_wanted) {
-                    print {$OUT} "    break if (", $stop, ")\n"
-                }
-
-                if ($action && $action_wanted) {
-                    print {$OUT} "    action:  ", $action, "\n"
-                }
+                $handle_db_line->($db->{$line});
 
                 if ($signal) {
                     last POSTPONED_SCANS;