Tidy/Debugger.pm

filter: Statementstmt 92.4% 61 / 66 Branchbran 62.5% 10 / 16 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 76.8% 83 / 108 CC 13 SCAR 18.8
CC
13
Cov
81%
close_debug_file
13.1
write_debug_entry
6.0
really_open_debug_file
2.0
CRAP 6.6
« Tidy/FileWriter.pm ↑ Summary Tidy/VerticalAligner/Line.pm »
1 package Perl::Tidy::Debugger;
2  
3 #####################################################################
4 #
5 # The Perl::Tidy::Debugger class shows line tokenization
6 #
7 #####################################################################
8  
9 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 44 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 44 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 44 our $VERSION = '20260705';
13  
14 44 ▶use constant EMPTY_STRING => q{};
Subroutine BEGIN: called CC=1 SCAR=0.0
15 44 ▶use constant SPACE => q{ };
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 sub new {
18  
19 2 ▶ my ( $class, $filename, $is_encoded_data ) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
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 sub really_open_debug_file {
30  
31 2 ▶ my $self = shift;
Subroutine really_open_debug_file: called CC=2 SCAR=7.0
Pod undocumented
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
BranchTrueFalseTotal
unless ($fh) 0 2 2
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 sub close_debug_file {
46  
47 2 ▶ my $self = shift;
Subroutine close_debug_file: called CC=7 SCAR=25.7
Pod undocumented
48 2 ▶ if ( $self->{_debug_file_opened} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_debug_file_opened"}) 2 0 2
49 2 my $fh = $self->{_fh};
50 2 my $debug_file = $self->{_debug_file};
51 2 ▶ if ( $fh
Branch: 1 branch
BranchTrueFalseTotal
if ($fh and $fh->can("close") and $debug_file ne "-" and not ref $debug_file) 0 2 2
Condition33%3/9
$fh and $fh->can("close") and $debug_file ne "-" and not ref $debug_file
!ll&&!rl&&r
200
$fh and $fh->can("close") and $debug_file ne "-"
!ll&&!rl&&r
200
$fh and $fh->can("close")
!ll&&!rl&&r
020
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
ABCDresult
0XXX0
10XX0
110X0
11100
11111
52 && $fh->can('close')
53 && $debug_file ne '-'
54 && !ref($debug_file) )
55 {
56 0 ▶ $fh->close()
Branch: 1 branch
BranchTrueFalseTotal
$fh->close or Perl::Tidy::Warn("can't close DEBUG file '${debug_file}': $Perl::Tidy::Debugger::OS_ERROR\n") 0 0 0
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 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 ▶ my ( $self, $line_of_tokens ) = @_;
Subroutine write_debug_entry: called CC=6 SCAR=18.0
Pod undocumented
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
BranchTrueFalseTotal
unless ($self->{"_debug_file_opened"}) 2 5 7
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
BranchTrueFalseTotal
if ($rtoken_type->[$j] eq 'k') { } 2 18 20
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
BranchTrueFalseTotal
if ($type_str eq " ") 0 20 20
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
BranchTrueFalseTotal
if (length $type_str == 1) 19 1 20
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 44 1;
« Tidy/FileWriter.pm ↑ Summary Tidy/VerticalAligner/Line.pm »