CohortExplorer/Command/History.pm

filter: Statementstmt 43.5% 17 / 39 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 55.5% 5 / 9 Podpod 100% 4 / 4 totaltotal 36.1% 26 / 72 CC 9 SCAR 30.0
CC
9
Cov
31%
run
42.0
validate
20.0
usage_text
2.0
CRAP 20.1
« CohortExplorer/Application/REDCap/Datasource.pm ↑ Summary CohortExplorer/Command/Describe.pm »
1 package CohortExplorer::Command::History;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = 0.14;
7  
8 1 ▶use base qw(CLI::Framework::Command);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use CLI::Framework::Exceptions qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use CohortExplorer::Command::Query qw($COMMAND_HISTORY);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 #-------
13 0 ▶sub usage_text {
Subroutine usage_text: not called CC=1 SCAR=6.9
Pod documented
14 0 q{
15 history [--show|s] [--clear|c] : show saved commands
16 };
17 }
18  
19 0 ▶sub option_spec {
Subroutine option_spec: not called CC=1 SCAR=6.9
Pod documented
20 (
21 0 [],
22 [ 'show|s' => 'show command history' ],
23 [ 'clear|c' => 'clear command history' ],
24 []
25 );
26 }
27  
28 0 ▶sub validate {
Subroutine validate: not called CC=4 SCAR=30.0
Pod documented
29 0 my ( $self, $opts, @args ) = @_;
30 0 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 0 0
31 0 throw_cmd_validation_exception(
32 error => 'No arguments are required to run this command' );
33 }
34 0 ▶ if ( $opts->{show} && $opts->{clear} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"show"} and $opts->{"clear"}) 0 0 0
Condition0%0/3
$opts->{"show"} and $opts->{"clear"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"show"} and $opts->{"clear"}
$opts->{"show"} $opts->{"clear"}
Truth table0%0/3
A and B
A= $opts->{"show"}B= $opts->{"clear"}
ABresult
0X0
100
111
35 0 throw_cmd_validation_exception( error =>
36 'Mutually exclusive options (show and clear) are specified together' );
37 }
38 }
39  
40 0 ▶sub run {
Subroutine run: not called CC=6 SCAR=37.4
Pod documented
41 0 my ( $self, $opts, @args ) = @_;
42 0 my ( $ds_name, $verbose ) = @{ $self->cache->get('cache') }{qw/datasource_name verbose/};
43 0 my @saved_commands = sort { $a <=> $b } keys %{ $COMMAND_HISTORY->{datasource}{$ds_name} };
44  
45 # Show all saved commands for the current datasource along with datetime
46 0 ▶ if ( $opts->{show} && @saved_commands ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"show"} and @saved_commands) 0 0 0
Condition0%0/3
$opts->{"show"} and @saved_commands
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"show"} and @saved_commands
$opts->{"show"} @saved_commands
Truth table0%0/3
A and B
A= $opts->{"show"}B= @saved_commands
ABresult
0X0
100
111
47 0 push my @rows, [qw/command_no datetime command/];
48 0 for (@saved_commands) {
49 push @rows,
50 [
51 $_,
52 0 @{ $COMMAND_HISTORY->{datasource}{$ds_name}{$_} }{qw/datetime command/}
53 ];
54 }
55
56 0 ▶ print STDERR "\nRendering command history ...\n\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
57
58 return {
59 0 headingText => 'command history',
60 rows => \@rows
61 };
62 }
63  
64 # Clears the command history for the current datasource
65 0 ▶ delete $COMMAND_HISTORY->{datasource}{$ds_name} if $opts->{clear};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"clear"} 0 0 0
66 0 return;
67 }
68  
69 #-------
70 1 1;
71 __END__
« CohortExplorer/Application/REDCap/Datasource.pm ↑ Summary CohortExplorer/Command/Describe.pm »