line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::ConMenu; |
2
|
1
|
|
|
1
|
|
62823
|
use 5.10.0; |
|
1
|
|
|
|
|
3
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
5
|
1
|
|
|
1
|
|
3
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
6
|
1
|
|
|
1
|
|
508
|
use YAML::Tiny; |
|
1
|
|
|
|
|
4787
|
|
|
1
|
|
|
|
|
48
|
|
7
|
1
|
|
|
1
|
|
437
|
use Term::ANSIScreen qw(cls); |
|
1
|
|
|
|
|
2089
|
|
|
1
|
|
|
|
|
499
|
|
8
|
|
|
|
|
|
|
our $VERSION = "1.00"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
1
|
|
|
1
|
0
|
128
|
my $type = shift; |
13
|
1
|
|
|
|
|
2
|
my $self = {}; |
14
|
1
|
|
|
|
|
3
|
return bless $self, $type; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# load the yaml file you should have |
18
|
|
|
|
|
|
|
# set filename by now. |
19
|
|
|
|
|
|
|
sub loadMenuFile { |
20
|
1
|
|
|
1
|
0
|
560
|
my $self = shift; |
21
|
1
|
50
|
|
|
|
5
|
$self->{fileName} or croak ("No yaml file Name set"); |
22
|
1
|
|
|
|
|
1
|
my $yaml; |
23
|
1
|
|
|
|
|
6
|
$yaml = YAML::Tiny -> read($self->{fileName}); |
24
|
1
|
|
|
|
|
10749
|
$self->{'menu'}= $yaml; |
25
|
1
|
|
|
|
|
4
|
return $yaml; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub execute { |
29
|
1
|
|
|
1
|
0
|
286
|
my $self = shift; |
30
|
1
|
|
|
|
|
2
|
my $commandStructure = shift; |
31
|
1
|
|
|
|
|
3
|
my $commands = $commandStructure->{'commands'}; |
32
|
1
|
|
|
|
|
2
|
foreach my $command (@$commands) |
33
|
|
|
|
|
|
|
{ |
34
|
1
|
|
|
|
|
2838
|
print `$command`; |
35
|
|
|
|
|
|
|
} |
36
|
1
|
|
|
|
|
54
|
return 1; # return 1 so that testing knows we got this far. |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub printMenu { |
40
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
41
|
0
|
|
|
|
|
|
my $menuItemsUnsorted = $self->{'menu'}->[0]; |
42
|
0
|
|
|
|
|
|
my @menuItems = sort { {$a} cmp {$b} } keys(%$menuItemsUnsorted); |
|
0
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$self->{menuItems} = \@menuItems; |
44
|
0
|
|
|
|
|
|
cls(); |
45
|
0
|
|
|
|
|
|
my $i=1; |
46
|
0
|
|
|
|
|
|
my @menuItemsNumerical = map { '['. $i++.'] '.$_ } @menuItems; |
|
0
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
say join("\n", @menuItemsNumerical); |
48
|
0
|
|
|
|
|
|
say 'Choose a menu item by pressing the corresponding number'; |
49
|
0
|
|
|
|
|
|
say 'q to exit'; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub waitForInput { |
53
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
54
|
0
|
|
|
|
|
|
my $selection = <>; |
55
|
0
|
0
|
|
|
|
|
if ($selection =~ /[0-9]+/){ |
56
|
0
|
0
|
0
|
|
|
|
if ($selection > scalar ($self->{menuItems}) or $selection < 1 ){ |
57
|
0
|
|
|
|
|
|
say 'Error no such menu item'; |
58
|
0
|
|
|
|
|
|
exit; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} else { |
61
|
0
|
|
|
|
|
|
exit; |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
my $menuItems = $self->{menuItems}; |
64
|
0
|
|
|
|
|
|
$self->execute($self->{menu}->[0]->{$menuItems->[$selection -1]}) |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# create a default file to get people going. |
68
|
|
|
|
|
|
|
sub createDefaultFile{ |
69
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
70
|
0
|
|
|
|
|
|
my $fileName = shift; |
71
|
0
|
|
|
|
|
|
my $menu = { |
72
|
|
|
|
|
|
|
'Menu option 1' => { |
73
|
|
|
|
|
|
|
'commands' => [ |
74
|
|
|
|
|
|
|
'ls' |
75
|
|
|
|
|
|
|
], |
76
|
|
|
|
|
|
|
'working_dir' => './' |
77
|
|
|
|
|
|
|
}, |
78
|
|
|
|
|
|
|
'Menu Option 2' => { |
79
|
|
|
|
|
|
|
'commands' => [ |
80
|
|
|
|
|
|
|
'dir' |
81
|
|
|
|
|
|
|
], |
82
|
|
|
|
|
|
|
'working_dir' => './' |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
}; |
86
|
0
|
|
|
|
|
|
my $yaml = YAML::Tiny->new($menu); |
87
|
0
|
|
|
|
|
|
$yaml->write($fileName); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
__END__ |