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

filter: Statementstmt 65.8% 102 / 155 Branchbran 25.0% 4 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 72.5% 29 / 40 Podpod 0.0% 0 / 7 totaltotal 59.2% 135 / 228 CC 13 SCAR 18.2
CC
13
Cov
60%
run
18.9
run
18.9
run
18.9
CRAP 6.1
« blib/lib/Devel/Trepan/Interface/Script.pm ↑ Summary blib/lib/Devel/Trepan/IO/TCPServer.pm »
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2012, 2014 Rocky Bernstein <rocky@cpan.org>
3 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
4  
5 12 ▶use rlib '../../../..';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # Our local modules
8 ## use Devel::Trepan::Options; or is it default
9 12 ▶use Devel::Trepan::Interface::Script;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use Devel::Trepan::IO::NullOutput;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # Must be outside of package!
13 12 ▶use if !@ISA, Devel::Trepan::Complete ;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 package Devel::Trepan::CmdProcessor::Command::Source;
16 12 ▶use Cwd 'abs_path';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
17 12 ▶use Getopt::Long qw(GetOptionsFromArray);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
18 12 ▶use if !@ISA, Devel::Trepan::CmdProcessor::Command ;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶unless (@ISA) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@ISA) 0 1 1
21 0 ▶ 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
Subroutine BEGIN: called CC=1 SCAR=0.0
22 use constant CATEGORY => 'support';
23 use constant SHORT_HELP => 'Run debugger commands from a file';
24 use constant MIN_ARGS => 1; # Need at least this many
25 use constant MAX_ARGS => undef; # Need at most this many - undef -> unlimited.
26 use constant NEED_STACK => 0;
27 EOE
28 }
29  
30 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 12 ▶use vars qw(@ISA); @ISA = qw(Devel::Trepan::CmdProcessor::Command);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
33 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
34  
35 1 our $NAME = set_name();
36 =pod
37  
38 =head2 Synopsis:
39  
40 =cut
41 1 our $HELP = <<'HELP';
42 =pod
43  
44 B<source> [I<options>] I<file>
45  
46 options:
47  
48 -q | --quiet | --no-quiet
49 -c | --continue | --no-continue
50 -Y | --yes | -N | --no
51 -v | --verbose | --no-verbose
52  
53 Read debugger commands from a file named I<file>. Optional C<-v> switch
54 causes each command in FILE to be echoed as it is executed. Option C<-Y>
55 sets the default value in any confirmation command to be 'yes' and C<-N>
56 sets the default value to 'no'.
57  
58 Option C<-q> will turn off any debugger output that normally occurs in
59 the running of the program.
60  
61 An error in any command terminates execution of the command file
62 unless option C<-c> or C<--continue> is given.
63 =cut
64 HELP
65  
66 # FIXME: put back in help.
67 # Note that the command startup file ${Devel::Trepan::CMD_INITFILE_BASE} is read automatically
68 # via a ${NAME} command the debugger is started.
69  
70 1 my $DEFAULT_OPTIONS = {
71 abort_on_error => 0,
72 confirm_val => 0,
73 quiet => 0,
74 verbose => 0
75 };
76  
77 0 ▶sub complete($$) {
Subroutine complete: not called CC=1 SCAR=6.9
Subroutine complete: not called CC=1 SCAR=6.9
Pod undocumented
Pod undocumented
78 0 ▶ my ($self, $prefix) = @_;
Subroutine complete: not called CC=1 SCAR=6.9
Pod undocumented
79 0 my @files = $self->{proc}{interfaces}[-1]->rl_filename_list($prefix);
80 0 my @opts = (qw(-c --continue -n --no -y --yes
81 -v --verbose --no-verbose), @files);
82 0 Devel::Trepan::Complete::complete_token(\@opts, $prefix) ;
83 }
84  
85 sub parse_options($$)
86 0 ▶{
Subroutine parse_options: not called CC=1 SCAR=6.9
Subroutine parse_options: not called CC=1 SCAR=6.9
Pod undocumented
Pod undocumented
87 0 my ($self, $args) = @_;
88 0 my $seen_yes_no = 0;
89 0 my %opts = %$DEFAULT_OPTIONS;
90 my $result = &GetOptionsFromArray($args,
91 '--continue' => \$opts{cont},
92 '--v' => \$opts{verbose},
93 '--verbose' => \$opts{verbose},
94 '-n' => \$opts{no},
95 '--no' => \$opts{no},
96 0 ▶ '-y' => sub { $opts{no} = 0; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
97 0 ▶ '--yes' => sub { $opts{no} = 0; }
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
98 0 );
99 0 \%opts;
100 }
101  
102 sub run($$)
103 0 ▶{
Subroutine run: not called CC=5 SCAR=29.4
Subroutine run: not called CC=5 SCAR=29.4
Pod undocumented
Pod undocumented
104 0 my ($self, $args) = @_;
105 0 my @args = @$args;
106 0 @args = splice @args, 1, scalar(@args) - 2;
107 0 my $options = parse_options($self, \@args);
108 0 my $intf = $self->{proc}{interfaces};
109 my $output = $options->{quiet} ? Devel::Trepan::IO::OutputNull->new :
110 0 ▶ $intf->[-1]{output};
Branch: 2 branches
BranchTrueFalseTotal
$options->{'quiet'} ? : 0 0 0
$options->{'quiet'} ? : 11 0 11
111  
112 0 my $filename = $args->[-1];
113  
114 0 my $expanded_filename = abs_path(glob($filename));
115 0 ▶ unless (defined $expanded_filename && -f $expanded_filename) {
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $expanded_filename and -f $expanded_filename) 0 0 0
unless (defined $expanded_filename and -f $expanded_filename) 0 11 11
Condition0%0/6
defined $expanded_filename and -f $expanded_filename
!ll&&!rl&&r
000
defined $expanded_filename and -f $expanded_filename
!ll&&!rl&&r
000
MC/DC0%0/2
defined $expanded_filename and -f $expanded_filename
defined $expanded_filename -f $expanded_filename
MC/DC0%0/2
defined $expanded_filename and -f $expanded_filename
defined $expanded_filename -f $expanded_filename
Truth table0%0/3
A and B
A= defined $expanded_filenameB= -f $expanded_filename
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $expanded_filenameB= -f $expanded_filename
ABresult
0X0
100
111
116 0 my $mess = sprintf("Debugger command file '%s' is not found", $filename);
117 0 $self->errmsg($mess);
118 0 return 0;
119 }
120 0 ▶ unless(-r $expanded_filename) {
Branch: 2 branches
BranchTrueFalseTotal
unless (-r $expanded_filename) 0 0 0
unless (-r $expanded_filename) 0 0 0
121 0 my $mess = sprintf("Debugger command file '%s' (%s) is not a readable file", $filename, $expanded_filename);
122 0 $self->errmsg($mess);
123 0 return 0;
124 }
125  
126 # Push a new debugger interface.
127 0 my $script_intf = Devel::Trepan::Interface::Script->new($expanded_filename,
128 $output, $options);
129 0 push @{$intf}, $script_intf;
130 }
131  
132  
133 # Demo it
134 1 ▶unless (caller) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller) 0 1 1
135 # require_relative '../mock'
136 # dbgr, cmd = MockDebugger::setup
137 # %w(--quiet -q --no-quiet --continue --no-continue -c -v --verbose
138 # --no-verbose).each do |opt|
139 # puts "parsing ${opt}"
140 # options =
141 # cmd.parse_options(Trepan::Command::SourceCommand::DEFAULT_OPTIONS.dup,
142 # opt)
143 # p options
144 # }
145  
146 # if ARGV.size >= 1
147 # puts "running... ${cmd.name} ${ARGV}"
148 # cmd.run([cmd.name, *ARGV])
149 # }
150 }
151  
152 1 1;
« blib/lib/Devel/Trepan/Interface/Script.pm ↑ Summary blib/lib/Devel/Trepan/IO/TCPServer.pm »