App-Unicode-Block
view release on metacpan or search on metacpan
my ($class, @params) = @_;
# Create object.
my $self = bless {}, $class;
# Object.
return $self;
}
# Run.
sub run {
my $self = shift;
# Process arguments.
$self->{'_opts'} = {
'h' => 0,
'l' => 0,
};
if (! getopts('hl', $self->{'_opts'}) || $self->{'_opts'}->{'h'}) {
print STDERR "Usage: $0 [-h] [-l] [--version] [unicode_block]\n";
print STDERR "\t-h\t\tHelp.\n";
print STDERR "\t-l\t\tList of blocks.\n";
print STDERR "\t--version\tPrint version.\n";
print STDERR "\tunicode_block\tUnicode block name for print.\n";
return 1;
}
$self->{'_unicode_block'} = $ARGV[0];
# Get unicode block list.
$self->{'_list'} = Unicode::Block::List->new;
$self->{'_unicode_block_list'} = [$self->{'_list'}->list];
# Check unicode block.
if (defined $self->{'_unicode_block'}) {
if (none { $self->{'_unicode_block'} eq $_ }
@{$self->{'_unicode_block_list'}}) {
err "Unicode block '$self->{'_unicode_block'}' doesn't exist.";
}
}
# Print unicode blocks.
if ($self->{'_opts'}->{'l'}) {
print join "\n", @{$self->{'_unicode_block_list'}};
print "\n";
return 0;
}
# Print block.
if ($self->{'_unicode_block'}) {
$self->_print_block($self->{'_unicode_block'});
# GUI for selecting of block.
} else {
# Window.
my $cui = Curses::UI->new;
my $win = $cui->add('window_id', 'Window');
$win->set_binding(\&exit, "\cQ", "\cC");
# Popup menu.
my $popupbox = $win->add(
'mypopupbox', 'Popupmenu',
'-labels' => {
map { $_, $_ } @{$self->{'_unicode_block_list'}},
},
'-onchange' => sub {
my $cui_self = shift;
$cui->leave_curses;
$self->_print_block($cui_self->get);
exit 0;
},
'-values' => $self->{'_unicode_block_list'},
);
$popupbox->focus;
# Loop.
$cui->mainloop;
}
return 0;
}
sub _print_block {
my ($self, $block) = @_;
my $block_hr = $self->{'_list'}->block($block);
my $block_ascii = Unicode::Block::Ascii->new(%{$block_hr});
print encode_utf8($block_ascii->get)."\n";
return;
}
1;
__END__
=pod
=encoding utf8
=head1 NAME
App::Unicode::Block - Base class for unicode-block script.
=head1 SYNOPSIS
use App::Unicode::Block;
my $app = App::Unicode::Block->new;
$app->run;
=head1 METHODS
=over 8
=item C<new()>
Constructor.
=item C<run()>
Run method.
Returns undef.
=back
=head1 ERRORS
run():
Unicode block '%s' doesn't exist.
=head1 EXAMPLE
( run in 1.693 second using v1.01-cache-2.11-cpan-364913b4093 )