line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
##################################################################### |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# The Perl::Tidy::Debugger class shows line tokenization |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
##################################################################### |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Perl::Tidy::Debugger; |
8
|
39
|
|
|
39
|
|
269
|
use strict; |
|
39
|
|
|
|
|
77
|
|
|
39
|
|
|
|
|
1176
|
|
9
|
39
|
|
|
39
|
|
190
|
use warnings; |
|
39
|
|
|
|
|
71
|
|
|
39
|
|
|
|
|
1064
|
|
10
|
39
|
|
|
39
|
|
199
|
use English qw( -no_match_vars ); |
|
39
|
|
|
|
|
78
|
|
|
39
|
|
|
|
|
181
|
|
11
|
|
|
|
|
|
|
our $VERSION = '20230912'; |
12
|
|
|
|
|
|
|
|
13
|
39
|
|
|
39
|
|
14594
|
use constant EMPTY_STRING => q{}; |
|
39
|
|
|
|
|
85
|
|
|
39
|
|
|
|
|
4574
|
|
14
|
39
|
|
|
39
|
|
283
|
use constant SPACE => q{ }; |
|
39
|
|
|
|
|
72
|
|
|
39
|
|
|
|
|
28769
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
0
|
7
|
my ( $class, $filename, $is_encoded_data ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
17
|
return bless { |
21
|
|
|
|
|
|
|
_debug_file => $filename, |
22
|
|
|
|
|
|
|
_debug_file_opened => 0, |
23
|
|
|
|
|
|
|
_fh => undef, |
24
|
|
|
|
|
|
|
_is_encoded_data => $is_encoded_data, |
25
|
|
|
|
|
|
|
}, $class; |
26
|
|
|
|
|
|
|
} ## end sub new |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub really_open_debug_file { |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
31
|
2
|
|
|
|
|
6
|
my $debug_file = $self->{_debug_file}; |
32
|
2
|
|
|
|
|
4
|
my $is_encoded_data = $self->{_is_encoded_data}; |
33
|
2
|
|
|
|
|
10
|
my ( $fh, $filename ) = |
34
|
|
|
|
|
|
|
Perl::Tidy::streamhandle( $debug_file, 'w', $is_encoded_data ); |
35
|
2
|
50
|
|
|
|
9
|
if ( !$fh ) { |
36
|
0
|
|
|
|
|
0
|
Perl::Tidy::Warn("can't open $debug_file: $OS_ERROR\n"); |
37
|
|
|
|
|
|
|
} |
38
|
2
|
|
|
|
|
5
|
$self->{_debug_file_opened} = 1; |
39
|
2
|
|
|
|
|
13
|
$self->{_fh} = $fh; |
40
|
2
|
|
|
|
|
16
|
$fh->print( |
41
|
|
|
|
|
|
|
"Use -dump-token-types (-dtt) to get a list of token type codes\n"); |
42
|
2
|
|
|
|
|
4
|
return; |
43
|
|
|
|
|
|
|
} ## end sub really_open_debug_file |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub close_debug_file { |
46
|
|
|
|
|
|
|
|
47
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
48
|
2
|
50
|
|
|
|
9
|
if ( $self->{_debug_file_opened} ) { |
49
|
2
|
|
|
|
|
4
|
my $fh = $self->{_fh}; |
50
|
2
|
|
|
|
|
4
|
my $debug_file = $self->{_debug_file}; |
51
|
2
|
0
|
33
|
|
|
31
|
if ( $fh |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
52
|
|
|
|
|
|
|
&& $fh->can('close') |
53
|
|
|
|
|
|
|
&& $debug_file ne '-' |
54
|
|
|
|
|
|
|
&& !ref($debug_file) ) |
55
|
|
|
|
|
|
|
{ |
56
|
0
|
0
|
|
|
|
0
|
$fh->close() |
57
|
|
|
|
|
|
|
or Perl::Tidy::Warn( |
58
|
|
|
|
|
|
|
"can't close DEBUG file '$debug_file': $OS_ERROR\n"); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
2
|
|
|
|
|
4
|
return; |
62
|
|
|
|
|
|
|
} ## end sub close_debug_file |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub write_debug_entry { |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# This is a debug dump routine which may be modified as necessary |
67
|
|
|
|
|
|
|
# to dump tokens on a line-by-line basis. The output will be written |
68
|
|
|
|
|
|
|
# to the .DEBUG file when the -D flag is entered. |
69
|
7
|
|
|
7
|
0
|
18
|
my ( $self, $line_of_tokens ) = @_; |
70
|
|
|
|
|
|
|
|
71
|
7
|
|
|
|
|
16
|
my $input_line = $line_of_tokens->{_line_text}; |
72
|
|
|
|
|
|
|
|
73
|
7
|
|
|
|
|
12
|
my $rtoken_type = $line_of_tokens->{_rtoken_type}; |
74
|
7
|
|
|
|
|
20
|
my $rtokens = $line_of_tokens->{_rtokens}; |
75
|
7
|
|
|
|
|
12
|
my $rlevels = $line_of_tokens->{_rlevels}; |
76
|
|
|
|
|
|
|
|
77
|
7
|
|
|
|
|
12
|
my $input_line_number = $line_of_tokens->{_line_number}; |
78
|
7
|
|
|
|
|
12
|
my $line_type = $line_of_tokens->{_line_type}; |
79
|
|
|
|
|
|
|
|
80
|
7
|
|
|
|
|
12
|
my ( $j, $num ); |
81
|
|
|
|
|
|
|
|
82
|
7
|
|
|
|
|
15
|
my $token_str = "$input_line_number: "; |
83
|
7
|
|
|
|
|
12
|
my $reconstructed_original = "$input_line_number: "; |
84
|
|
|
|
|
|
|
|
85
|
7
|
|
|
|
|
13
|
my $pattern = EMPTY_STRING; |
86
|
7
|
|
|
|
|
21
|
my @next_char = ( '"', '"' ); |
87
|
7
|
|
|
|
|
14
|
my $i_next = 0; |
88
|
7
|
100
|
|
|
|
15
|
if ( !$self->{_debug_file_opened} ) { |
89
|
2
|
|
|
|
|
9
|
$self->really_open_debug_file(); |
90
|
|
|
|
|
|
|
} |
91
|
7
|
|
|
|
|
13
|
my $fh = $self->{_fh}; |
92
|
|
|
|
|
|
|
|
93
|
7
|
|
|
|
|
11
|
foreach my $j ( 0 .. @{$rtoken_type} - 1 ) { |
|
7
|
|
|
|
|
31
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# testing patterns |
96
|
20
|
100
|
|
|
|
39
|
if ( $rtoken_type->[$j] eq 'k' ) { |
97
|
2
|
|
|
|
|
5
|
$pattern .= $rtokens->[$j]; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
else { |
100
|
18
|
|
|
|
|
33
|
$pattern .= $rtoken_type->[$j]; |
101
|
|
|
|
|
|
|
} |
102
|
20
|
|
|
|
|
28
|
$reconstructed_original .= $rtokens->[$j]; |
103
|
20
|
|
|
|
|
37
|
$num = length( $rtokens->[$j] ); |
104
|
20
|
|
|
|
|
34
|
my $type_str = $rtoken_type->[$j]; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# be sure there are no blank tokens (shouldn't happen) |
107
|
|
|
|
|
|
|
# This can only happen if a programming error has been made |
108
|
|
|
|
|
|
|
# because all valid tokens are non-blank |
109
|
20
|
50
|
|
|
|
39
|
if ( $type_str eq SPACE ) { |
110
|
0
|
|
|
|
|
0
|
$fh->print("BLANK TOKEN on the next line\n"); |
111
|
0
|
|
|
|
|
0
|
$type_str = $next_char[$i_next]; |
112
|
0
|
|
|
|
|
0
|
$i_next = 1 - $i_next; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
20
|
100
|
|
|
|
40
|
if ( length($type_str) == 1 ) { |
116
|
19
|
|
|
|
|
28
|
$type_str = $type_str x $num; |
117
|
|
|
|
|
|
|
} |
118
|
20
|
|
|
|
|
42
|
$token_str .= $type_str; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# Write what you want here ... |
122
|
|
|
|
|
|
|
# $fh->print "$input_line\n"; |
123
|
|
|
|
|
|
|
# $fh->print "$pattern\n"; |
124
|
7
|
|
|
|
|
36
|
$fh->print("$reconstructed_original\n"); |
125
|
7
|
|
|
|
|
26
|
$fh->print("$token_str\n"); |
126
|
|
|
|
|
|
|
|
127
|
7
|
|
|
|
|
22
|
return; |
128
|
|
|
|
|
|
|
} ## end sub write_debug_entry |
129
|
|
|
|
|
|
|
1; |