line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (C) 2011-2012, 2015 Rocky Bernstein <rocky@cpan.org> |
2
|
|
|
|
|
|
|
# I/O related command processor methods |
3
|
|
|
|
|
|
|
|
4
|
12
|
|
|
12
|
|
76
|
use warnings; |
|
12
|
|
|
|
|
34
|
|
|
12
|
|
|
|
|
496
|
|
5
|
12
|
|
|
12
|
|
65
|
no warnings 'redefine'; |
|
12
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
516
|
|
6
|
12
|
|
|
12
|
|
73
|
use strict; |
|
12
|
|
|
|
|
29
|
|
|
12
|
|
|
|
|
292
|
|
7
|
12
|
|
|
12
|
|
112
|
use Exporter; |
|
12
|
|
|
|
|
33
|
|
|
12
|
|
|
|
|
463
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
12
|
|
|
12
|
|
79
|
use rlib '../../..'; |
|
12
|
|
|
|
|
36
|
|
|
12
|
|
|
|
|
137
|
|
11
|
|
|
|
|
|
|
require Devel::Trepan::Util; |
12
|
|
|
|
|
|
|
require Devel::Trepan::CmdProcessor; |
13
|
|
|
|
|
|
|
package Devel::Trepan::CmdProcessor; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Because we use Exporter we want to silence: |
16
|
|
|
|
|
|
|
# Use of inherited AUTOLOAD for non-method ... is deprecated |
17
|
|
|
|
|
|
|
sub AUTOLOAD |
18
|
|
|
|
|
|
|
{ |
19
|
0
|
|
|
0
|
|
|
my $name = our $AUTOLOAD; |
20
|
0
|
|
|
|
|
|
$name =~ s/.*:://; # lose package name |
21
|
0
|
|
|
|
|
|
my $target = "DynaLoader::$name"; |
22
|
0
|
|
|
|
|
|
goto &$target; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
12
|
|
|
12
|
|
5543
|
use vars qw(@EXPORT @ISA $HAVE_TERM_ANSIColor); |
|
12
|
|
|
|
|
30
|
|
|
12
|
|
|
|
|
9958
|
|
27
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
28
|
|
|
|
|
|
|
|
29
|
12
|
|
|
12
|
|
83
|
$HAVE_TERM_ANSIColor = eval "use Term::ANSIColor; 1"; |
|
12
|
|
|
|
|
38
|
|
|
12
|
|
|
|
|
563
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# attr_accessor :ruby_highlighter |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub confirm($$$) |
34
|
|
|
|
|
|
|
{ |
35
|
0
|
|
|
0
|
0
|
0
|
my ($self, $msg, $default) = @_; |
36
|
0
|
|
|
|
|
0
|
my $intf = $self->{interfaces}[-1]; |
37
|
|
|
|
|
|
|
my $confirmed = $self->{settings}{confirm} ? |
38
|
0
|
0
|
|
|
|
0
|
$intf->confirm($msg, $default) : 1; |
39
|
0
|
0
|
|
|
|
0
|
$intf->remove_history unless $confirmed; |
40
|
0
|
|
|
|
|
0
|
$confirmed; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub errmsg($$;$) { |
44
|
2
|
|
|
2
|
0
|
5
|
my($self, $message, $opts) = @_; |
45
|
2
|
|
50
|
|
|
12
|
$opts ||={}; |
46
|
2
|
50
|
|
|
|
6
|
if (ref($message) eq 'ARRAY') { |
47
|
0
|
|
|
|
|
0
|
foreach my $mess (@$message) { |
48
|
0
|
|
|
|
|
0
|
$self->errmsg($mess, $opts) |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
0
|
return; |
51
|
|
|
|
|
|
|
} else { |
52
|
2
|
50
|
|
|
|
10
|
$message = $self->safe_rep($message) unless $self->{opts}{unlimited}; |
53
|
|
|
|
|
|
|
} |
54
|
2
|
50
|
33
|
|
|
12
|
if ($self->{settings}{highlight} && $HAVE_TERM_ANSIColor) { |
55
|
2
|
|
|
|
|
7
|
$message = color('underscore') . $message . color('reset'); |
56
|
|
|
|
|
|
|
} |
57
|
2
|
|
|
|
|
85
|
$self->{interfaces}[-1]->errmsg($message); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub msg($$;$) { |
61
|
3
|
|
|
3
|
0
|
6
|
my($self, $message, $opts) = @_; |
62
|
3
|
50
|
|
|
|
12
|
$message = $self->safe_rep($message) unless $opts->{unlimited}; |
63
|
|
|
|
|
|
|
# $message = $self->perl_format($message) if $opts->{code}; |
64
|
|
|
|
|
|
|
$self->{interfaces}[-1]->msg($message) if |
65
|
3
|
50
|
|
|
|
16
|
defined $self->{interfaces}[-1]; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub msg_need_running($$;$) { |
70
|
0
|
|
|
0
|
0
|
0
|
my($self, $prefix, $opts) = @_; |
71
|
0
|
|
|
|
|
0
|
$self->errmsg("$prefix not available when terminated"); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub msg_nocr($$;$) { |
75
|
0
|
|
|
0
|
0
|
0
|
my($self, $message, $opts) = @_; |
76
|
0
|
0
|
|
|
|
0
|
$message = $self->safe_rep($message) unless $self->{opts}{unlimited}; |
77
|
|
|
|
|
|
|
# $message = $self->perl_format($message) if $self->{opts}{code}; |
78
|
0
|
|
|
|
|
0
|
$self->{interfaces}[-1]->msg_nocr($message); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub read_command($) { |
83
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
84
|
0
|
|
|
|
|
0
|
$self->{interfaces}[-1]->read_command($self->{prompt}); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# sub perl_format($$) { |
88
|
|
|
|
|
|
|
# my($self, $text); |
89
|
|
|
|
|
|
|
# return $text unless $self->settings{highlight}; |
90
|
|
|
|
|
|
|
# unless @ruby_highlighter |
91
|
|
|
|
|
|
|
# begin |
92
|
|
|
|
|
|
|
# require 'coderay' |
93
|
|
|
|
|
|
|
# require 'term/ansicolor' |
94
|
|
|
|
|
|
|
# @ruby_highlighter = CodeRay::Duo[:ruby, :term] |
95
|
|
|
|
|
|
|
# rescue LoadError |
96
|
|
|
|
|
|
|
# return text |
97
|
|
|
|
|
|
|
# } |
98
|
|
|
|
|
|
|
# } |
99
|
|
|
|
|
|
|
# return @ruby_highlighter.encode(text) |
100
|
|
|
|
|
|
|
# } |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub safe_rep($$) { |
103
|
7
|
|
|
7
|
0
|
15
|
my($self, $str) = @_; |
104
|
7
|
|
|
|
|
24
|
Devel::Trepan::Util::safe_repr($str, $self->{settings}{maxstring}); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub bolden($$) { |
108
|
2
|
|
|
2
|
0
|
4
|
my($self, $message) = @_; |
109
|
2
|
50
|
33
|
|
|
10
|
if ($self->{settings}{highlight} && $HAVE_TERM_ANSIColor) { |
110
|
2
|
|
|
|
|
12
|
return $message = color('bold') . $message . color('reset'); |
111
|
|
|
|
|
|
|
} else { |
112
|
0
|
|
|
|
|
0
|
return $message |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub underline($$) { |
117
|
0
|
|
|
0
|
0
|
0
|
my($self, $message) = @_; |
118
|
0
|
0
|
0
|
|
|
0
|
if ($self->{settings}{highlight} && $HAVE_TERM_ANSIColor) { |
119
|
0
|
|
|
|
|
0
|
return $message = color('underscore') . $message . color('reset'); |
120
|
|
|
|
|
|
|
} else { |
121
|
0
|
|
|
|
|
0
|
return $message |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub section($$;$) { |
126
|
2
|
|
|
2
|
0
|
4
|
my($self, $message, $opts) = @_; |
127
|
2
|
|
50
|
|
|
7
|
$opts ||= {}; |
128
|
2
|
50
|
|
|
|
10
|
$message = $self->safe_rep($message) unless $self->{opts}{unlimited}; |
129
|
2
|
50
|
33
|
|
|
13
|
if ($self->{settings}{highlight} && $HAVE_TERM_ANSIColor) { |
130
|
2
|
|
|
|
|
7
|
$message = $self->bolden($message); |
131
|
|
|
|
|
|
|
} else { |
132
|
0
|
|
|
|
|
0
|
$message .= "\n" . '-' x length($message); |
133
|
|
|
|
|
|
|
} |
134
|
2
|
|
|
|
|
103
|
$self->{interfaces}[-1]->msg($message); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
if (__FILE__ eq $0) { |
138
|
|
|
|
|
|
|
require Devel::Trepan::CmdProcessor; |
139
|
|
|
|
|
|
|
my $proc = Devel::Trepan::CmdProcessor->new; |
140
|
|
|
|
|
|
|
if (scalar(@ARGV) > 0 && $proc->{interfaces}[-1]->is_interactive) { |
141
|
|
|
|
|
|
|
my $response = $proc->confirm("Are you sure?", 1); |
142
|
|
|
|
|
|
|
printf "You typed: %s\n", $response ? "Y" : "N"; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |