CohortExplorer
view release on metacpan or search on metacpan
lib/CohortExplorer/Application.pm view on Meta::CPAN
}
if ( $cmd eq 'compare'
&& substr( $line, 0, $start - 1 ) =~ /(\-c|\-\-cond)\s*$/ )
{
return map { $_ . "='opr, val'" } (
qw(entity_id),
keys %{ $ds->variable_info },
@{ $ds->visit_variables || [] }
);
}
# Listen to arguments
else {
if ( $cmd eq 'search' ) {
return keys %{ $ds->variable_info };
} elsif ( $cmd eq 'find' ) {
return keys %{ $ds->table_info };
} elsif ( $cmd eq 'compare' ) {
return ( keys %{ $ds->variable_info }, @{ $ds->visit_variables || [] } );
} else {
return;
}
}
}
}
# help command
return $app->get_interactive_commands if ( $line =~ /^\s*help/ );
# describe command
return if $line =~ /^\s*describe/;
# default
return $app->get_interactive_commands if ( $line =~ /^\s*/ );
}
}
sub init {
my ( $app, $opts ) = @_;
require Log::Log4perl;
require File::Spec;
require File::HomeDir;
# Path to log configuration file
my $log_config_file =
File::Spec->catfile( File::Spec->rootdir, 'etc',
'CohortExplorer', 'log-config.properties' );
# initialize logger
eval { Log::Log4perl::init($log_config_file); };
if ( catch my $e ) {
throw_app_init_exception( error => $e );
}
my $logger = Log::Log4perl->get_logger;
# Check command history file exists and is readable and writable
my $command_history_file =
File::Spec->catfile( File::HomeDir->my_home, ".CohortExplorer_History" );
if ( !-r $command_history_file || !-w $command_history_file ) {
throw_app_init_exception( error =>
"'$command_history_file' must exist with RW enabled (i.e. chmod 766) for CohortExplorer"
);
}
# Prompt for password if not provided at command line
if ( !$opts->{password} ) {
$app->render("Enter password: ");
ReadMode 'noecho';
$opts->{password} = ReadLine(300);
ReadMode 'normal';
$app->render("\n");
if ( !$opts->{password} ) {
$app->render("timeout\n");
exit;
}
}
chomp $opts->{password};
# Path to datasource configuration file
my $ds_config_file =
File::Spec->catfile( File::Spec->rootdir, 'etc',
'CohortExplorer', 'datasource-config.properties' );
require Text::CSV_XS;
# Initialize the datasource and store the datasource object along with other bits
# in cache for further use
$app->cache->set(
cache => {
datasource =>
CohortExplorer::Datasource->initialize( $opts, $ds_config_file ),
datasource_name => $opts->{datasource},
verbose => $opts->{verbose},
user => $opts->{username} . '@' . $opts->{datasource},
logger => $logger,
csv =>
Text::CSV_XS->new(
{
'quote_char' => '"',
'escape_char' => '"',
'sep_char' => ',',
'binary' => 1,
'auto_diag' => 1,
'eol' => $/
}
)
}
);
if ( $app->get_current_command eq 'console' ) {
$app->render(
"Welcome to the CohortExplorer version $VERSION console." . "\n\n"
. "Type 'help <COMMAND>' for command specific help." . "\n"
. "Use tab for command-line completion and ctrl + L to clear the screen."
. "\n"
. "Type q or exit to quit." );
}
return;
}
#-------
1;
__END__
( run in 0.714 second using v1.01-cache-2.11-cpan-39bf76dae61 )