Rosetta
view release on metacpan or search on metacpan
lib/Rosetta/Shell.pm view on Meta::CPAN
#!perl
use 5.008001;
use utf8;
use strict;
use warnings;
# External packages used by packages in this file, that don't export symbols:
use only 'Locale::KeyedText' => '1.72.0-';
use only 'Rosetta' => '0.722.0-';
###########################################################################
###########################################################################
# Constant values used by packages in this file:
use only 'Readonly' => '1.03-';
Readonly my $EMPTY_STR => q{};
###########################################################################
###########################################################################
{ package Rosetta::Shell; # module
use version; our $VERSION = qv('0.1.2');
# External packages used by the Rosetta::Shell module, that do export symbols:
# (None Yet)
# State variables used by the Rosetta::Shell module:
my $translator;
my $dbms;
###########################################################################
sub main {
my ($arg_ref) = @_;
my $engine_name = $arg_ref->{'engine_name'};
my $user_lang_prefs_ref
= exists $arg_ref->{'user_lang_prefs'}
? $arg_ref->{'user_lang_prefs'} : ['en'];
$translator = Locale::KeyedText::Translator->new({
'set_names' => [
'Rosetta::Shell::L::',
'Rosetta::L::',
'Rosetta::Model::L::',
'Locale::KeyedText::L::',
$engine_name . '::L::',
],
'member_names' => $user_lang_prefs_ref,
});
_show_message( Locale::KeyedText::Message->new({
'msg_key' => 'ROS_S_HELLO' }) );
eval {
$dbms = Rosetta::Interface::DBMS->new({
'engine_name' => $engine_name });
};
if ($@) {
_show_message( Locale::KeyedText::Message->new({
'msg_key' => 'ROS_S_DBMS_INIT_FAIL',
'msg_vars' => {
'ENGINE_NAME' => $engine_name,
},
}) );
}
else {
_show_message( Locale::KeyedText::Message->new({
'msg_key' => 'ROS_S_DBMS_INIT_SUCCESS',
'msg_vars' => {
'ENGINE_NAME' => $engine_name,
},
}) );
_command_loop();
}
_show_message( Locale::KeyedText::Message->new({
'msg_key' => 'ROS_S_GOODBYE' }) );
return;
}
###########################################################################
sub _command_loop {
INPUT_LINE:
while (1) {
_show_message( Locale::KeyedText::Message->new({
'msg_key' => 'ROS_S_PROMPT' }) );
my $user_input = <STDIN>;
chomp $user_input;
# user simply hits return on an empty line to quit the program
last INPUT_LINE
if $user_input eq $EMPTY_STR;
eval {
_show_message( Locale::KeyedText::Message->new({
'msg_key' => 'ROS_S_TODO_RESULT' }) );
};
_show_message( $@ )
if $@; # input error, detected by library
}
return;
}
###########################################################################
( run in 1.009 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )