bin/trepan.pl

filter: Statementstmt 91.2% 73 / 80 Branchbran 61.1% 11 / 18 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 85.9% 98 / 114 CC 1 SCAR 0.0
CC
1
Cov
85%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« example/signal.pl ↑ Summary lib/Devel/Trepan/CmdProcessor/Command/TBreak.pm »
1 #!/usr/bin/env perl
2 # Copyright (C) 2012, 2014 Rocky Bernstein <rocky@cpan.org>
3 # Standalone routine to invoke a Perl program under the debugger.
4  
5 # The usual boilerplate...
6 39 ▶use strict; use warnings; use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 39 ▶use File::Basename; use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
9 39 ▶use File::Temp qw(tempfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 39 my $dirname = dirname(__FILE__);
12 39 my $file = File::Spec->rel2abs(__FILE__);
13 39 my $TREPAN_DIR = File::Spec->catfile(dirname($file), '..', 'lib');
14  
15 39 ▶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
16 use Data::Dumper;
17 my @OLD_INC = @INC;
18 use lib $TREPAN_DIR;
19 use Devel::Trepan::Options;
20 use Devel::Trepan::Client;
21 use Devel::Trepan::Util;
22 @INC = @OLD_INC;
23 EOE
24 39 ▶die $EVAL_ERROR if $EVAL_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if $main::EVAL_ERROR 0 39 39
25  
26 39 my $opts = Devel::Trepan::Options::process_options(\@ARGV);
27  
28 39 ▶if ($opts->{client}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"client"}) 0 39 39
29 0 Devel::Trepan::Client::start_client($opts);
30 0 exit;
31 }
32  
33 39 my @exec_strs = @{$opts->{exec_strs}};
34 39 my @exec_strs_with_e = map {('-e', qq{'$_'})} @exec_strs;
35 39 my $cmd;
36 39 ▶if (scalar @exec_strs) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @exec_strs) { } 1 38 39
37 1 $cmd = join(' ', @exec_strs_with_e) . join(' ', @ARGV);
38 } else {
39 38 ▶ die "You need a Perl program to run or pass an string to eval"
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 38 38
40 unless @ARGV;
41  
42 # Resolve program name if it is not readable
43 38 ▶ $ARGV[0] = whence_file($ARGV[0]) unless -r $ARGV[0];
Branch: 1 branch
BranchTrueFalseTotal
unless -r $ARGV[0] 0 38 38
44 38 $cmd = join(' ', @ARGV);
45 }
46  
47 # Check that the debugged Perl program is syntactically valid.
48 39 my $syntax_errmsg = Devel::Trepan::Util::invalid_perl_syntax($cmd, 1);
49 39 ▶if ($syntax_errmsg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($syntax_errmsg) 0 39 39
50 0 print STDERR "$syntax_errmsg\n";
51 0 exit -1;
52 }
53  
54 39 $opts->{dollar_0} = $ARGV[0];
55 39 unshift @{$opts->{includes}}, $TREPAN_DIR;
56 39 $ENV{'TREPANPL_OPTS'} = Data::Dumper::Dumper($opts);
57  
58 # And just when you thought we'd never get around to actually
59 # doing something...
60 39 my $i=0;
61 39 foreach my $arg (@exec_strs_with_e) {
62 2 ▶ if ('-e' eq $arg && scalar(@exec_strs_with_e) > $i) {
Branch: 1 branch
BranchTrueFalseTotal
if ("-e" eq $arg and scalar @exec_strs_with_e > $i) 1 1 2
Condition66%2/3
"-e" eq $arg and scalar @exec_strs_with_e > $i
!ll&&!rl&&r
101
MC/DC50%1/2
"-e" eq $arg and scalar @exec_strs_with_e > $i
"-e" eq $arg scalar @exec_strs_with_e > $i
Truth table66%2/3
A and B
A= "-e" eq $argB= scalar @exec_strs_with_e > $i
ABresult
0X0
100
111
63 1 $exec_strs_with_e[$i+1] =~ s/^(["'])(.+)\1$/$2/ ;
64 1 $i++;
65 }
66 }
67  
68 39 my @INCLUDES = ();
69 39 foreach my $inc (@{$opts->{includes}}) {
70 39 push @INCLUDES, ('-I', $inc);
71 };
72  
73 39 my @MODULES = ();
74  
75 39 foreach my $mod (@{$opts->{modules}}) {
76 0 push @MODULES, '-M' . $mod;
77 }
78  
79 39 my @ARGS = ($EXECUTABLE_NAME, @INCLUDES, '-d:Trepan', @MODULES,
80 @exec_strs_with_e, @ARGV);
81  
82 print Data::Dumper->Dump([$opts, \@ARGS],
83 [qw($ENV{TREPANPL_OPTS} ARGS)])
84 39 ▶ if $opts->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"verbose"} 0 39 39
85  
86 39 ▶if ($OSNAME eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::OSNAME eq 'MSWin32') { } 0 39 39
87 # I don't understand why but Strawberry Perl has trouble with exec.
88 0 system @ARGS;
89 0 exit $?;
90 } else {
91 39 exec { $ARGS[0]} @ARGS;
92 }
« example/signal.pl ↑ Summary lib/Devel/Trepan/CmdProcessor/Command/TBreak.pm »