line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Turns figlets into styled figlets |
2
|
1
|
|
|
1
|
|
643
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
4
|
|
|
|
|
|
|
package Text::ASCII::Stylize; |
5
|
1
|
|
|
1
|
|
189
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use YAML::Tiny; |
7
|
|
|
|
|
|
|
use Try::Tiny; |
8
|
|
|
|
|
|
|
use Getopt::Long; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use constant DEFAULT_FORMAT => 'id-software'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'in' => ( |
13
|
|
|
|
|
|
|
is => 'rw', |
14
|
|
|
|
|
|
|
isa => 'ArrayRef' |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'dib' => ( |
18
|
|
|
|
|
|
|
is => 'rw', |
19
|
|
|
|
|
|
|
isa => 'ArrayRef' |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'yaml' => ( |
23
|
|
|
|
|
|
|
is => 'rw', |
24
|
|
|
|
|
|
|
isa => 'Object' |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has 'format' => ( |
28
|
|
|
|
|
|
|
is => 'rw', |
29
|
|
|
|
|
|
|
isa => 'Str', |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub main { |
33
|
|
|
|
|
|
|
my ($self) = @_; |
34
|
|
|
|
|
|
|
$self->proc_options(); |
35
|
|
|
|
|
|
|
$self->defaults(); |
36
|
|
|
|
|
|
|
$self->proc_in(); |
37
|
|
|
|
|
|
|
$self->proc_yaml(); |
38
|
|
|
|
|
|
|
$self->proc_seq(); |
39
|
|
|
|
|
|
|
$self->blit(); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub put { |
43
|
|
|
|
|
|
|
my ($self,$x,$y,$ch) = @_; |
44
|
|
|
|
|
|
|
try { |
45
|
|
|
|
|
|
|
$self->dib->[$y]->[$x] = $ch; |
46
|
|
|
|
|
|
|
} catch { |
47
|
|
|
|
|
|
|
return(0); |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub get { |
52
|
|
|
|
|
|
|
my ($self,$x,$y) = @_; |
53
|
|
|
|
|
|
|
my $ret; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
return(0) if $x < 0 || $y < 0; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
try { |
58
|
|
|
|
|
|
|
$ret = $self->dib->[$y]->[$x]; |
59
|
|
|
|
|
|
|
} catch { |
60
|
|
|
|
|
|
|
return(0); |
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
return($ret) if $ret; |
64
|
|
|
|
|
|
|
return(0); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub rio { |
68
|
|
|
|
|
|
|
my ($self,$x,$y,$ch,$w) = @_; |
69
|
|
|
|
|
|
|
if(&$w) { |
70
|
|
|
|
|
|
|
$self->put($x,$y,$ch); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub letters { |
75
|
|
|
|
|
|
|
my ($self) = @_; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# top down |
78
|
|
|
|
|
|
|
$self->letters_top_half(); |
79
|
|
|
|
|
|
|
$self->letters_full(); |
80
|
|
|
|
|
|
|
$self->letters_bottom_half(); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# left right |
83
|
|
|
|
|
|
|
$self->letters_top_left(); |
84
|
|
|
|
|
|
|
$self->letters_bottom_left(); |
85
|
|
|
|
|
|
|
$self->letters_top_right(); |
86
|
|
|
|
|
|
|
$self->letters_bottom_right(); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub letters_full { |
90
|
|
|
|
|
|
|
my ($self) = @_; |
91
|
|
|
|
|
|
|
my ($idx_x,$idx_y) = (0,0); |
92
|
|
|
|
|
|
|
for my $y (@{$self->dib}) { |
93
|
|
|
|
|
|
|
for my $x (@{$y}) { |
94
|
|
|
|
|
|
|
$self->rio($idx_x,$idx_y,$self->yaml->[0]->{preset}->{letters}->{blocks}->{fill},sub { |
95
|
|
|
|
|
|
|
my $block = $self->get($idx_x,$idx_y); |
96
|
|
|
|
|
|
|
if($block =~ /[|\$&\()V\/\\=\:\<\>;]/) { |
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
} else { |
99
|
|
|
|
|
|
|
0; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
}); |
102
|
|
|
|
|
|
|
$idx_x++; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
$idx_x = 0; |
105
|
|
|
|
|
|
|
$idx_y++; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub letters_top_half { |
110
|
|
|
|
|
|
|
my ($self) = @_; |
111
|
|
|
|
|
|
|
my ($idx_x,$idx_y) = (0,0); |
112
|
|
|
|
|
|
|
for my $y (@{$self->dib}) { |
113
|
|
|
|
|
|
|
for my $x (@{$y}) { |
114
|
|
|
|
|
|
|
$self->rio($idx_x,$idx_y,$self->yaml->[0]->{preset}->{letters}->{blocks}->{'top-half'},sub { |
115
|
|
|
|
|
|
|
my $block = $self->get($idx_x,$idx_y); |
116
|
|
|
|
|
|
|
if($block =~ /[-'`*]/) { |
117
|
|
|
|
|
|
|
1; |
118
|
|
|
|
|
|
|
} else { |
119
|
|
|
|
|
|
|
0; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
}); |
122
|
|
|
|
|
|
|
$idx_x++; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
$idx_x = 0; |
125
|
|
|
|
|
|
|
$idx_y++; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub letters_top_left { |
130
|
|
|
|
|
|
|
my ($self) = @_; |
131
|
|
|
|
|
|
|
my ($idx_x,$idx_y) = (0,0); |
132
|
|
|
|
|
|
|
for my $y (@{$self->dib}) { |
133
|
|
|
|
|
|
|
for my $x (@{$y}) { |
134
|
|
|
|
|
|
|
$self->rio($idx_x,$idx_y,$self->yaml->[0]->{preset}->{letters}->{blocks}->{'top-left'},sub { |
135
|
|
|
|
|
|
|
my $block = $self->get($idx_x,$idx_y); |
136
|
|
|
|
|
|
|
my $block_above = ($self->get($idx_x,$idx_y - 1) || ' '); |
137
|
|
|
|
|
|
|
my $block_left = ($self->get($idx_x - 1,$idx_y) || ' '); |
138
|
|
|
|
|
|
|
if($block_left =~ /[\s]/ && $block_above =~ /[\s]/ && $block =~ /[^\s]/) { |
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
} else { |
141
|
|
|
|
|
|
|
0; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
}); |
144
|
|
|
|
|
|
|
$idx_x++; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
$idx_x = 0; |
147
|
|
|
|
|
|
|
$idx_y++; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub letters_top_right { |
152
|
|
|
|
|
|
|
my ($self) = @_; |
153
|
|
|
|
|
|
|
my ($idx_x,$idx_y) = (0,0); |
154
|
|
|
|
|
|
|
for my $y (@{$self->dib}) { |
155
|
|
|
|
|
|
|
for my $x (@{$y}) { |
156
|
|
|
|
|
|
|
$self->rio($idx_x,$idx_y,$self->yaml->[0]->{preset}->{letters}->{blocks}->{'top-right'},sub { |
157
|
|
|
|
|
|
|
my $block = $self->get($idx_x,$idx_y); |
158
|
|
|
|
|
|
|
my $block_above = ($self->get($idx_x,$idx_y - 1) || ' '); |
159
|
|
|
|
|
|
|
my $block_diag = ($self->get($idx_x + 1,$idx_y - 1) || ' '); |
160
|
|
|
|
|
|
|
my $block_right = ($self->get($idx_x + 1,$idx_y) || ' '); |
161
|
|
|
|
|
|
|
if($block_right =~ /[\s]/ && $block_above =~ /[\s]/ && $block_diag =~ /[\s]/ && $block =~ /[^\s]/) { |
162
|
|
|
|
|
|
|
return(1); |
163
|
|
|
|
|
|
|
} else { |
164
|
|
|
|
|
|
|
return(0); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
}); |
167
|
|
|
|
|
|
|
$idx_x++; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
$idx_x = 0; |
170
|
|
|
|
|
|
|
$idx_y++; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub letters_bottom_left { |
175
|
|
|
|
|
|
|
my ($self) = @_; |
176
|
|
|
|
|
|
|
my ($idx_x,$idx_y) = (0,0); |
177
|
|
|
|
|
|
|
for my $y (@{$self->dib}) { |
178
|
|
|
|
|
|
|
for my $x (@{$y}) { |
179
|
|
|
|
|
|
|
$self->rio($idx_x,$idx_y,$self->yaml->[0]->{preset}->{letters}->{blocks}->{'bottom-left'},sub { |
180
|
|
|
|
|
|
|
my $block = $self->get($idx_x,$idx_y); |
181
|
|
|
|
|
|
|
my $block_below = ($self->get($idx_x,$idx_y + 1) || ' '); |
182
|
|
|
|
|
|
|
my $block_diag = ($self->get($idx_x - 1,$idx_y + 1) || ' '); |
183
|
|
|
|
|
|
|
my $block_left = ($self->get($idx_x - 1,$idx_y) || ' '); |
184
|
|
|
|
|
|
|
if($block_left =~ /[\s]/ && $block_below =~ /[\s]/ && $block_diag =~ /[\s]/ && $block =~ /[^\s]/) { |
185
|
|
|
|
|
|
|
return(1); |
186
|
|
|
|
|
|
|
} else { |
187
|
|
|
|
|
|
|
return(0); |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
}); |
190
|
|
|
|
|
|
|
$idx_x++; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
$idx_x = 0; |
193
|
|
|
|
|
|
|
$idx_y++; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub letters_bottom_right { |
198
|
|
|
|
|
|
|
my ($self) = @_; |
199
|
|
|
|
|
|
|
my ($idx_x,$idx_y) = (0,0); |
200
|
|
|
|
|
|
|
for my $y (@{$self->dib}) { |
201
|
|
|
|
|
|
|
for my $x (@{$y}) { |
202
|
|
|
|
|
|
|
$self->rio($idx_x,$idx_y,$self->yaml->[0]->{preset}->{letters}->{blocks}->{'bottom-right'},sub { |
203
|
|
|
|
|
|
|
my $block = $self->get($idx_x,$idx_y); |
204
|
|
|
|
|
|
|
my $block_below = ($self->get($idx_x,$idx_y + 1) || ' '); |
205
|
|
|
|
|
|
|
my $block_diag = ($self->get($idx_x + 1,$idx_y + 1) || ' '); |
206
|
|
|
|
|
|
|
my $block_right = ($self->get($idx_x + 1,$idx_y) || ' '); |
207
|
|
|
|
|
|
|
if($block_right =~ /[\s]/ && $block_below =~ /[\s]/ && $block_diag =~ /[\s]/ && $block =~ /[^\s]/) { |
208
|
|
|
|
|
|
|
return(1); |
209
|
|
|
|
|
|
|
} else { |
210
|
|
|
|
|
|
|
return(0); |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
}); |
213
|
|
|
|
|
|
|
$idx_x++; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
$idx_x = 0; |
216
|
|
|
|
|
|
|
$idx_y++; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub letters_bottom_half { |
221
|
|
|
|
|
|
|
my ($self) = @_; |
222
|
|
|
|
|
|
|
my ($idx_x,$idx_y) = (0,0); |
223
|
|
|
|
|
|
|
for my $y (@{$self->dib}) { |
224
|
|
|
|
|
|
|
for my $x (@{$y}) { |
225
|
|
|
|
|
|
|
$self->rio($idx_x,$idx_y,$self->yaml->[0]->{preset}->{letters}->{blocks}->{'bottom-half'},sub { |
226
|
|
|
|
|
|
|
my $block = $self->get($idx_x,$idx_y); |
227
|
|
|
|
|
|
|
if($block =~ /[_,]/) { |
228
|
|
|
|
|
|
|
return(1); |
229
|
|
|
|
|
|
|
} else { |
230
|
|
|
|
|
|
|
return(0); |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
}); |
233
|
|
|
|
|
|
|
$idx_x++; |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
$idx_x = 0; |
236
|
|
|
|
|
|
|
$idx_y++; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub fill_fill { |
241
|
|
|
|
|
|
|
my ($self) = @_; |
242
|
|
|
|
|
|
|
my ($idx_x,$idx_y) = (0,0); |
243
|
|
|
|
|
|
|
for my $y (@{$self->dib}) { |
244
|
|
|
|
|
|
|
for my $x (@{$y}) { |
245
|
|
|
|
|
|
|
$self->rio($idx_x,$idx_y,$self->yaml->[0]->{preset}->{letters}->{blocks}->{'fill-fill'},sub { |
246
|
|
|
|
|
|
|
my $block = $self->get($idx_x,$idx_y); |
247
|
|
|
|
|
|
|
my $block_above = ($self->get($idx_x,$idx_y - 1) || ' '); |
248
|
|
|
|
|
|
|
my $block_below = ($self->get($idx_x,$idx_y + 1) || ' '); |
249
|
|
|
|
|
|
|
my $block_left = ($self->get($idx_x - 1,$idx_y) || ' '); |
250
|
|
|
|
|
|
|
my $block_right = ($self->get($idx_x + 1,$idx_y) || ' '); |
251
|
|
|
|
|
|
|
if(($block_below =~ /[\s]/ && $block_above =~ /[\s]/ && $block_right =~ /[\s]/ && $block_left =~ /[\s]/) && $block =~ /[\s]/) { |
252
|
|
|
|
|
|
|
return(1); |
253
|
|
|
|
|
|
|
} else { |
254
|
|
|
|
|
|
|
return(0); |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
}); |
257
|
|
|
|
|
|
|
$idx_x++; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
$idx_x = 0; |
260
|
|
|
|
|
|
|
$idx_y++; |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
sub proc_options { |
265
|
|
|
|
|
|
|
my $self = shift; |
266
|
|
|
|
|
|
|
my $opt_format = DEFAULT_FORMAT; |
267
|
|
|
|
|
|
|
eval { |
268
|
|
|
|
|
|
|
GetOptions('format=s' => \$opt_format); |
269
|
|
|
|
|
|
|
$self->format($opt_format); |
270
|
|
|
|
|
|
|
}; |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
die "Regrettably, this is not a valid format option. Choose one of (id-software or seth-able)." if $@; |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
return(0); |
275
|
|
|
|
|
|
|
} |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
sub proc_seq { |
278
|
|
|
|
|
|
|
my ($self) = @_; |
279
|
|
|
|
|
|
|
$self->letters; |
280
|
|
|
|
|
|
|
$self->fill_fill; |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
sub proc_yaml { |
284
|
|
|
|
|
|
|
my ($self) = @_; |
285
|
|
|
|
|
|
|
open(my $yaml_filehandle,'<','./text_ascii_stylize.d/' . $self->format . '.yml') or die('cannot open < format.yml'); |
286
|
|
|
|
|
|
|
my @lines = <$yaml_filehandle>; |
287
|
|
|
|
|
|
|
close($yaml_filehandle); |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
my $yaml = YAML::Tiny->read_string("@lines"); |
290
|
|
|
|
|
|
|
$self->yaml($yaml); |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
sub defaults { |
294
|
|
|
|
|
|
|
my ($self) = @_; |
295
|
|
|
|
|
|
|
my @in = <>; |
296
|
|
|
|
|
|
|
$self->in(\@in); |
297
|
|
|
|
|
|
|
} |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
sub blit { |
300
|
|
|
|
|
|
|
my ($self) = @_; |
301
|
|
|
|
|
|
|
for my $y (@{$self->dib}) { |
302
|
|
|
|
|
|
|
for my $x (@{$y}) { |
303
|
|
|
|
|
|
|
print $x; |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
print "\n"; |
306
|
|
|
|
|
|
|
} |
307
|
|
|
|
|
|
|
} |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
sub proc_in { |
310
|
|
|
|
|
|
|
my ($self) = @_; |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
my @rows = @{$self->in}; |
313
|
|
|
|
|
|
|
my @dib; |
314
|
|
|
|
|
|
|
for my $y (@rows) { |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
my @row; |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
chomp($y); |
319
|
|
|
|
|
|
|
for(my $x = 0;$x < length($y);$x++) { |
320
|
|
|
|
|
|
|
push @row,substr($y,$x,1); |
321
|
|
|
|
|
|
|
} |
322
|
|
|
|
|
|
|
push @dib,\@row; |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
$self->dib(\@dib); |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
1; |