| 1 | package Perl::Tidy::Debugger; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ##################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # The Perl::Tidy::Debugger class shows line tokenization | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ##################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 45 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 45 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 45 | ▶ | use English qw( -no_match_vars ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 45 | our $VERSION = '20260826'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 45 | ▶ | use constant EMPTY_STRING => q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 45 | ▶ | use constant SPACE => q{ }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | my ( $class, $filename, $is_encoded_data ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | return bless { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | _debug_file => $filename, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | _debug_file_opened => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | _fh => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | _is_encoded_data => $is_encoded_data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } ## end sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | sub really_open_debug_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
really_open_debug_file: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | my $debug_file = $self->{_debug_file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | my $is_encoded_data = $self->{_is_encoded_data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | my $fh = Perl::Tidy::streamhandle( $debug_file, 'w', $is_encoded_data ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | if ( !$fh ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | Perl::Tidy::Warn("can't open debug file '$debug_file'\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | $self->{_debug_file_opened} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | $self->{_fh} = $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | $fh->print( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | "Use -dump-token-types (-dtt) to get a list of token type codes\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } ## end sub really_open_debug_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | sub close_debug_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close_debug_file: called CC=7 SCAR=25.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | ▶ | if ( $self->{_debug_file_opened} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | my $fh = $self->{_fh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | my $debug_file = $self->{_debug_file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | ▶ | if ( $fh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$fh and $fh->can("close") and $debug_file ne "-" and not ref $debug_file
$fh and $fh->can("close") and $debug_file ne "-"
$fh and $fh->can("close")
MC/DC0%0/4
$fh and $fh->can("close") and $debug_file ne "-" and not ref $debug_file
$fh
$fh->can("close")
$debug_file ne "-"
not ref $debug_file
Truth table20%1/5
A and B and C and not(D)
A= $fhB= $fh->can("close")C= $debug_file ne "-"D= not ref $debug_file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | && $fh->can('close') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | && $debug_file ne '-' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | && !ref($debug_file) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | $fh->close() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | or Perl::Tidy::Warn( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | "can't close DEBUG file '$debug_file': $OS_ERROR\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } ## end sub close_debug_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 7 | ▶ | sub write_debug_entry { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_debug_entry: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | my ( $self, $line_of_tokens ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 7 | my $rtoken_type = $line_of_tokens->{_rtoken_type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 7 | my $rtokens = $line_of_tokens->{_rtokens}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 7 | my $input_line_number = $line_of_tokens->{_line_number}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ## uncomment if needed: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ## my $input_line = $line_of_tokens->{_line_text}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ## my $rlevels = $line_of_tokens->{_rlevels}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ## my $line_type = $line_of_tokens->{_line_type}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 7 | my $token_str = "$input_line_number: "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 7 | my $reconstructed_original = "$input_line_number: "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 7 | my $pattern = EMPTY_STRING; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 7 | my @next_char = ( '"', '"' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 7 | my $i_next = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 7 | ▶ | if ( !$self->{_debug_file_opened} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | $self->really_open_debug_file(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 7 | my $fh = $self->{_fh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 7 | foreach my $j ( 0 .. @{$rtoken_type} - 1 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # testing patterns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 20 | ▶ | if ( $rtoken_type->[$j] eq 'k' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | $pattern .= $rtokens->[$j]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 18 | $pattern .= $rtoken_type->[$j]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 20 | $reconstructed_original .= $rtokens->[$j]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 20 | my $num = length( $rtokens->[$j] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 20 | my $type_str = $rtoken_type->[$j]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # be sure there are no blank tokens (shouldn't happen) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # This can only happen if a programming error has been made | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # because all valid tokens are non-blank | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 20 | ▶ | if ( $type_str eq SPACE ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $fh->print("BLANK TOKEN on the next line\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $type_str = $next_char[$i_next]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $i_next = 1 - $i_next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 20 | ▶ | if ( length($type_str) == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 19 | $type_str = $type_str x $num; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 20 | $token_str .= $type_str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # Write what you want here ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # $fh->print "$input_line\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # $fh->print "$pattern\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 7 | $fh->print("$reconstructed_original\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 7 | $fh->print("$token_str\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } ## end sub write_debug_entry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 45 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||