This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Refactor some more command-handlers.
[perl5.git] / lib / perl5db.pl
index fe62ffe..410dbf5 100644 (file)
@@ -1839,9 +1839,10 @@ sub _DB__trim_command_and_return_first_component {
     $cmd =~ s/\A\s+//s;    # trim annoying leading whitespace
     $cmd =~ s/\s+\z//s;    # trim annoying trailing whitespace
 
-    $cmd =~ m{\A(\S*)};
+    my ($verb, $args) = $cmd =~ m{\A(\S*)\s*(.*)}s;
 
-    $obj->cmd_verb($1);
+    $obj->cmd_verb($verb);
+    $obj->cmd_args($args);
 
     return;
 }
@@ -1968,16 +1969,16 @@ sub _DB__handle_y_command {
 sub _DB__handle_c_command {
     my ($obj) = @_;
 
-    if (my ($new_verb) = $cmd =~ m#\Ac\b\s*([\w:]*)\s*\z#) {
+    my $i = $obj->cmd_args;
 
-        $obj->cmd_verb($new_verb);
+    if ($i =~ m#\A[\w:]*\z#) {
 
         # Hey, show's over. The debugged program finished
         # executing already.
         next CMD if _DB__is_finished();
 
         # Capture the place to put a one-time break.
-        $subname = $obj->cmd_verb;
+        $subname = $i;
 
         #  Probably not needed, since we finish an interactive
         #  sub-session anyway...
@@ -2000,13 +2001,13 @@ sub _DB__handle_c_command {
             # to where the subroutine is defined; we call find_sub,
             # break up the return value, and assign it in one
             # operation.
-            ( $file, $new_verb ) = ( find_sub($subname) =~ /^(.*):(.*)$/ );
+            ( $file, $i ) = ( find_sub($subname) =~ /^(.*):(.*)$/ );
 
             # Force the line number to be numeric.
-            $obj->cmd_verb($new_verb + 0);
+            $i = $i + 0;
 
             # If we got a line number, we found the sub.
-            if ($obj->cmd_verb) {
+            if ($i) {
 
                 # Switch all the debugger's internals around so
                 # we're actually working with that file.
@@ -2019,12 +2020,12 @@ sub _DB__handle_c_command {
                 # Scan forward to the first executable line
                 # after the 'sub whatever' line.
                 $max = $#dbline;
-                my $_line_num = $obj->cmd_verb;
+                my $_line_num = $i;
                 while ($dbline[$_line_num] == 0 && $_line_num< $max)
                 {
                     $_line_num++;
                 }
-                $obj->cmd_verb($_line_num);
+                $i = $_line_num;
             } ## end if ($i)
 
             # We didn't find a sub by that name.
@@ -2055,22 +2056,22 @@ sub _DB__handle_c_command {
         # On the gripping hand, we can't do anything unless the
         # current value of $i points to a valid breakable line.
         # Check that.
-        if ($obj->cmd_verb) {
+        if ($i) {
 
             # Breakable?
-            if ( $dbline[$obj->cmd_verb] == 0 ) {
-                print $OUT "Line " . $obj->cmd_verb . " not breakable.\n";
+            if ( $dbline[$i] == 0 ) {
+                print $OUT "Line $i not breakable.\n";
                 next CMD;
             }
 
             # Yes. Set up the one-time-break sigil.
-            $dbline{$obj->cmd_verb} =~ s/($|\0)/;9$1/;  # add one-time-only b.p.
-            _enable_breakpoint_temp_enabled_status($filename, $obj->cmd_verb);
+            $dbline{$i} =~ s/($|\0)/;9$1/;  # add one-time-only b.p.
+            _enable_breakpoint_temp_enabled_status($filename, $i);
         } ## end if ($i)
 
         # Turn off stack tracing from here up.
-        for my $i (0 .. $stack_depth) {
-            $stack[ $i ] &= ~1;
+        for my $j (0 .. $stack_depth) {
+            $stack[ $j ] &= ~1;
         }
         last CMD;
     }
@@ -2480,6 +2481,7 @@ sub DB {
     }
 
     my $cmd_verb;
+    my $cmd_args;
 
     my $obj = DB::Obj->new(
         {
@@ -2488,6 +2490,7 @@ sub DB {
             after => \$after,
             explicit_stop => \$explicit_stop,
             infix => \$infix,
+            cmd_args => \$cmd_args,
             cmd_verb => \$cmd_verb,
             pat => \$pat,
             piped => \$piped,
@@ -3116,6 +3119,7 @@ sub _init {
     no strict 'refs';
     foreach my $slot_name (qw(
         after explicit_stop infix pat piped position prefix selected cmd_verb
+        cmd_args
         )) {
         my $slot = $slot_name;
         *{$slot} = sub {
@@ -3349,8 +3353,10 @@ sub _handle_t_command {
 
 
 sub _handle_S_command {
+    my $self = shift;
+
     if (my ($print_all_subs, $should_reverse, $Spatt)
-        = $DB::cmd =~ /\AS(\s+(!)?(.+))?\z/) {
+        = $self->cmd_args =~ /\A((!)?(.+))?\z/) {
         # $Spatt is the pattern (if any) to use.
         # Reverse scan?
         my $Srev     = defined $should_reverse;
@@ -3532,7 +3538,9 @@ sub _handle_w_command {
 }
 
 sub _handle_W_command {
-    if (my ($arg) = $DB::cmd =~ /\AW\b\s*(.*)/s) {
+    my $self = shift;
+
+    if (my $arg = $self->cmd_args) {
         DB::cmd_W( 'W', $arg );
         next CMD;
     }
@@ -3611,14 +3619,13 @@ sub _handle_rc_search_history_command {
 sub _handle_H_command {
     my $self = shift;
 
-    if ($DB::cmd =~ /\AH\b\s*\*/) {
+    if ($self->cmd_args =~ m#\A\*#) {
         @hist = @truehist = ();
         print $OUT "History cleansed\n";
         next CMD;
     }
 
-    if (my ($num)
-        = $DB::cmd =~ /\AH\b\s*(?:-(\d+))?/) {
+    if (my ($num) = $self->cmd_args =~ /\A(?:-(\d+))?/) {
 
         # Anything other than negative numbers is ignored by
         # the (incorrect) pattern, so this test does nothing.