TextHighlight/Template.pm

filter: Statementstmt 9.1% 11 / 120 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 12.5% 3 / 24 Podpod 85.7% 18 / 21 totaltotal 16.1% 32 / 198 CC 16 SCAR 18.9
CC
16
Cov
7%
snippetParse
20.0
new
12.0
callbacks
6.0
CRAP 6.6
« TextHighlight/Xresources.pm ↑ Summary TextHighlight/Perl.pm »
1 package Tk::TextHighlight::Template;
2  
3 4 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 $VERSION = '0.3';
5  
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
10 0 my ($proto, $rules) = @_;
11 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
12 0 ▶ if (not defined($rules)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rules) 0 0 0
13 0 $rules = [];
14 };
15 0 my $self = {};
16 0 $self->{'lists'} = {};
17 0 $self->{'out'} = [];
18 $self->{'rules'} = $rules,
19 0 $self->{'stack'} = [];
20 0 $self->{'snippet'} = '';
21 0 $self->{'callbacks'} = {};
22 0 $self->{'oneliners'} = [],
23 bless ($self, $class);
24 0 return $self;
25 }
26  
27 0 ▶sub callbacks {
Subroutine callbacks: not called CC=2 SCAR=17.9
Pod documented
28 0 my $hlt = shift;
29 0 ▶ if (@_) { $hlt->{'callbacks'} = shift; };
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
30 0 return $hlt->{'callbacks'};
31 }
32  
33 0 ▶sub highlight {
Subroutine highlight: not called CC=2 SCAR=17.9
Pod documented
34 0 my ($hlt, $text) = @_;
35 0 $hlt->snippetParse;
36 0 my $out = $hlt->out;
37 0 @$out = ();
38 0 ▶ while ($text) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text) 0 0 0
39 # print "highlighting '$text'\n";
40 # print "mode is", $hlt->stackTop, "\n";
41 0 my $sub = $hlt->callbacks->{$hlt->stackTop};
42 0 $text = &$sub($hlt, $text);
43 }
44 0 $hlt->snippetParse;
45 0 return @$out;
46 }
47  
48 0 ▶sub lists {
Subroutine lists: not called CC=2 SCAR=17.9
Pod documented
49 0 my $hlt = shift;
50 0 ▶ if (@_) { $hlt->{'lists'} = shift; };
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
51 0 return $hlt->{'lists'};
52 }
53  
54 0 ▶sub listAdd {
Subroutine listAdd: not called CC=2 SCAR=17.9
Pod documented
55 0 my $hlt = shift;
56 0 my $listname = shift;
57 # print "listname $listname\n";
58 0 my $lst = $hlt->lists;
59 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
60 0 $lst->{$listname} = [@_];
61 } else {
62 0 $lst->{$listname} = [];
63 }
64 0 my $r = $hlt->lists->{$listname};
65 # print "added tokens\n"; foreach my $f (@$r) { print " $f\n"; };
66 }
67  
68 0 ▶sub rules {
Subroutine rules: not called CC=2 SCAR=17.9
Pod documented
69 0 my $hlt = shift;
70 0 ▶ if (@_) { $hlt->{'rules'} = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
71 0 return $hlt->{'rules'};
72 }
73  
74 0 ▶sub out {
Subroutine out: not called CC=2 SCAR=17.9
Pod documented
75 0 my $hlt = shift;
76 0 ▶ if (@_) { $hlt->{'out'} = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
77 0 return $hlt->{'out'};
78 }
79  
80 0 ▶sub parserError {
Subroutine parserError: not called CC=2 SCAR=17.9
Pod documented
81 0 my ($hlt, $text) = @_;
82 0 my $s = $hlt->stack;
83 0 ▶ if (@$s eq 1) { #we cannot dump this mode because it's the lowest.
Branch: 1 branch
BranchTrueFalseTotal
if (@$s eq 1) { } 0 0 0
84 0 warn "Parser error\n\tmode: '" . $hlt->stackTop . "'\n" .
85 "text: '$text'\nparsing as plain text";
86 0 $hlt->snippetParse($text);
87 0 $text =''; #Let's call it a day;
88 } else {
89 0 warn "Parser error\n\tmode: '" . $hlt->stackTop . "'\n" .
90 "text: '$text'\nexiting mode";
91 0 $hlt->stackPull;
92 };
93 0 return $text;
94 }
95  
96 0 ▶sub snippet {
Subroutine snippet: not called CC=2 SCAR=17.9
Pod undocumented
97 0 my $hlt = shift;
98 0 ▶ if (@_) { $hlt->{'snippet'} = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
99 0 return $hlt->{'snippet'};
100 }
101  
102 0 ▶sub snippetAppend {
Subroutine snippetAppend: not called CC=1 SCAR=6.9
Pod documented
103 0 my ($hlt, $ch) = @_;
104 0 $hlt->{'snippet'} = $hlt->{'snippet'} . $ch;
105 }
106  
107 0 ▶sub snippetParse {
Subroutine snippetParse: not called CC=4 SCAR=30.0
Pod documented
108 0 my $hlt = shift;
109 0 my $snip = shift;
110 0 my $attr = shift;
111 0 ▶ unless (defined($snip)) { $snip = $hlt->snippet }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $snip) 0 0 0
112 0 ▶ unless (defined($attr)) { $attr = $hlt->stackTop }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $attr) 0 0 0
113 0 my $out = $hlt->{'out'};
114 # print "parsing '$snip' with attribute '$attr'\n";
115 0 ▶ if (length $snip) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $snip) 0 0 0
116 0 push(@$out, length($snip), $attr);
117 0 $hlt->snippet('');
118 }
119 }
120  
121 0 ▶sub stack {
Subroutine stack: not called CC=1 SCAR=6.9
Pod documented
122 0 my $hlt = shift;
123 0 return $hlt->{'stack'};
124 }
125  
126 0 ▶sub stackPush {
Subroutine stackPush: not called CC=1 SCAR=6.9
Pod documented
127 0 my ($hlt, $val) = @_;
128 # print "pushing $val\n";
129 0 my $stack = $hlt->stack;
130 0 unshift(@$stack, $val);
131 }
132  
133 0 ▶sub stackPull {
Subroutine stackPull: not called CC=1 SCAR=6.9
Pod documented
134 0 my ($hlt, $val) = @_;
135 0 my $stack = $hlt->stack;
136 0 return shift(@$stack);
137 }
138  
139 0 ▶sub stackTop {
Subroutine stackTop: not called CC=1 SCAR=6.9
Pod documented
140 0 my $hlt = shift;
141 0 return $hlt->stack->[0];
142 }
143  
144 0 ▶sub stateCompare {
Subroutine stateCompare: not called CC=2 SCAR=17.9
Pod documented
145 0 my ($hlt, $state) = @_;
146 0 my $h = [ $hlt->stateGet ];
147 0 my $equal = 1;
148 0 ▶ if (Dumper($h) ne Dumper($state)) { $equal = 0 };
Branch: 1 branch
BranchTrueFalseTotal
if (Dumper($h) ne Dumper($state)) 0 0 0
149 0 return $equal;
150 }
151  
152 0 ▶sub stateGet {
Subroutine stateGet: not called CC=1 SCAR=6.9
Pod documented
153 0 my $hlt = shift;
154 0 my $s = $hlt->stack;
155 0 return @$s;
156 }
157  
158 0 ▶sub stateSet {
Subroutine stateSet: not called CC=1 SCAR=6.9
Pod documented
159 0 my $hlt = shift;
160 0 my $s = $hlt->stack;
161 0 @$s = (@_);
162 }
163  
164 0 ▶sub syntax {
Subroutine syntax: not called CC=1 SCAR=6.9
Pod undocumented
165 0 my $hlt = shift;
166 0 my $class = ref $hlt;
167 0 $class =~ /Tk::TextHighlight::(.*)/o;
168 0 return $1;
169 }
170  
171 0 ▶sub tokenParse {
Subroutine tokenParse: not called CC=1 SCAR=6.9
Pod documented
172 0 my $hlt = shift;
173 0 my $tkn = shift;
174 0 $hlt->stackPush($tkn);
175 0 $hlt->snippetParse(@_);
176 0 $hlt->stackPull;
177 }
178  
179 0 ▶sub tokenTest {
Subroutine tokenTest: not called CC=2 SCAR=17.9
Pod documented
180 0 my ($hlt, $test, $list) = @_;
181 # print "tokenTest $test\n";
182 0 my $l = $hlt->lists->{$list};
183 0 my @list = reverse sort @$l;
184 # return grep { ($test =~ /^$_/o) } @$l;
185 0 my @rl = grep { (substr($test, 0, length($_)) eq $_) } @list;
186 # foreach my $r (@rl) { print "$r\n" }
187 0 ▶ if (@rl) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rl) { } 0 0 0
188 0 return $rl[0]
189 } else {
190 0 return undef;
191 }
192 }
193 4 1;
194  
195 __END__
« TextHighlight/Xresources.pm ↑ Summary TextHighlight/Perl.pm »