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