lib/Devel/Trepan/CmdProcessor/Command/Macro.pm

filter: Statementstmt 72.8% 83 / 114 Branchbran 56.2% 9 / 16 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 95.4% 21 / 22 Podpod 0.0% 0 / 2 totaltotal 69.5% 114 / 164 CC 10 SCAR 12.2
CC
10
Cov
68%
run
7.4
run
7.4
run
7.4
CRAP 3.4
« lib/Devel/Trepan/IO.pm ↑ Summary lib/Devel/Trepan/CmdProcessor/Parse/BPLocation.pm »
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2014 Rocky Bernstein <rocky@cpan.org>
3  
4 12 ▶use warnings; no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use rlib '../../../..';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 package Devel::Trepan::CmdProcessor::Command::Macro;
8 12 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use if !@ISA, Devel::Trepan::CmdProcessor::Command ;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶unless (@ISA) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@ISA) 1 1 2
11 12 ▶ eval <<'EOE';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
12 use constant CATEGORY => 'support';
13 use constant SHORT_HELP => 'Define a macro';
14 use constant MIN_ARGS => 3; # Need at least this many
15 use constant MAX_ARGS => undef; # Need at most this many - undef -> unlimited.
16 EOE
17 }
18  
19 12 ▶use strict; use vars qw(@ISA); @ISA = @CMD_ISA;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
20 12 ▶use vars @CMD_VARS; # Value inherited from parent
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 2 our $NAME = set_name();
23 =pod
24  
25 =head2 Synopsis:
26  
27 =cut
28 2 our $HELP = <<'HELP';
29 =pod
30  
31 macro I<macro-name> sub { ... }
32  
33 Define I<macro-name> as a debugger macro. Debugger macros get a list of
34 arguments which you supply without parenthesis or commas. See below
35 for an example.
36  
37 The macro (really a Perl anonymous subroutine) should return either a
38 string or an list reference to a list of strings. Each string is a
39 debugger command.
40  
41 If a single string is returned, that gets tokenized by a simple C<split(/ /,
42 $string)>. Note that macro processing is done right after splitting
43 on C<;;> so if the macro returns a string containing C<;;> this will
44 not be handled on the string returned.
45  
46 If a reference to a list of strings is returned instead, then the
47 first string is shifted from the array and executed. The remaining
48 strings are pushed onto the command queue. In contrast to the first
49 string, subsequent strings can contain other macros. Any C<;;> in those
50 strings will be split into separate commands.
51  
52 =head2 Examples:
53  
54 The below creates a macro called I<fin+> which issues two commands
55 C<finish> followed by C<step>:
56  
57 macro fin+ sub{ ['finish', 'step']}
58  
59 If you wanted to parameterize the argument of the C<finish> command
60 you could do it this way:
61  
62 macro fin+ sub{ \
63 ['finish', 'step ' . (shift)] \
64 }
65  
66 Invoking with:
67  
68 fin+ 3
69  
70 would expand to C<["finish", "step 3"]>
71  
72 If you were to add another parameter, note that the invocation is like
73 you use for other debugger commands, no commas or parenthesis. That is:
74  
75 fin+ 3 2
76  
77 rather than C<fin+(3,2)> or C<fin+ 3, 2>.
78  
79 =head2 See also:
80  
81 L<C<alias>|Devel::Trepan::CmdProcessor::Command::Alias>, and
82 L<C<info macro>|Devel::Trepan::CmdProcessor::Command::Info::Macro>.
83  
84 =cut
85 HELP
86  
87 # This method runs the command
88 0 ▶sub run($$) {
Subroutine run: not called CC=4 SCAR=20.0
Subroutine run: called CC=4 SCAR=20.0
Pod undocumented
Pod undocumented
89 0 my ($self, $args) = @_;
90 0 my $cmd_name = $args->[1];
91 0 my $proc = $self->{proc};
92 0 my $cmd_argstr = $proc->{cmd_argstr};
93 0 $cmd_argstr =~ s/^\s+//;
94 0 $cmd_argstr = substr($cmd_argstr, length($cmd_name));
95 0 $cmd_argstr =~ s/^\s+//;
96 0 my $fn = eval($cmd_argstr);
97 0 ▶ if ($EVAL_ERROR) {
Branch: 6 branches
BranchTrueFalseTotal
if ($Devel::Trepan::CmdProcessor::Command::Macro::EVAL_ERROR) { } 0 0 0
elsif ($fn and ref $fn eq 'CODE') { } 0 0 0
if ($Devel::Trepan::CmdProcessor::Command::Macro::EVAL_ERROR) { } 10 1 11
elsif ($fn and ref $fn eq 'CODE') { } 1 10 11
if ($Devel::Trepan::CmdProcessor::Command::Macro::EVAL_ERROR) { } 0 1 1
elsif ($fn and ref $fn eq 'CODE') { } 0 1 1
98 0 $proc->errmsg($EVAL_ERROR)
99 ▶ } elsif ($fn && ref($fn) eq 'CODE') {
Condition16%1/6
$fn and ref $fn eq "CODE"
!ll&&!rl&&r
000
$fn and ref $fn eq "CODE"
!ll&&!rl&&r
001
MC/DC0%0/2
$fn and ref $fn eq "CODE"
$fn ref $fn eq "CODE"
MC/DC0%0/2
$fn and ref $fn eq "CODE"
$fn ref $fn eq "CODE"
Truth table0%0/3
A and B
A= $fnB= ref $fn eq "CODE"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= $fnB= ref $fn eq "CODE"
ABresult
0X0
100
111
100 0 $proc->{macros}{$cmd_name} = [$fn, $cmd_argstr];
101 0 $proc->msg("Macro \"${cmd_name}\" defined.");
102 } else {
103 0 $proc->errmsg("Expecting an anonymous subroutine");
104 }
105 }
106  
107 2 ▶unless (caller) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller) 0 2 2
108 0 require Devel::Trepan::CmdProcessor;
109 0 my $proc = Devel::Trepan::CmdProcessor->new(undef, 'bogus');
110 0 my $cmd = __PACKAGE__->new($proc);
111 0 $proc->{cmd_argstr} = "fin+ sub{ ['finish', 'step']}";
112 0 my @args = ($NAME, split(/\s+/, $proc->{cmd_argstr}));
113 0 $cmd->run(\@args);
114 0 print join(' ', @{$proc->{macros}{'fin+'}}), "\n";
115 }
116  
117 2 1;
« lib/Devel/Trepan/IO.pm ↑ Summary lib/Devel/Trepan/CmdProcessor/Parse/BPLocation.pm »