| 1 | package CohortExplorer::Application; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = 0.14; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use base qw(CLI::Framework::Application); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use CLI::Framework::Exceptions qw ( :all); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use CohortExplorer::Datasource; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Exception::Class::TryCatch; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Term::ReadKey; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | #------- | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub usage_text { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage_text: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | q{ | |||||||||||||||||||||||||||||||||||||||||
| 18 | CohortExplorer | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | OPTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 21 | -d --datasource : provide datasource | ||||||||||||||||||||||||||||||||||||||||||
| 22 | -u --username : provide username | ||||||||||||||||||||||||||||||||||||||||||
| 23 | -p --password : provide password | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | -v --verbose : show with verbosity | ||||||||||||||||||||||||||||||||||||||||||
| 26 | -h --help : show usage message and exit | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | COMMANDS | ||||||||||||||||||||||||||||||||||||||||||
| 30 | help - show application or command-specific help | ||||||||||||||||||||||||||||||||||||||||||
| 31 | menu - show menu of available commands | ||||||||||||||||||||||||||||||||||||||||||
| 32 | console - start a command console for the application | ||||||||||||||||||||||||||||||||||||||||||
| 33 | describe - show datasource description including the entity count | ||||||||||||||||||||||||||||||||||||||||||
| 34 | find - find variables using keywords | ||||||||||||||||||||||||||||||||||||||||||
| 35 | search - search entities with/without conditions on variables | ||||||||||||||||||||||||||||||||||||||||||
| 36 | compare - compare entities across visits (valid to longitudinal datasources with data on at least 2 visits) | ||||||||||||||||||||||||||||||||||||||||||
| 37 | history - show saved commands | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub option_spec { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
option_spec: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | # Username, password and datasource name are mandatory options | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # Password may or may not be provided at start | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | [], | |||||||||||||||||||||||||||||||||||||||||
| 47 | [ 'datasource|d:s' => 'provide datasource' ], | ||||||||||||||||||||||||||||||||||||||||||
| 48 | [ 'username|u:s' => 'provide username' ], | ||||||||||||||||||||||||||||||||||||||||||
| 49 | [ 'password|p:s' => 'provide password' ], | ||||||||||||||||||||||||||||||||||||||||||
| 50 | [], | ||||||||||||||||||||||||||||||||||||||||||
| 51 | [ 'verbose|v' => 'show with verbosity' ], | ||||||||||||||||||||||||||||||||||||||||||
| 52 | [ 'help|h' => 'show usage message and exit' ], | ||||||||||||||||||||||||||||||||||||||||||
| 53 | []; | ||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub validate_options { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_options: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my ( $app, $opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | # Show help and exit | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ( $opts->{help} || keys %$opts == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opts->{"help"} or keys %$opts == 0
MC/DC0%0/2
$opts->{"help"} or keys %$opts == 0
$opts->{"help"}
keys %$opts == 0
Truth table0%0/3
A or B
A= $opts->{"help"}B= keys %$opts == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $app->render( $app->get_default_usage ); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | # Throw exception if mandatory options are missing | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ( !$opts->{datasource} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$opts->{'datasource'} && $opts->{'username'} && exists $opts->{'password'}
$opts->{"datasource"} and $opts->{"username"}
MC/DC0%0/3
$opts->{'datasource'} && $opts->{'username'} && exists $opts->{'password'}
$opts->{"datasource"}
$opts->{"username"}
exists $opts->{'password'}
Truth table0%0/4
A and B && C
A= $opts->{"datasource"}B= $opts->{"username"}C= exists $opts->{'password'}
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | || !$opts->{username} | ||||||||||||||||||||||||||||||||||||||||||
| 68 | || !exists $opts->{password} ) | ||||||||||||||||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | throw_app_opts_validation_exception( | |||||||||||||||||||||||||||||||||||||||||
| 71 | error => "All mandatory parameters must be provided" ); | ||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub command_map { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_map: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | console => 'CLI::Framework::Command::Console', | |||||||||||||||||||||||||||||||||||||||||
| 78 | help => 'CohortExplorer::Command::Help', | ||||||||||||||||||||||||||||||||||||||||||
| 79 | menu => 'CohortExplorer::Command::Menu', | ||||||||||||||||||||||||||||||||||||||||||
| 80 | describe => 'CohortExplorer::Command::Describe', | ||||||||||||||||||||||||||||||||||||||||||
| 81 | history => 'CohortExplorer::Command::History', | ||||||||||||||||||||||||||||||||||||||||||
| 82 | find => 'CohortExplorer::Command::Find', | ||||||||||||||||||||||||||||||||||||||||||
| 83 | search => 'CohortExplorer::Command::Query::Search', | ||||||||||||||||||||||||||||||||||||||||||
| 84 | compare => 'CohortExplorer::Command::Query::Compare'; | ||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub command_alias { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_alias: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | h => 'help', | |||||||||||||||||||||||||||||||||||||||||
| 89 | m => 'menu', | ||||||||||||||||||||||||||||||||||||||||||
| 90 | s => 'search', | ||||||||||||||||||||||||||||||||||||||||||
| 91 | c => 'compare', | ||||||||||||||||||||||||||||||||||||||||||
| 92 | d => 'describe', | ||||||||||||||||||||||||||||||||||||||||||
| 93 | hist => 'history', | ||||||||||||||||||||||||||||||||||||||||||
| 94 | f => 'find', | ||||||||||||||||||||||||||||||||||||||||||
| 95 | sh => 'console'; | ||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub noninteractive_commands { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
noninteractive_commands: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my ($app) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my $ds = $app->cache->get('cache')->{datasource}; | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | # May or may not be preloaded | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | eval 'require ' . ref $ds; | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | # Menu and console commands are invalid under interactive mode | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | push my @noninteractive_command, qw/menu console/; | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | # search, compare and history commands are invalid if the user | ||||||||||||||||||||||||||||||||||||||||||
| 109 | # does not have access to any variable | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ( keys %{ $ds->variable_info } == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | push @noninteractive_command, qw/search history compare/; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | # Compare command is invalid only if | ||||||||||||||||||||||||||||||||||||||||||
| 115 | # visit variables are defined | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ( !$ds->visit_variables ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | push @noninteractive_command, 'compare'; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | return @noninteractive_command; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub render { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my ( $app, $output ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | # All commands except help return hash where key is headingText (table heading) | ||||||||||||||||||||||||||||||||||||||||||
| 126 | # and value is ref to array of arrays containing column values | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ( ref $output eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | require Text::ASCIITable; | |||||||||||||||||||||||||||||||||||||||||
| 129 | my $t = Text::ASCIITable->new( | ||||||||||||||||||||||||||||||||||||||||||
| 130 | { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | hide_Lastline => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 132 | reportErrors => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 133 | drawRowLine => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | headingText => $output->{headingText} | ||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my @col = @{ shift @{ $output->{rows} } }; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | my $colWidth = $output->{headingText} eq 'command history' ? 1000 : 30; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $t->setCols(@col); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | for (@col) { | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $t->setColWidth( $_, $colWidth ); | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | # Prevent truncation by inserting space at every $colWidth character | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | for my $r ( @{ $output->{rows} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 146 | my @row = map { | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | substr( $_, ( $colWidth - 1 ), 0 ) = ' ' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$_ and $_ =~ /^[^\n]+$/ and length $_ >= $colWidth
$_ and $_ =~ /^[^\n]+$/
MC/DC0%0/3
$_ and $_ =~ /^[^\n]+$/ and length $_ >= $colWidth
$_
$_ =~ /^[^\n]+$/
length $_ >= $colWidth
Truth table0%0/4
A and B and C
A= $_B= $_ =~ /^[^\n]+$/C= length $_ >= $colWidth
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | if ( $_ && $_ =~ /^[^\n]+$/ && length $_ >= $colWidth ); | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $_ | |||||||||||||||||||||||||||||||||||||||||
| 150 | } @$r; | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $t->addRow(@row); | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | my $table = $t->draw( | |||||||||||||||||||||||||||||||||||||||||
| 155 | [ '', '', '', '' ], | ||||||||||||||||||||||||||||||||||||||||||
| 156 | [ '', '', '' ], | ||||||||||||||||||||||||||||||||||||||||||
| 157 | [ '', '', '', '' ], | ||||||||||||||||||||||||||||||||||||||||||
| 158 | [ '', '', '' ], | ||||||||||||||||||||||||||||||||||||||||||
| 159 | [ '', '', '', '' ], | ||||||||||||||||||||||||||||||||||||||||||
| 160 | [ '', '', '', '' ] | ||||||||||||||||||||||||||||||||||||||||||
| 161 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 162 | ) =~ s/\|//g; | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | if ( $^O eq 'linux' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | delete @ENV{qw(PATH)}; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $ENV{PATH} = "/usr/bin:/bin"; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $path = $ENV{'PATH'}; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | open( my $less, '|-', $ENV{PAGER} || 'less', '-e' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$ENV{'PAGER'} || 'less'
MC/DC0%0/1
$ENV{'PAGER'} || 'less'
$ENV{'PAGER'}
Truth table0%0/2
A
A= $ENV{'PAGER'}
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | or croak "Failed to pipe to pager: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | print $less "\n" . $table . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | close($less); | |||||||||||||||||||||||||||||||||||||||||
| 171 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | print "\n" . $table . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | print STDERR $output; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | sub handle_exception { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_exception: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my ( $app, $e ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my $cache = $app->cache->get('cache'); | |||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if ( !$cache | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $cache or $e->isa("CLI::Framework::Exception::CmdValidationException")
MC/DC0%0/2
not $cache or $e->isa("CLI::Framework::Exception::CmdValidationException")
not $cache
$e->isa("CLI::Framework::Exception::CmdValidationException")
Truth table0%0/3
not(A) or B
A= not $cacheB= $e->isa("CLI::Framework::Exception::CmdValidationException")
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | || $e->isa('CLI::Framework::Exception::CmdValidationException') ) | ||||||||||||||||||||||||||||||||||||||||||
| 185 | { | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | # Print command validation errors for the users | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $app->render( $e->description . "\n\n" . $e->error . "\n\n" ); | |||||||||||||||||||||||||||||||||||||||||
| 189 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | # Print application initialization related errors (source CohortExplorer::Datasource) | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | $app->render( $e->description . "\n\n" ); | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | # Log all other errors | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if ($cache) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $cache->{logger}->error( $e->error . ' [ User: ', $cache->{user} . ' ]' ); | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | sub pre_dispatch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pre_dispatch: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my ( $app, $command ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $cache = $app->cache->get('cache'); | |||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my @invalid_command = | |||||||||||||||||||||||||||||||||||||||||
| 206 | grep ( /^(search|compare|history)$/, $app->noninteractive_commands ); | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my $current_command = $app->get_current_command; | |||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | # Don't allow invalid commands to dispatch | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if ( grep( $_ eq $current_command, @invalid_command ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | throw_invalid_cmd_exception( | |||||||||||||||||||||||||||||||||||||||||
| 212 | error => "Invalid command: " . $current_command . "\n" ); | ||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | # Log user activity | ||||||||||||||||||||||||||||||||||||||||||
| 216 | $cache->{logger} | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ->info( "Command '$current_command' is run by " . $cache->{user} ); | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | sub read_cmd { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_cmd: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | my ($app) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | require Text::ParseWords; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | # Retrieve or cache Term::ReadLine object (this is necessary to save | ||||||||||||||||||||||||||||||||||||||||||
| 225 | # command-line history in persistent object) | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my $term = $app->{_readline}; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | if ( !$term ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | require Term::ReadLine; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | $term = Term::ReadLine->new('CohortExplorer'); | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | select $term->OUT; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $app->{_readline} = $term; | |||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | # Arrange for command-line completion | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | my $attribs = $term->Attribs; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | $term->ornaments(0); | |||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | $attribs->{completion_function} = $app->_cmd_request_completions; | |||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | # Prompt for the name of a command and read input from STDIN | ||||||||||||||||||||||||||||||||||||||||||
| 240 | # Store the individual tokens that are read in @ARGV | ||||||||||||||||||||||||||||||||||||||||||
| 241 | my $command_request = | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | $term->readline( $app->cache->get('cache')->{user} . '# ' ); | |||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if ( !defined $command_request ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | # Interpret CTRL-D (EOF) as a quit signal | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | @ARGV = $app->quit_signals; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | print "\n"; # since EOF character is rendered as '' | |||||||||||||||||||||||||||||||||||||||||
| 248 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | # Prepare command for usual parsing | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | @ARGV = Text::ParseWords::shellwords($command_request); | |||||||||||||||||||||||||||||||||||||||||
| 252 | $term->addhistory($command_request) | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | if ( $command_request =~ /\S/ and !$term->Features->{autohistory} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$command_request =~ /\S/ and not $term->Features->{"autohistory"}
MC/DC0%0/2
$command_request =~ /\S/ and not $term->Features->{"autohistory"}
$command_request =~ /\S/
not $term->Features->{"autohistory"}
Truth table0%0/3
A and not(B)
A= $command_request =~ /\S/B= not $term->Features->{"autohistory"}
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | sub _cmd_request_completions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cmd_request_completions: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | my ($app) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | # Valid only when the application is running in console/interactive mode | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=28 SCAR=67.0
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | my ( $text, $line, $start ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my $ds = $app->cache->get('cache')->{datasource}; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my $ds_type = $ds->type; | |||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | # Listen to search/compare commands | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if ( $line =~ /^\s*(search|compare|find|history|[scf]|hist)\s+/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my $cmd = $1; | |||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | # Make completion work with command aliases | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | $cmd = 'search' if ( $cmd eq 's' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | $cmd = 'compare' if ( $cmd eq 'c' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | $cmd = 'find' if ( $cmd eq 'f' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | $cmd = 'history' if ( $cmd eq 'hist' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | # Ensure search/compare/history/find are valid commands | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | if ( $app->is_interactive_command($cmd) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | # Listen to options | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | if ( $text =~ /^\s*\-/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | return qw(--show --clear) if ( $cmd eq 'history' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | return qw(--fuzzy --ignore-case --and) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | if ( $cmd eq 'find' ); | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | return qw(--out --cond --save-command --stats --export --export-all) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | if ( $cmd =~ /^(search|compare)$/ ); | ||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | if ( $cmd =~ /^(?:search|compare)$/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cmd =~ /^(?:search|compare)$/ and substr($line, 0, ($start - 1)) =~ /(\-o|\-\-out)\s*$/
MC/DC0%0/2
$cmd =~ /^(?:search|compare)$/ and substr($line, 0, ($start - 1)) =~ /(\-o|\-\-out)\s*$/
$cmd =~ /^(?:search|compare)$/
substr($line, 0, ($start - 1)) =~ /(\-o|\-\-out)\s*$/
Truth table0%0/3
A and B
A= $cmd =~ /^(?:search|compare)$/B= substr($line, 0, ($start - 1)) =~ /(\-o|\-\-out)\s*$/
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | && substr( $line, 0, $start - 1 ) =~ /(\-o|\-\-out)\s*$/ ) | ||||||||||||||||||||||||||||||||||||||||||
| 290 | { | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | return File::HomeDir->my_home; | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | if ( $cmd =~ /^(?:search|compare)$/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cmd =~ /^(?:search|compare)$/ and substr($line, 0, ($start - 1)) =~ /(\-e|\-\-export)\s*$/
MC/DC0%0/2
$cmd =~ /^(?:search|compare)$/ and substr($line, 0, ($start - 1)) =~ /(\-e|\-\-export)\s*$/
$cmd =~ /^(?:search|compare)$/
substr($line, 0, ($start - 1)) =~ /(\-e|\-\-export)\s*$/
Truth table0%0/3
A and B
A= $cmd =~ /^(?:search|compare)$/B= substr($line, 0, ($start - 1)) =~ /(\-e|\-\-export)\s*$/
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | && substr( $line, 0, $start - 1 ) =~ /(\-e|\-\-export)\s*$/ ) | ||||||||||||||||||||||||||||||||||||||||||
| 295 | { | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | return keys %{ $ds->table_info }; | |||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | if ( $cmd eq 'search' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cmd eq "search" and substr($line, 0, ($start - 1)) =~ /(\-c|\-\-cond)\s*$/
MC/DC0%0/2
$cmd eq "search" and substr($line, 0, ($start - 1)) =~ /(\-c|\-\-cond)\s*$/
$cmd eq "search"
substr($line, 0, ($start - 1)) =~ /(\-c|\-\-cond)\s*$/
Truth table0%0/3
A and B
A= $cmd eq "search"B= substr($line, 0, ($start - 1)) =~ /(\-c|\-\-cond)\s*$/
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | && substr( $line, 0, $start - 1 ) =~ /(\-c|\-\-cond)\s*$/ ) | ||||||||||||||||||||||||||||||||||||||||||
| 300 | { | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | return map { $_ . "='opr, val'" } ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | $ds_type eq 'standard' | ||||||||||||||||||||||||||||||||||||||||||
| 303 | ? qw(entity_id) | ||||||||||||||||||||||||||||||||||||||||||
| 304 | : qw(entity_id visit) | ||||||||||||||||||||||||||||||||||||||||||
| 305 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | keys %{ $ds->variable_info }; | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | if ( $cmd eq 'compare' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cmd eq "compare" and substr($line, 0, ($start - 1)) =~ /(\-c|\-\-cond)\s*$/
MC/DC0%0/2
$cmd eq "compare" and substr($line, 0, ($start - 1)) =~ /(\-c|\-\-cond)\s*$/
$cmd eq "compare"
substr($line, 0, ($start - 1)) =~ /(\-c|\-\-cond)\s*$/
Truth table0%0/3
A and B
A= $cmd eq "compare"B= substr($line, 0, ($start - 1)) =~ /(\-c|\-\-cond)\s*$/
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | && substr( $line, 0, $start - 1 ) =~ /(\-c|\-\-cond)\s*$/ ) | ||||||||||||||||||||||||||||||||||||||||||
| 310 | { | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | return map { $_ . "='opr, val'" } ( | |||||||||||||||||||||||||||||||||||||||||
| 312 | qw(entity_id), | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | keys %{ $ds->variable_info }, | |||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | @{ $ds->visit_variables || [] } | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ds->visit_variables || []
MC/DC0%0/1
$ds->visit_variables || []
$ds->visit_variables
Truth table0%0/2
A
A= $ds->visit_variables
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | # Listen to arguments | ||||||||||||||||||||||||||||||||||||||||||
| 319 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | if ( $cmd eq 'search' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | return keys %{ $ds->variable_info }; | |||||||||||||||||||||||||||||||||||||||||
| 322 | } elsif ( $cmd eq 'find' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | return keys %{ $ds->table_info }; | |||||||||||||||||||||||||||||||||||||||||
| 324 | } elsif ( $cmd eq 'compare' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | return ( keys %{ $ds->variable_info }, @{ $ds->visit_variables || [] } ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ds->visit_variables || []
MC/DC0%0/1
$ds->visit_variables || []
$ds->visit_variables
Truth table0%0/2
A
A= $ds->visit_variables
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | # help command | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | return $app->get_interactive_commands if ( $line =~ /^\s*help/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | # describe command | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | return if $line =~ /^\s*describe/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | # default | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | return $app->get_interactive_commands if ( $line =~ /^\s*/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | my ( $app, $opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | require Log::Log4perl; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | require File::Spec; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | require File::HomeDir; | |||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | # Path to log configuration file | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | my $log_config_file = | |||||||||||||||||||||||||||||||||||||||||
| 352 | File::Spec->catfile( File::Spec->rootdir, 'etc', | ||||||||||||||||||||||||||||||||||||||||||
| 353 | 'CohortExplorer', 'log-config.properties' ); | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | # initialize logger | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | eval { Log::Log4perl::init($log_config_file); }; | |||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | if ( catch my $e ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | throw_app_init_exception( error => $e ); | |||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my $logger = Log::Log4perl->get_logger; | |||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | # Check command history file exists and is readable and writable | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | my $command_history_file = | |||||||||||||||||||||||||||||||||||||||||
| 364 | File::Spec->catfile( File::HomeDir->my_home, ".CohortExplorer_History" ); | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | if ( !-r $command_history_file || !-w $command_history_file ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-r $command_history_file and -w $command_history_file
MC/DC0%0/2
-r $command_history_file and -w $command_history_file
-r $command_history_file
-w $command_history_file
Truth table0%0/3
A and B
A= -r $command_history_fileB= -w $command_history_file
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | throw_app_init_exception( error => | |||||||||||||||||||||||||||||||||||||||||
| 367 | "'$command_history_file' must exist with RW enabled (i.e. chmod 766) for CohortExplorer" | ||||||||||||||||||||||||||||||||||||||||||
| 368 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | # Prompt for password if not provided at command line | ||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | if ( !$opts->{password} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | $app->render("Enter password: "); | |||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ReadMode 'noecho'; | |||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | $opts->{password} = ReadLine(300); | |||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ReadMode 'normal'; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | $app->render("\n"); | |||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | if ( !$opts->{password} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | $app->render("timeout\n"); | |||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | chomp $opts->{password}; | |||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | # Path to datasource configuration file | ||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | my $ds_config_file = | |||||||||||||||||||||||||||||||||||||||||
| 387 | File::Spec->catfile( File::Spec->rootdir, 'etc', | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 'CohortExplorer', 'datasource-config.properties' ); | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | require Text::CSV_XS; | |||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | # Initialize the datasource and store the datasource object along with other bits | ||||||||||||||||||||||||||||||||||||||||||
| 392 | # in cache for further use | ||||||||||||||||||||||||||||||||||||||||||
| 393 | $app->cache->set( | ||||||||||||||||||||||||||||||||||||||||||
| 394 | cache => { | ||||||||||||||||||||||||||||||||||||||||||
| 395 | datasource => | ||||||||||||||||||||||||||||||||||||||||||
| 396 | CohortExplorer::Datasource->initialize( $opts, $ds_config_file ), | ||||||||||||||||||||||||||||||||||||||||||
| 397 | datasource_name => $opts->{datasource}, | ||||||||||||||||||||||||||||||||||||||||||
| 398 | verbose => $opts->{verbose}, | ||||||||||||||||||||||||||||||||||||||||||
| 399 | user => $opts->{username} . '@' . $opts->{datasource}, | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | logger => $logger, | |||||||||||||||||||||||||||||||||||||||||
| 401 | csv => | ||||||||||||||||||||||||||||||||||||||||||
| 402 | Text::CSV_XS->new( | ||||||||||||||||||||||||||||||||||||||||||
| 403 | { | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 'quote_char' => '"', | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 'escape_char' => '"', | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 'sep_char' => ',', | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 'binary' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 408 | 'auto_diag' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 'eol' => $/ | ||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||
| 411 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | if ( $app->get_current_command eq 'console' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | $app->render( | |||||||||||||||||||||||||||||||||||||||||
| 416 | "Welcome to the CohortExplorer version $VERSION console." . "\n\n" | ||||||||||||||||||||||||||||||||||||||||||
| 417 | . "Type 'help <COMMAND>' for command specific help." . "\n" | ||||||||||||||||||||||||||||||||||||||||||
| 418 | . "Use tab for command-line completion and ctrl + L to clear the screen." | ||||||||||||||||||||||||||||||||||||||||||
| 419 | . "\n" | ||||||||||||||||||||||||||||||||||||||||||
| 420 | . "Type q or exit to quit." ); | ||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | #------- | ||||||||||||||||||||||||||||||||||||||||||
| 426 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 427 | __END__ | ||||||||||||||||||||||||||||||||||||||||||