Acme-SuddenlyDeath
view release on metacpan or search on metacpan
lib/Acme/SuddenlyDeath.pm view on Meta::CPAN
use Text::VisualWidth::UTF8;
our @EXPORT = qw/ sudden_death sudden_death_single /;
use version; our $VERSION = '0.09';
sub _generator {
my $decoded_str = shift;
my @decoded_lines = split /\n/, $decoded_str;
my $max_length = 0;
$max_length = $_ > $max_length ? $_ : $max_length
for map {Text::VisualWidth::UTF8::width($_)} @decoded_lines;
my $ascii = [];
my $frame_length = ($max_length + 2) / 2;
push @{$ascii}, '_' . '人' x $frame_length . '_';
for my $line (@decoded_lines) {
my $str_length = $max_length - Text::VisualWidth::UTF8::width($line);
my ($left, $right) = map{' ' x $_} ($str_length / 2, $str_length / 2);
$left = $str_length % 2 != 0 ? $left . ' ' : $left;
push @{$ascii}, 'ï¼ ' . $left . $line . $right . ' ï¼';
}
push @{$ascii}, 'ï¿£' . '^Y' x ($frame_length - 1) . '^ï¿£';
return $ascii;
}
sub sudden_death {
my $string = shift;
my $ascii = _generator($string);
return join "\n", @{$ascii};
}
( run in 1.219 second using v1.01-cache-2.11-cpan-65fba6d93b7 )