| 1 | package Csistck::Term; | ||||||||||
| 2 | |||||||||||
| 3 | 17 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 17 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 17 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 17 | ▶ | use base 'Exporter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 17 | ▶ | use Term::ReadKey; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 17 | ▶ | use Csistck::Test; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 17 | ▶ | use Csistck::Test::Return; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 17 | our @EXPORT_OK = qw/ | |||||||||
| 14 | prompt | ||||||||||
| 15 | /; | ||||||||||
| 16 | |||||||||||
| 17 | # Interactive terminal prompt. Takes in test as argument, and displays action | ||||||||||
| 18 | # options | ||||||||||
| 19 | sub prompt { | ||||||||||
| 20 | 0 | ▶ | my $test = shift; | ||||||||
|
Subroutine
prompt: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||
| 21 | 0 | my %options; | |||||||||
| 22 | |||||||||||
| 23 | # Ask question loop, get input. If choices are not code refs, do not show choice | ||||||||||
| 24 | 0 | say("What would you like to:"); | |||||||||
| 25 | 0 | my @choices = (); | |||||||||
| 26 | # Repair | ||||||||||
| 27 | 0 | ▶ | if ($test->can('repair')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 0 | say(" Y : Repair"); | |||||||||
| 29 | 0 | push(@choices, 'Y'); | |||||||||
| 30 | } | ||||||||||
| 31 | # Skip | ||||||||||
| 32 | 0 | say(" N : Skip"); | |||||||||
| 33 | 0 | push(@choices, 'n'); | |||||||||
| 34 | # Diff | ||||||||||
| 35 | 0 | ▶ | if ($test->can('diff')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | say(" D : Diff"); | |||||||||
| 37 | 0 | push(@choices, 'd'); | |||||||||
| 38 | } | ||||||||||
| 39 | 0 | print("[Y/n/d]? "); | |||||||||
| 40 | |||||||||||
| 41 | 0 | ReadMode 3; | |||||||||
| 42 | 0 | my $action = ReadKey(0); | |||||||||
| 43 | 0 | say($action); | |||||||||
| 44 | 0 | ReadMode 0; | |||||||||
| 45 | |||||||||||
| 46 | # Execute and return, based on input. Return value is used for processing | ||||||||||
| 47 | # on_repair operations. | ||||||||||
| 48 | 0 | given ($action) { | |||||||||
| 49 | 0 | when (/[Yy\n]/) { | |||||||||
| 50 | 0 | ▶ | return $test->execute('repair') if ($test->can('repair')); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | } | ||||||||||
| 52 | 0 | when (/[Dd]/) { | |||||||||
| 53 | # Show diff, loop through prompt again | ||||||||||
| 54 | 0 | ▶ | $test->execute('diff') if ($test->can('diff')); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 0 | return prompt($test); | |||||||||
| 56 | } | ||||||||||
| 57 | 0 | default { | |||||||||
| 58 | 0 | return Csistck::Test::Return->new( | |||||||||
| 59 | resp => 0, | ||||||||||
| 60 | msg => 'Missing function', | ||||||||||
| 61 | desc => $test->desc | ||||||||||
| 62 | ); | ||||||||||
| 63 | } | ||||||||||
| 64 | } | ||||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 17 | 1; | |||||||||