| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::perlhl; |
|
2
|
3
|
|
|
3
|
|
325358
|
use strict; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
449
|
|
|
3
|
3
|
|
|
3
|
|
198
|
use warnings; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
101
|
|
|
4
|
3
|
|
|
3
|
|
57
|
use v5.10.1; |
|
|
3
|
|
|
|
|
11
|
|
|
|
3
|
|
|
|
|
188
|
|
|
5
|
3
|
|
|
3
|
|
4752
|
no if ($] >= 5.017010), warnings => 'experimental::smartmatch'; |
|
|
3
|
|
|
|
|
28
|
|
|
|
3
|
|
|
|
|
22
|
|
|
6
|
3
|
|
|
3
|
|
6191
|
use Syntax::Highlight::Perl::Improved 1.01 (); |
|
|
3
|
|
|
|
|
114815
|
|
|
|
3
|
|
|
|
|
123
|
|
|
7
|
3
|
|
|
3
|
|
18579
|
use Term::ANSIColor 3.00 (); |
|
|
3
|
|
|
|
|
50397
|
|
|
|
3
|
|
|
|
|
2471
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: application class for syntax highlighting Perl source code |
|
10
|
|
|
|
|
|
|
our $VERSION = '0.007'; # VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
|
14
|
4
|
|
|
4
|
1
|
3821
|
my $class = shift; |
|
15
|
4
|
|
100
|
|
|
23
|
my $output= shift || 'ansi'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
4
|
|
|
|
|
43
|
my $formatter = Syntax::Highlight::Perl::Improved->new(); |
|
18
|
4
|
|
|
|
|
1717
|
given ($output) { |
|
19
|
4
|
|
|
|
|
33
|
when ('html') { |
|
20
|
2
|
|
|
|
|
57
|
my $color_table = { |
|
21
|
|
|
|
|
|
|
'Variable_Scalar' => 'color:#080;', |
|
22
|
|
|
|
|
|
|
'Variable_Array' => 'color:#f70;', |
|
23
|
|
|
|
|
|
|
'Variable_Hash' => 'color:#80f;', |
|
24
|
|
|
|
|
|
|
'Variable_Typeglob' => 'color:#f03;', |
|
25
|
|
|
|
|
|
|
'Subroutine' => 'color:#980;', |
|
26
|
|
|
|
|
|
|
'Quote' => 'color:#00a;', |
|
27
|
|
|
|
|
|
|
'String' => 'color:#00a;', |
|
28
|
|
|
|
|
|
|
'Comment_Normal' => 'color:#069;font-style:italic;', |
|
29
|
|
|
|
|
|
|
'Comment_POD' => 'color:#014;font-family:garamond,serif;font-size:11pt;', |
|
30
|
|
|
|
|
|
|
'Bareword' => 'color:#3A3;', |
|
31
|
|
|
|
|
|
|
'Package' => 'color:#900;', |
|
32
|
|
|
|
|
|
|
'Number' => 'color:#f0f;', |
|
33
|
|
|
|
|
|
|
'Operator' => 'color:#000;', |
|
34
|
|
|
|
|
|
|
'Symbol' => 'color:#000;', |
|
35
|
|
|
|
|
|
|
'Keyword' => 'color:#000;', |
|
36
|
|
|
|
|
|
|
'Builtin_Operator' => 'color:#300;', |
|
37
|
|
|
|
|
|
|
'Builtin_Function' => 'color:#001;', |
|
38
|
|
|
|
|
|
|
'Character' => 'color:#800;', |
|
39
|
|
|
|
|
|
|
'Directive' => 'color:#399;font-style:italic;', |
|
40
|
|
|
|
|
|
|
'Label' => 'color:#939;font-style:italic;', |
|
41
|
|
|
|
|
|
|
'Line' => 'color:#000;', |
|
42
|
|
|
|
|
|
|
}; |
|
43
|
|
|
|
|
|
|
# HTML escapes. |
|
44
|
2
|
|
|
|
|
13
|
$formatter->define_substitution('<' => '<', |
|
45
|
|
|
|
|
|
|
'>' => '>', |
|
46
|
|
|
|
|
|
|
'&' => '&'); |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# install the formats set up above |
|
49
|
2
|
|
|
|
|
35
|
while ( my($type, $style) = each %{$color_table} ) { |
|
|
44
|
|
|
|
|
773
|
|
|
50
|
42
|
|
|
|
|
162
|
$formatter->set_format($type, [ qq{}, qq{} ]); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
} |
|
53
|
2
|
|
|
|
|
6
|
when ('ansi') { |
|
54
|
2
|
|
|
|
|
47
|
my $color_table = { # Readability is not so good -- play with it more |
|
55
|
|
|
|
|
|
|
'Bareword' => 'bright_green', |
|
56
|
|
|
|
|
|
|
'Builtin_Function' => 'blue', |
|
57
|
|
|
|
|
|
|
'Builtin_Operator' => 'bright_red', |
|
58
|
|
|
|
|
|
|
'Character' => 'bold bright_red', |
|
59
|
|
|
|
|
|
|
'Comment_Normal' => 'bright_blue', |
|
60
|
|
|
|
|
|
|
'Comment_POD' => 'bright_black', |
|
61
|
|
|
|
|
|
|
'Directive' => 'bold bright_black', |
|
62
|
|
|
|
|
|
|
'Keyword' => 'white', |
|
63
|
|
|
|
|
|
|
'Label' => 'bright_magenta', |
|
64
|
|
|
|
|
|
|
'Line' => 'white', |
|
65
|
|
|
|
|
|
|
'Number' => 'bright_red', |
|
66
|
|
|
|
|
|
|
'Operator' => 'white', |
|
67
|
|
|
|
|
|
|
'Package' => 'bold bright_red', |
|
68
|
|
|
|
|
|
|
'Quote' => 'blue', |
|
69
|
|
|
|
|
|
|
'String' => 'blue', |
|
70
|
|
|
|
|
|
|
'Subroutine' => 'yellow', |
|
71
|
|
|
|
|
|
|
'Symbol' => 'white', |
|
72
|
|
|
|
|
|
|
'Variable_Array' => 'cyan', |
|
73
|
|
|
|
|
|
|
'Variable_Hash' => 'magenta', |
|
74
|
|
|
|
|
|
|
'Variable_Scalar' => 'green', |
|
75
|
|
|
|
|
|
|
'Variable_Typeglob' => 'bright_red', |
|
76
|
|
|
|
|
|
|
}; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# install the formats set up above |
|
79
|
2
|
|
|
|
|
6
|
while ( my ( $type, $style ) = each %{$color_table} ) { |
|
|
44
|
|
|
|
|
2192
|
|
|
80
|
42
|
|
|
|
|
113
|
$formatter->set_format($type, [ Term::ANSIColor::color($style), Term::ANSIColor::color('reset') ]); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
4
|
|
|
|
|
40
|
return bless { formatter => $formatter }, $class; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub run { |
|
90
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
|
91
|
2
|
|
|
|
|
4
|
my $mode = shift; |
|
92
|
2
|
|
|
|
|
9
|
my @files = @_; |
|
93
|
|
|
|
|
|
|
|
|
94
|
2
|
|
|
|
|
5
|
given ($mode) { |
|
95
|
2
|
|
|
|
|
6
|
when ('version') { $self->_do_version(); } |
|
|
0
|
|
|
|
|
0
|
|
|
96
|
2
|
|
|
|
|
5
|
when ('highlight') { $self->_do_highlighting(@files); } |
|
|
1
|
|
|
|
|
4
|
|
|
97
|
1
|
|
|
|
|
2
|
default { $self->_do_highlighting(@files); } |
|
|
1
|
|
|
|
|
5
|
|
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _do_version { |
|
102
|
0
|
|
|
0
|
|
0
|
my $this = __PACKAGE__; |
|
103
|
0
|
0
|
|
|
|
0
|
my $this_ver = (defined __PACKAGE__->VERSION ? __PACKAGE__->VERSION : 'dev'); |
|
104
|
0
|
0
|
|
|
|
0
|
say "$this version $this_ver" and exit; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _do_highlighting { |
|
108
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
|
109
|
2
|
|
|
|
|
7
|
my @files = @_; |
|
110
|
|
|
|
|
|
|
|
|
111
|
2
|
50
|
|
|
|
20
|
if (@files) { |
|
112
|
2
|
|
|
|
|
5
|
foreach my $filename (@files) { |
|
113
|
2
|
|
|
|
|
97
|
open my $in, '<', $filename; |
|
114
|
|
|
|
|
|
|
# Use a separate object for each file - otherwise, |
|
115
|
|
|
|
|
|
|
# highlighting for anything after the first file |
|
116
|
|
|
|
|
|
|
# will be suboptimal. |
|
117
|
2
|
|
|
|
|
19
|
my $formatter = $self->{formatter}->new(); |
|
118
|
2
|
|
|
|
|
1760
|
while (<$in>) { |
|
119
|
36
|
|
|
|
|
65051
|
print $formatter->format_string; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
else { |
|
124
|
0
|
|
|
|
|
0
|
while () { |
|
125
|
0
|
|
|
|
|
0
|
print $self->{formatter}->format_string while (); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
2
|
|
|
|
|
1463
|
print "\n"; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |