| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
2
|
|
|
2
|
|
14889
|
use 5.010; # state |
|
|
2
|
|
|
|
|
4
|
|
|
2
|
2
|
|
|
2
|
|
6
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
36
|
|
|
3
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
160
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Minecraft::SectionFilter; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.003003'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Strip/Process magical ยง characters from minecraft |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY |
|
12
|
|
|
|
|
|
|
|
|
13
|
2
|
|
|
|
|
17
|
use Sub::Exporter::Progressive -setup => { |
|
14
|
|
|
|
|
|
|
exports => [qw( translate_sections strip_sections ansi_encode_sections )], |
|
15
|
|
|
|
|
|
|
groups => { |
|
16
|
|
|
|
|
|
|
default => [qw( strip_sections ansi_encode_sections )], |
|
17
|
|
|
|
|
|
|
}, |
|
18
|
2
|
|
|
2
|
|
777
|
}; |
|
|
2
|
|
|
|
|
1513
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
191
|
use Carp qw( carp ); |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
982
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub translate_sections { |
|
39
|
4
|
|
|
4
|
1
|
6
|
my ($line) = @_; |
|
40
|
|
|
|
|
|
|
|
|
41
|
4
|
|
|
|
|
6
|
state $section = chr 0xA7; |
|
42
|
|
|
|
|
|
|
|
|
43
|
4
|
|
|
|
|
2
|
my (@out); |
|
44
|
4
|
|
|
|
|
15
|
while ( length $line > 0 ) { |
|
45
|
24
|
100
|
|
|
|
111
|
if ( $line =~ /\A([^$section]+)/msx ) { |
|
46
|
12
|
|
|
|
|
28
|
push @out, { type => text =>, content => "$1", }; |
|
47
|
12
|
|
|
|
|
24
|
substr $line, 0, length "$1", q{}; |
|
48
|
12
|
|
|
|
|
20
|
next; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
12
|
50
|
|
|
|
47
|
if ( $line =~ /\A$section(.)/msx ) { |
|
51
|
12
|
|
|
|
|
32
|
push @out, { type => section =>, section_code => "$1" }; |
|
52
|
12
|
|
|
|
|
43
|
substr $line, 0, 2, q{}; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
} |
|
56
|
4
|
|
|
|
|
12
|
return @out; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _section_to_stripped { |
|
68
|
12
|
|
|
12
|
|
12
|
my ($section) = @_; |
|
69
|
12
|
100
|
|
|
|
34
|
return $section->{content} if 'text' eq $section->{type}; |
|
70
|
6
|
|
|
|
|
9
|
return q{}; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub strip_sections { |
|
74
|
2
|
|
|
2
|
1
|
2203
|
my ($section_string) = @_; |
|
75
|
2
|
|
|
|
|
5
|
return join q{}, map { _section_to_stripped($_) } translate_sections($section_string); |
|
|
12
|
|
|
|
|
14
|
|
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _ansi_translation_table { |
|
79
|
1
|
|
|
1
|
|
26
|
return state $translation_table = { |
|
80
|
|
|
|
|
|
|
0 => 'black', |
|
81
|
|
|
|
|
|
|
1 => 'blue', |
|
82
|
|
|
|
|
|
|
2 => 'green', |
|
83
|
|
|
|
|
|
|
3 => 'cyan', |
|
84
|
|
|
|
|
|
|
4 => 'red', |
|
85
|
|
|
|
|
|
|
5 => 'magenta', |
|
86
|
|
|
|
|
|
|
6 => 'yellow', |
|
87
|
|
|
|
|
|
|
7 => 'white', |
|
88
|
|
|
|
|
|
|
8 => 'bright_black', |
|
89
|
|
|
|
|
|
|
9 => 'bright_blue', |
|
90
|
|
|
|
|
|
|
a => 'bright_green', |
|
91
|
|
|
|
|
|
|
b => 'bright_cyan', |
|
92
|
|
|
|
|
|
|
c => 'bright_red', |
|
93
|
|
|
|
|
|
|
d => 'bright_magenta', |
|
94
|
|
|
|
|
|
|
e => 'bright_yellow', |
|
95
|
|
|
|
|
|
|
f => 'bright_white', |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
l => 'bold', |
|
98
|
|
|
|
|
|
|
m => 'concealed', |
|
99
|
|
|
|
|
|
|
n => 'underscore', |
|
100
|
|
|
|
|
|
|
o => 'reverse', |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
r => 'reset', |
|
103
|
|
|
|
|
|
|
}; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _warn { |
|
107
|
0
|
|
|
0
|
|
0
|
my (@args) = @_; |
|
108
|
0
|
|
|
|
|
0
|
return carp( sprintf '[%s] %s', __PACKAGE__, join q{ }, @args ); |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _warnf { |
|
112
|
0
|
|
|
0
|
|
0
|
my (@args) = @_; |
|
113
|
0
|
|
|
|
|
0
|
my $format = '[%s] ' . shift; |
|
114
|
0
|
|
|
|
|
0
|
return carp( sprintf $format, __PACKAGE__, @args ); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub _section_to_ansi { |
|
118
|
12
|
|
|
12
|
|
11
|
my ($section) = @_; |
|
119
|
12
|
100
|
|
|
|
32
|
return $section->{content} unless 'section' eq $section->{type}; |
|
120
|
6
|
|
|
|
|
6
|
state $colorize = do { |
|
121
|
1
|
|
|
|
|
9
|
require Term::ANSIColor; |
|
122
|
1
|
|
|
|
|
3
|
\&Term::ANSIColor::color; |
|
123
|
|
|
|
|
|
|
}; |
|
124
|
6
|
|
|
|
|
6
|
state $trt = _ansi_translation_table(); |
|
125
|
6
|
|
|
|
|
8
|
my ($code) = $section->{section_code}; |
|
126
|
6
|
50
|
|
|
|
13
|
if ( exists $trt->{$code} ) { |
|
127
|
6
|
|
|
|
|
15
|
return $colorize->( $trt->{$code} ); |
|
128
|
|
|
|
|
|
|
} |
|
129
|
0
|
0
|
|
|
|
0
|
if ( exists $trt->{ lc $code } ) { |
|
130
|
0
|
|
|
|
|
0
|
_warnf( 'uppercase section code "%s" (ord=%s)', $section->{section_code}, ord $section->{section_code} ); |
|
131
|
0
|
|
|
|
|
0
|
return $colorize->( $trt->{ lc $code } ); |
|
132
|
|
|
|
|
|
|
} |
|
133
|
0
|
|
|
|
|
0
|
_warnf( 'unknown section code "%s" (ord=%s)', $section->{section_code}, ord $section->{section_code} ); |
|
134
|
0
|
|
|
|
|
0
|
return '{section_code} . '>'; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub ansi_encode_sections { |
|
146
|
2
|
|
|
2
|
1
|
781
|
my ($section_string) = @_; |
|
147
|
2
|
|
|
|
|
5
|
return join q{}, map { _section_to_ansi($_) } translate_sections($section_string); |
|
|
12
|
|
|
|
|
93
|
|
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
1; |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
__END__ |